@grant messes up the script with Firefox, but not with Chrome

52 views
Skip to first unread message

mens sana

unread,
Oct 29, 2015, 8:03:45 PM10/29/15
to greasemonkey-users
Hello ! I'm going nuts trying to figure out how to use @grant and still access the webpage contents properly.

My script is waiting for the window property channel to be defined, then it sets a few listeners. In Firefox, the property channel becomes unavailable when @grant is different than none.

Here is a simplified version of the script :

// ==UserScript==
// @name         foo
// @version       1
// @grant          GM_getResourceURL
// ==/UserScript==

var lookup = function()
{
    if (typeof channel !== "undefined")
    {
        console.log("Loaded");
        clearInterval(nextInitHnd);
        setListeners();
    }
    else
        console.log("Not loaded, waiting...");
}

var setListeners = function()
{
    console.log("Setting listeners");
   
    channel.socket.on("chatMessage", function(e)
    {
        console.log(e.text);
    });
}

var nextInitHnd = setInterval(lookup, 1000);

Please note that this works perfectly in Chrome, or in Firefox with @grant none. The problem only appears in Firefox with @grant GM_getResourceURL (or any other value different than none).

I tried changing channel to window.channel or unsafeWindow.channel but this doesn't help. I just want to make the property accessible for Firefox, while keeping the working code for Chrome.

Thanks for your advice
Message has been deleted

David Millar

unread,
Mar 30, 2016, 2:53:49 PM3/30/16
to greasemonkey-users
Hey Mens, just wondering if you ever found a solution. I am experiencing the same problem when trying to use unsafeWindow when I've declared @grant unsafeWindow. When I leave off the @grant line or use @grant none the script works perfectly.

Dave
Reply all
Reply to author
Forward
0 new messages