Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Greasemonkey - access in page window Javascript variable from userscript?

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).

like image 843
wesinat0r Avatar asked Nov 06 '25 20:11

wesinat0r


1 Answers

Using unsafeWindow can access page variables

unsafeWindow.varname

https://github.com/greasemonkey/greasemonkey/issues/2700

https://wiki.greasespot.net/UnsafeWindow

like image 85
wesinat0r Avatar answered Nov 08 '25 10:11

wesinat0r