我正在编写一个Greasemonkey脚本,该脚本将在用户访问页面时运行,收集页面上的一些信息,然后将这些信息发送到另一个位置进行日志记录。然而,每当脚本调用GM_xmlhttpRequest时,它就会停止。例如:
// ==UserScript==
// @name GetProfileInfo
// @namespace LinkedIn
// @include https://www.linkedin.com/profile/view*
// @version 1
// @require http://code.jquery.com/jquery-latest.js
// ==/UserScript==
console.log("start");
GM_xmlhttpRequest({
method: "GET",
url: "http://www.google.com",
onload: function(response) {
console.log("sent");
}
});
console.log("done");
输出只是"开始"。
我想我可能必须在头部@grant GM_xmlhttpRequest,但当我这样做时,根本没有输出!
更新:因此,我似乎确实想@grant GM_xmlhttpRequest,但当我这样做时,我会收到错误"Components.utils.getObjectPrincipal不是函数"
您错过了@grant GM_xmlhttpRequest
// @grant GM_xmlhttpRequest
结果:开始已完成发送