Tampermonkey / tampermonkey

Tampermonkey is the most popular userscript manager, with over 10 million users. It's available for Chrome, Microsoft Edge, Safari, Opera Next, and Firefox.
GNU General Public License v3.0
4.3k stars 424 forks source link

Hard to find userscript source in debugger #831

Open johnd0e opened 4 years ago

johnd0e commented 4 years ago

E.g. I want to set breakpoint in script source. So I press F12 to open Chrome DevTools and go to Sources tab. In left pane there is a tree with many domains, including Tampermonkey. And there are all my scripts inside of it, shown in form chrome-extension://dhdgffkkebhmkfjojejmpbldmpobfkfo/userscript.html?id=02a585a6-c478-409d-98d9-d0ac3d13441b

The problem is that I have a lot of scripts, so it's hard to find which one is needed.

I wish the source name was more meaningful, e.g. <myscriptname>.html?id=02a585a6-c478-409d-98d9-d0ac3d13441b

tophf commented 4 years ago

Violentmonkey shows script names:

image

Violentmonkey does it by adding a special comment to the script element's textContent:

'\n//# sourceURL=' + browser.extension.getURL(`${name}.user.js#${scriptId}`);

A bonus feature is an automatic redirection to a real script editor URL using webRequest.onBeforeRequest when choosing "open in new tab" in the devtools context menu for the script. This particular thing doesn't work in Firefox though as extension URLs aren't reported to webRequest in FF, but welp there's no "open in new tab" in FF's devtools anyway.

machsix commented 4 years ago

E.g. I want to set breakpoint in script source. So I press F12 to open Chrome DevTools and go to Sources tab. In left pane there is a tree with many domains, including Tampermonkey. And there are all my scripts inside of it, shown in form chrome-extension://dhdgffkkebhmkfjojejmpbldmpobfkfo/userscript.html?id=02a585a6-c478-409d-98d9-d0ac3d13441b

The problem is that I have a lot of scripts, so it's hard to find which one is needed.

I wish the source name was more meaningful, e.g. <myscriptname>.html?id=02a585a6-c478-409d-98d9-d0ac3d13441b

Just add debugger at the beginning of the script should do the trick. For ES5 script, add it to the beginning of IIFE. P.S. it's really painful to debug in Firefox+TM as the script jumps randomly when I click next line.

derjanb commented 4 years ago

I've added a name parameter to the URL which should allow to distinguish the scripts.

darkred commented 4 years ago

I've added a name parameter to the URL which should allow to distinguish the scripts.

Yes, the name parameter works and thank you for that, but it contains percent encoding, in the following example it's %20 instead of ` (space), and there's a precedinguserscript.html?name=and a trailing&id=___` : 2020-01-28_011654~

i.e. userscript.html?name=GitHub%2520Code%2520Colors.user.js&id=01363ab9-5fe6-4b27-9f13-9cdc5c47a852 instead of GitHub Code Colors.user.js

Could the percentage encoding and the preceding and trailing parts be removed, so that the name is displayed plain, like in ViolentMonkey: ? 2020-01-28_012438

P.S. Using latest TM beta 4.10.6109 in Chrome 79.