ReferenceError: GM_xmlhttpRequest is not defined

Kendall Frey picture Kendall Frey · May 24, 2013 · Viewed 12.2k times · Source

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?

Answer

user5287133 picture user5287133 · Dec 21, 2017

I had the same problem, and what fixed it for me was adding this at the top:

// @grant        GM_xmlhttpRequest