4

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

1 Answer 1

4

Using unsafeWindow can access page variables

unsafeWindow.varname

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

https://wiki.greasespot.net/UnsafeWindow

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.