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