I'm trying to access a javascript variable loaded in the page from a Greasemonkey script.
I tried the var name directly , or using window.varname (which works in the console), but neither of them load in the greasemonkey script (the window variable is undefined).
I tried run-at document-end and using setTimeout around the function, neither of those work.
Is there a specific way required to do this, or did I run into a bug for a specific page ?
Accessing Variables from Greasemonkey to Page & vice versa asked this question as the second part of the question, but I didn't see a clear answer. (I would comment under that question, but I don't have the credits).
Using unsafeWindow can access page variables
unsafeWindow.varname
https://github.com/greasemonkey/greasemonkey/issues/2700
https://wiki.greasespot.net/UnsafeWindow
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