Greasy Fork is available in English.

Discussioni » Sviluppo

Tips to adapt GreaseMonkey script for Chrome TamperMonkey?

§
Pubblicato: 20/02/2019
Modificato: 20/02/2019

Tips to adapt GreaseMonkey script for Chrome TamperMonkey?

I wonder if some of you might have some tips to make GM scripts work on Chrome — or even how to get started in order to debug.

Last week I uploaded my simple Reverso Enhancer Spanish script, which works perfectly in PaleMoon, but on Chrome with TamperMonkey nothing happens.

TamperMonkey is not showing any errors, so I'm not even sure how to start debugging, apart from using a bunch of alert

Thanks in advance for any thoughts.

wOxxOmMod
§
Pubblicato: 20/02/2019

For historical compatibility with the old scripts @grant none in Tampermonkey runs the code in the page context - not inside the userscript sandbox - so your global functions and global variables are mixed with the page and may interfere, the opposite can also occur if the page runs some script after yours and defines a property on window with the same name as one of your vars/functions. If that's not your goal, remove @grant none.

As for debugging, you can use devtools to properly debug the code, set breakpoints, step through the code line by line, inspect the values, etc.

§
Pubblicato: 20/02/2019

Thank you for the precious tips, @wOxxOm!

Looks like the script is choking early, on this line: var this_url = content.document.location TamperMonkey reports that content is not defined.

Is that a namespace problem? Does that mean that some 'vanilla' language needs to be used to check whether the script is running in Chrome, and if so to declare a few variables differently?

§
Pubblicato: 20/02/2019
Modificato: 20/02/2019

UPDATE changed that line to var this_url = window.location.toString() and… it looks like the basic functionality works.

Will probably have to tweak some things, but that's a great start. Thank you again.

wOxxOmMod
§
Pubblicato: 21/02/2019

content isn't a standard thing, probably something ancient.

§
Pubblicato: 21/02/2019

Okay, great to know, thank you! Removed it from all my scripts.

Pubblica risposta

Accedi per pubblicare una risposta.