Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ReferenceError:未定义GM_xmlhttpRequest_Javascript_Greasemonkey_Referenceerror_Gm Xmlhttprequest - Fatal编程技术网

Javascript ReferenceError:未定义GM_xmlhttpRequest

Javascript ReferenceError:未定义GM_xmlhttpRequest,javascript,greasemonkey,referenceerror,gm-xmlhttprequest,Javascript,Greasemonkey,Referenceerror,Gm Xmlhttprequest,我在以下userscript代码中得到一个ReferenceError: // ==UserScript== // @name ... // @namespace ... // @description ... // @include ... // @grant GM_xmlhttpRequest // ==/UserScript== console.log(GM_info); try { console.log(GM_xmlh

我在以下userscript代码中得到一个ReferenceError:

// ==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);
}
...
它首先成功地记录了
gmu info
,然后记录了ReferenceError。(我正在使用Firefox/Firebug。)

ReferenceError:未定义GM_xmlhttpRequest


为什么会出现此错误?

重新安装脚本修复了此问题。我不需要重新启动Firefox,但它可能对其他人有帮助。对于类似的问题,有一些有用的调试技巧。

我也遇到过同样的问题,而解决这个问题的方法是在顶部添加以下内容:

// @grant        GM_xmlhttpRequest
自新版本(GM 4.0)以来,在使用
GM\u xmlhttpRequest
时发生此错误,因为
GM\u xmlhttpRequest
被替换为:
GM.xmlhttpRequest

新守则是:

// ==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);
}
//...

无法复制。你的规格是什么?(操作系统、FF版本、GM版本等)这很可能是由于无效的元数据块。Win7 SP1 x64、FF 21.0、GM 1.9。元数据块来自,仅修改了
@grant
。在同一系统上测试(小于SP1)。没有发现问题。元数据块是否有前导空格?文件是否以ANSI或UTF以外的格式编码?Pastebin复制问题的确切脚本。从中执行步骤4。重新安装脚本修复了它。应保持向后兼容性。绝对愚蠢的changes.GM对象的方法是异步的(与包含“\”的函数相反)。他们不会减慢页面的速度。有时,如果不破坏其他东西,就没有进展。以新的方式编写新脚本,对于GM提供的旧脚本,请快速修复。只需添加:
/@requirehttps://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js