When my GM script does this:
var curTab = GM_openInTab(url);
it results in a 'GM_openInTab is not defined'
JavaScript error in the Browser Console.
I also tried using var curWin = window.open(url);
instead of GM_openInTab
but it had no affect.
What I'm trying to do with this GM script is: for a given website (domain name), go through a list (array) of URLs on this domain and look for items of interest.
What's wrong with my code or approach?
I'm using Greasemonkey 2.3 with Firefox 33.1.1 and Windows XP 32-bit.
When my GM script does this:
var curTab = GM_openInTab(url);
it results in a 'GM_openInTab is not defined'
JavaScript error in the Browser Console.
I also tried using var curWin = window.open(url);
instead of GM_openInTab
but it had no affect.
What I'm trying to do with this GM script is: for a given website (domain name), go through a list (array) of URLs on this domain and look for items of interest.
What's wrong with my code or approach?
I'm using Greasemonkey 2.3 with Firefox 33.1.1 and Windows XP 32-bit.
Share Improve this question edited Feb 6, 2015 at 19:07 Brock Adams 93.5k23 gold badges240 silver badges304 bronze badges asked Feb 1, 2015 at 22:46 KXNV-89.1FMKXNV-89.1FM 1151 silver badge6 bronze badges 1-
4
Have you
@grant GM_openInTab
? – tsh Commented Feb 2, 2015 at 2:43
1 Answer
Reset to default 16In order to use any of the GM_
functions, you must set a matching @grant
directiveDoc (As of Greasemonkey version 2.0Release notes)
For example:
// ==UserScript==
// @name _YOUR_SCRIPT_NAME
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @grant GM_openInTab
// ==/UserScript==
var curTab = GM_openInTab ("http://pwnthemall./");
Note that this has the side effect of switching Greasemonkey's sandbox back on. See also:
- Error: Permission denied to access property 'handler'
- How to access `window` (Target page) objects when @grant values are set?
Tampermonkey emulates most of this behavior as of version 3.9Release notes. But the current version (3.9.202) still attempts to guess appropriate values if @grant
is not specified, so you won't necessarily see an error (yet).
Always use @grant
anyway, for maximum patibility and to future-proof your code.