I would like to debug a Tampermonkey script with Chrome's console, but I can't find my script in the list..
Am I doing something wrong, or is it just that the Tampermonkey scripts don't appear there? And in that case, how can I debug it?
Open the global script debugger window via Tools → Web Developer → Browser Toolbox → Debugger (or Ctrl + Shift + Alt + I ) . Search for the name of your userscript and start debugging.
Open Tampermonkey's Dashboard and click at the script's name. Click at the 'Storage' if present and check or modify the stored data as needed. If there is no 'Storage' tab, then the script has no data stored.
Let's quickly summarize: Tampermonkey itself is neither safe nor unsafe; it's just a tool for managing user scripts. However, many user scripts can potentially be dangerous and contain malware. Other user scripts can be bad in the sense that they have unintended side effects, like bad CPU performance.
Tampermonkey is simply an extension that injects boilerplate scripts to evaluate your custom scripts, so you can debug any of these scripts if you can find them..
The trouble is that it is evaluating userscripts as if someone called eval()
on them, so you will see VM###
instead of something nice like myscript.js
and you can't normally navigate to them like permanent scripts.
Instead, add debugger lines:
TamperMonkey Dashboard -> Settings -> General (Config mode: Advanced) -> Debug scripts
Or, in your userscript add the line:
debugger;
like so:
(Doing this at the top of a userscript is equivalent to the Tampermonkey setting)
When you have a console open on a page using the script it will pause when the debugger lines are hit and show you your source file (surrounded with some tampermonkey boilerplate).
Which should look like this:
You can then instrument any other lines you need to from within the debugger.
If you run into trouble, you can also debug the main logic of tampermonkey itself by opening the background page inspection in chrome://extensions. It prints nice messages to let you know what it is up to which you can use to jump around in its code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With