Erorr访问GreaseMonkey沙箱API

时间:2016-03-16 08:21:27

标签: javascript greasemonkey

是的,这基本上是一个老问题。编写我的第一个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并启用/禁用了;该脚本纯粹存在于我的剪贴板和沙盒中,但是在“删除脚本并从剪贴板重新创建它”的情况下,我还重新安装了脚本。

我现在尝试将文件复制到.user.js文件并从那里安装;仍然不起作用。

1 个答案:

答案 0 :(得分:0)

事实证明,暂存器中的“重新加载和运行”选项不适用于任何需要Greasemonkey沙箱的脚本,如发现here