window.setTimeout does not work with JavaScript disabled #1209

Closed
monkeyfriend opened this Issue Oct 26, 2010 · 6 comments

Projects

None yet

6 participants

@monkeyfriend

While JavaScript is disabled (by the add-on NoScript)
window.setTimeout
is ignored, (which to the best of my knowledge is not mentioned in the documentation as a restriction of the sandbox.)

@erikvold

issue #1238 is a dup of this ticket

@arantius
Collaborator

Confirmed: https://gist.github.com/920010

Via Preferences > Content > Enable Javascript un-checked

@k100

#1238#

i've patch this bug here

@arantius
Collaborator

k100 could you please format this patch as a git branch that we can merge?

@ewwink

k100 patch, formatted:
In greasemonkey.js: find [ injectScripts ]: function..... add our GM-api.....

sandbox.setTimeOut = function (callback, timeout, p1,p2,p3/*....*/){
    var args = Array.prototype.slice.call(arguments,2);
    return  sandbox.window.setTimeout(function(){
        return callback.apply(sandbox, args);
    } ,timeout);
}

or

sandbox.setInterval = function (callback, timeout, p1,p2,p3/*....*/){
    var args = Array.prototype.slice.call(arguments,2);
    return sandbox.window.setInterval(function(){
        return callback.apply(sandbox, args);
    } ,timeout);
}

then i add it in my greasemonkey.js like:

service.prototype.injectScripts = function(
scripts, url, wrappedContentWin, chromeWin
) {
var sandbox;
var script;
var logger;
var console;
var storage;
var xmlhttpRequester;
var resources;
var unsafeContentWin = wrappedContentWin.wrappedJSObject;

sandbox.window = sandbox.proto;
sandbox.setTimeOut = function (callback, timeout, p1,p2,p3/..../){
var args = Array.prototype.slice.call(arguments,2);
return sandbox.window.setTimeout(function(){
return callback.apply(sandbox, args);
},timeout);
}

but it not work and i got error "sandbox is undefined"

@xaberus

Hi, I am not quite sure, if this compromises security, but the following patch works for me

--- components/greasemonkey.js  2012-02-12 15:37:33.099205394 +0100
+++ /tmp/greasemonkey.js        2012-02-12 15:21:28.049465131 +0100
@@ -121,6 +121,19 @@
       new GM_xmlhttpRequester(aContentWin, aChromeWin, aUrl),
       'contentStartRequest');

+  sandbox.GM_setTimeout = function (callback, timeout) {
+    var args = Array.prototype.slice.call(arguments,2);
+    return  sandbox.window.setTimeout(function() {
+      return callback.apply(sandbox, args);
+    }, timeout);
+  };
+  sandbox.GM_setInterval = function (callback, timeout) {
+    var args = Array.prototype.slice.call(arguments,2);
+    return sandbox.window.setInterval(function() {
+      return callback.apply(sandbox, args);
+    }, timeout);
+  };
+
   Components.utils.evalInSandbox(
       'const GM_info = ' + uneval(info(aScript)), sandbox);

would be nice to this function in greasemonkey, so I do not have to patch it by hand after every update....

EDIT: usage:

GM_setInterval(function() {
  /* do something */
}, 200)
@arantius arantius added a commit to arantius/greasemonkey that referenced this issue Mar 9, 2012
@arantius arantius Refactor GM_util.timeout() argument order.
To match standard setTimeout().  Refs #1209
100813e
@arantius arantius added a commit to arantius/greasemonkey that referenced this issue Mar 9, 2012
@arantius arantius Curry extra arguments for GM_util.timeout's callback.
Refs #1209
4ef5e31
@arantius arantius closed this in 7eccacb Mar 9, 2012
@arantius arantius added a commit to arantius/greasemonkey that referenced this issue May 11, 2012
@arantius arantius Revert "Inject a custom setTimeout method into the sandbox."
This reverts commit 7eccacb.

Fixes #1549, #1552, #1553
Refs #1209
88b9019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment