访问 GreaseMonkey 沙箱时出错 API
Erorr accessing GreaseMonkey sandbox API
是的,这基本上是同一个老问题。编写我的第一个 GreaseMonkey 脚本时,脚本告诉我 GM_xmlhttpRequest 未定义。经过进一步调查 - 我认为我一般无法访问 API,GM_info 给了我同样的问题。
完整脚本如下:
// ==UserScript==
// @name Mirror Page
// @namespace mailto:linkhyrule5@gmail.com
// @description POSTs page to dynamic page mirror
// @include http://www.google.com
// @version 1
// @grant GM_xmlhttpRequest
// @grant GM_info
// ==/UserScript==
console.log(GM_info);
var ihtml = document.body.innerHTML;
GM_xmlhttpRequest({
method:'POST',
url:'http://localhost:5723/index.php',
data:"PageContents=" + escape(ihtml) + "\nURL=" + escape(document.URL),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
});
在 Google 主页上得到了我
/*
Exception: ReferenceError: GM_info is not defined
@Scratchpad/1:11:1
*/
以及更早的 GM_xmlhttpRequest is not defined
.
运行 Firefox 45.0 上的 GreaseMonkey 3.7。我重新启动了 Firefox 和 enabled/disabled;该脚本纯粹存在于我的剪贴板和沙箱中,但就 "removing the script and recreating it from clipboard" 而言,我还重新安装了该脚本。
我现在尝试将文件复制到 .user.js 文件并从那里安装;还是不行。
事实证明,暂存器中的重新加载和 运行 选项不适用于任何需要 Greasemonkey 沙箱的脚本,正如所发现的那样 here。
是的,这基本上是同一个老问题。编写我的第一个 GreaseMonkey 脚本时,脚本告诉我 GM_xmlhttpRequest 未定义。经过进一步调查 - 我认为我一般无法访问 API,GM_info 给了我同样的问题。
完整脚本如下:
// ==UserScript==
// @name Mirror Page
// @namespace mailto:linkhyrule5@gmail.com
// @description POSTs page to dynamic page mirror
// @include http://www.google.com
// @version 1
// @grant GM_xmlhttpRequest
// @grant GM_info
// ==/UserScript==
console.log(GM_info);
var ihtml = document.body.innerHTML;
GM_xmlhttpRequest({
method:'POST',
url:'http://localhost:5723/index.php',
data:"PageContents=" + escape(ihtml) + "\nURL=" + escape(document.URL),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
});
在 Google 主页上得到了我
/*
Exception: ReferenceError: GM_info is not defined
@Scratchpad/1:11:1
*/
以及更早的 GM_xmlhttpRequest is not defined
.
运行 Firefox 45.0 上的 GreaseMonkey 3.7。我重新启动了 Firefox 和 enabled/disabled;该脚本纯粹存在于我的剪贴板和沙箱中,但就 "removing the script and recreating it from clipboard" 而言,我还重新安装了该脚本。
我现在尝试将文件复制到 .user.js 文件并从那里安装;还是不行。
事实证明,暂存器中的重新加载和 运行 选项不适用于任何需要 Greasemonkey 沙箱的脚本,正如所发现的那样 here。