ReferenceError: GM_xmlhttpRequest is not defined
Solution 1
Reinstalling the script fixed the problem. I didn't need to restart Firefox, but it may be helpful for other people. Brock's answer has helpful debugging tips for problems like this.
Solution 2
Since the news version (GM 4.0) this error happened when you use GM_xmlhttpRequest
because GM_xmlhttpRequest
was replaced by : GM.xmlHttpRequest
.
The new code is :
// ==UserScript==
// @name ...
// @namespace ...
// @description ...
// @include ...
// @grant GM.xmlHttpRequest
// ==/UserScript==
console.log(GM_info);
try
{
console.log(GM.xmlHttpRequest({ method: "GET", url: "http://google.ca/", synchronous: true }).readyState);
}
catch (e)
{
console.log(e);
}
//...
Greasemonkey: "GM_xmlhttpRequest is not defined" with the new update
Kendall Frey
I am primarily a C# programmer, but also use JavaScript, and some other languages in my spare time. Website: http://kendallfrey.com
Updated on June 05, 2022Comments
-
Kendall Frey almost 2 years
I get a ReferenceError in the following userscript code:
// ==UserScript== // @name ... // @namespace ... // @description ... // @include ... // @grant GM_xmlhttpRequest // ==/UserScript== console.log(GM_info); try { console.log(GM_xmlhttpRequest({ method: "GET", url: "http://google.ca/", synchronous: true }).readyState); } catch (e) { console.log(e); } ...
It first logs
GM_info
successfully, then logs the ReferenceError. (I'm using Firefox/Firebug.)ReferenceError: GM_xmlhttpRequest is not defined
Why do I get this error?
-
neverMind9 almost 5 yearsShould have kept backwards compatibility. Absolutely moronic changes.
-
papo over 4 yearsGM object's methods are async (as opposed to functions containing "_"). They will not slow down the page. Sometimes there is no progress without breaking something else. Do your new scripts the new way, for old scripts GM offered fast-fix. Just add:
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
reference