admin管理员组

文章数量:1277900

I'm seriously struggling trying to resolve an issue with my script. Whatever I try and do GM.xmlHttpRequest throws error "is not a function".

The rest of my code works fine.

This is an abridged version of my code:

// ==UserScript==
// @name         FUT20 Autobuyer Menu
// @namespace    /
// @version      0.6
// @description  try to take over the world!
// @author       Rastor
// @match        /*
// @match        /*
// @grant        GM.xmlHttpRequest
// ==/UserScript==

        try {
            GM.xmlHttpRequest({
              method: "GET",
              url: "/",
              onload: function(response) {
                alert(response.responseText);
              }
            });
        }
        catch (err) {
            console.log(err);
        }

I'm seriously struggling trying to resolve an issue with my script. Whatever I try and do GM.xmlHttpRequest throws error "is not a function".

The rest of my code works fine.

This is an abridged version of my code:

// ==UserScript==
// @name         FUT20 Autobuyer Menu
// @namespace    http://tampermonkey/
// @version      0.6
// @description  try to take over the world!
// @author       Rastor
// @match        https://www.easports./uk/fifa/ultimate-team/web-app/*
// @match        https://www.easports./fifa/ultimate-team/web-app/*
// @grant        GM.xmlHttpRequest
// ==/UserScript==

        try {
            GM.xmlHttpRequest({
              method: "GET",
              url: "http://www.example./",
              onload: function(response) {
                alert(response.responseText);
              }
            });
        }
        catch (err) {
            console.log(err);
        }
Share Improve this question edited Jun 8, 2020 at 11:02 Matt Bridges asked Jun 8, 2020 at 10:38 Matt BridgesMatt Bridges 1711 gold badge3 silver badges10 bronze badges 4
  • The code is missing // ==UserScript== at the beginning. – woxxom Commented Jun 8, 2020 at 10:44
  • It is but unfortunately that's just how it's copied in. Everything else is working. – Matt Bridges Commented Jun 8, 2020 at 10:53
  • I've edited the post above to show what the code actually looks like. I had missed that line in the post above. When it appears in the actual code it still doesn't work. – Matt Bridges Commented Jun 8, 2020 at 11:02
  • 1 Since the posted code works for me I guess there's a bug in your version of Tampermonkey or browser or there's a typo in your actual code. – woxxom Commented Jun 8, 2020 at 11:07
Add a ment  | 

2 Answers 2

Reset to default 7

In Tampermonkey it is GM_xmlhttpRequest (underscore not dot) as the privilege and function name!

In my scenario, I had to enable the call with the below grant:

// @grant        GM.xmlHttpRequest

I was then able to plete the request.

本文标签: javascriptTampermonkey GMxmlHttpRequest is not a functionStack Overflow