Greasemonkey: "GM_xmlhttpRequest is not defined" with the new update
Asked Answered
A

1

2

Why this simple Greasemonkey script is not working for me https://jsfiddle.net/pghnsw8z/1/ ? I mean that instead of getting successful response I get error while making an ajax call.

// ==UserScript==
// @name        _Starter AJAX request in GM, TM, etc.
// @match       *://php.net/*
// @grant       GM_xmlhttpRequest
// @connect     php.net
// ==/UserScript==

GM_xmlhttpRequest ( {
    method:     'GET',
    url:        'http://php.net/',
    onload:     function (responseDetails) {
                    // DO ALL RESPONSE PROCESSING HERE...
                                alert(responseDetails);
                    console.log (
                        "GM_xmlhttpRequest() response is:\n",
                        responseDetails.responseText.substring (0, 80) + '...'
                    );
                }
} );

I found the script here https://mcmap.net/q/752486/-how-can-userscript-make-a-network-request-to-a-different-domain and it seems it worked well for someone earlier.

I'm using Firefox 59.0.1 and Greasemonkey 4.3

Restarting Firefox and reinstalling script didn't help.

Angelinaangeline answered 19/3, 2018 at 14:43 Comment(7)
GM4 has abandoned the classic API, see their documentation, now it's GM.*Urdu
@wOxxOm In this case I get GM.xmlhttpRequest is not a functionAngelinaangeline
The new API function uses uppercase H.Urdu
@wOxxOm Perfect! thank's a lot.Angelinaangeline
Peter, as per GM's own recommendation, you should switch to Tampermonkey or Violentmonkey. The new Greasemonkey is severely degraded, not backwards compatible, and has significantly less utility than the other engines.Diastema
@Brock Adams Thank's for pointing that out for me.Angelinaangeline
use GM.* in new scripts, add polyfill to old scripts. One line, too easy. A suggestion for users (just users) if a script was not updated by one of these methods is that they might to switch to tampermonkey meanwhile. GM is not dying. Why is not GM adding the polyfill automatically? Maybe wanted to force the change.Ironic
W
4

The doc : https://wiki.greasespot.net/GM.xmlHttpRequest

The GM API was changed. You have to use xmlHttpRequest property of GM class, it is compatibility: GM 4.0+.

Replace GM_xmlhttpRequest by : GM.xmlHttpRequest like this :

// ==UserScript==
// ...
// @grant         GM.xmlHttpRequest
// ==/UserScript==

GM.xmlHttpRequest({
Wildeyed answered 31/1, 2019 at 8:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.