-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modify code in DevTools #342
Comments
Small update, I somehow managed to modify the code when the code hit a breakpoint, then I used CTR+S to save and continue, the code was then executed with the modification, but on further breakpoints it did not execute any modifications, it just kept running the first modification. |
Hi, another update after more than 2 years :) In the meantime I was playing with CEF and webView2 but they both have massive disadvantages, for the interested reader her my results: Using CEF and the ShowDevTools mehod to bring up and use the debugger:
Using MS webView2 (invoking CoreWebView2.OpenDevToolsWindow()):
None of the above approaches suit my needs, although it's intriguing to have a "proper' web browser doing the job opening up new possibilities. So, back to ClearScript. Having now being forced to explore the DevTools in more depth, I figured out something that might solve my original problem sticking to ClearScript. The "magic" can be done by overriding the script content:
Now you can set breakpoints, modify the code, save it with ctrl+s! The modifications will be written to disc of course Once you stop the script from running in your host application, you can take the script from disc and store it with the modifications made during the debug session. The good thing is that those settings persist over time in chrome, the next time you run the ClearScript and you attach to it, the settings are already in place. You only need to take care of the copy stored on disc, the script will be overwritten by whatever has been found on disc as soon as you attach the debugger. For code consistency, one needs to overwrite the file with the content of whatever you pass to ClearScript BEFORE calling Execute. I suppose all this works in a similar fashion using Visual Studio Code !? To make this workflow a bit smoother, it might be useful to have in ClearScript a method "Execute" that takes a file name instead of a string containing the script, but it's easy to workaround this of course. Maybe you have other&better suggestions! Sorry for the lengthy post, but I feel this might help other users who might stumble about this problem. |
Hi @flat-eric147,
Perhaps not; the content override feature could be unique to DevTools.
Sure, you can do the following: engine.DocumentSettings.AccessFlags = DocumentAccessFlags.EnableFileLoading;
engine.ExecuteDocument(filePath); Good luck! |
Originally posted by @ClearScriptLib in #260 (comment)
Hello and thank you for your reply! I am not quite sure how you achieved that. I connected to my host through the DevTools (tried both chrome and edge), set a breakpoint and modified the code in DevTools, but as expected the new code is not executed. When the debugger hits the breakpoint again, a different tab opens with the original code. Any specific settings I forgot? I'm also not sure how the eventually modified code can be read back into my host application. The ScriptEngine class dos not appear to have getter methods to retrieve the code in execution.
The text was updated successfully, but these errors were encountered: