Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debug tampermonkey script

I would like to debug a Tampermonkey script with Chrome's console, but I can't find my script in the list..

enter image description here

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?

like image 326
thestral Avatar asked Apr 12 '15 17:04

thestral


People also ask

How do I debug a Greasemonkey script?

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.

How do I check my Tampermonkey script?

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.

Is Tampermonkey safe to use?

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.


1 Answers

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:

  • Settings Checkmark:

TamperMonkey Dashboard -> Settings -> General (Config mode: Advanced) -> Debug scripts Tampermonkey general settings w/debug checked

  • Or, in your userscript add the line:

    debugger;

like so: debugger line in userscript

(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: chrome paused on tampermonkey script

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.

like image 96
lossleader Avatar answered Sep 22 '22 20:09

lossleader