问题
I use Scratchpad in Firefox to run scripts against web pages and it works fine.
Is there any way to debug and watch variables during execution?
回答1:
Right now it's not possible to view code entered into the Scratchpad using the Debugger pane of the Firefox Developer Tools. It just shows up in the sources like Scratchpad/1 with content:
Error loading source:
loadSourceError
This will be fixed in bugs 816988 and 813087 so go and vote for those.
What you can do is:
Add a
debugger;
statement to the line in your Scratchpad code where you want to break. It will still be possible to view variable values, scope, etc...Interact with the Debugger object directly. Here is a video that explains getting started with that (note you can now set the option "Enable chrome and add-on debugging" in Developer Tool settings instead of going to
about:config
). You will also want to review the API.
回答2:
The issue mentioned in Alex's reply was fixed in Firefox 47 (see bug 1252077), you can now use debugger;
statements in your Scratchpad code or set breakpoints directly in the Debugger. The Scratchpad script's source should appear there after you have run the script at least once. Make sure you have Dev Tools open.
It's a bit awkward though since Scratchpad scripts don't update in the Debugger window after they were modified in the Scratchpad, you need to refresh the page you're on first or use Execute
→ Reload and Run
in the Scratchpad.
来源:https://stackoverflow.com/questions/18364124/how-to-watch-variables-in-the-firefox-scratchpad