I’m working on a project that requires my user script be run on pages as they are rendered without executing any of the page’s JavaScript. That is to say, we need to browse with JavaScript disabled.
I’ve encountered a problem though when I try to delay execution of a function within my script. Whenever I make a call to window.setTimeout, the function I pass in never gets executed.
I think maybe this function is actually getting called on unsafeWindow instead of window. Is there any workaround for this?
I should mention that calls to setTimeout work fine when JavaScript is enabled and everything else in my script is working fine without enabling JavaScript.
Thanks for your help!
Even though Greasemonkey JavaScript runs with elevated privileges, as Pointy said,
setTimeoutfunctions are appended to the page’s JavaScript space — wrapped in a closure as needed. (In normal operation, the Greasemonkey instance is often gone by the time any timers, it has set, fire.)So, if the page’s main JavaScript is disabled, the timer will never run.
Possible workarounds:
Use
GM_xmlhttpRequestas a crude delay. You can setup a page that deliberately draws out its response. So code like:Would call a utility page that you set up to do the delay for you.
Use NoScript to disable all of the page’s JavaScript except for the main page. For example, for page, YourSite.com/testpage.htm, which includes scripts from, say, *SpamGenerator.net… Allow scripts from YourSite.com but block them from SpamGenerator.net.