Safari中的Tampermonkey无法找到xmlHttpRequest

时间:2017-06-04 07:32:06

标签: javascript safari tampermonkey gm-xmlhttprequest

我正在尝试使用本地网络服务器使用Tampermonkey来存储来自网站的信息。使用GM_setvalue时,值似乎很大。

要调用本地服务器,我使用了GM_xmlhttpRequest。但是,控制台显示错误:

  

错误:执行脚本'测试'失败!找不到变量:GM_xmlhttpRequest。

我在Mac OS上使用Safari。

// ==UserScript==
// @name         Test
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://localhost/*
// @grant        none
// @grant        GM_xmlhttpRequest
// ==/UserScript==

//unsafeWindow.console.log("Requesting stuff!");
GM_xmlhttpRequest({
  method: 'GET',
  url:    'http://en.wikipedia.org/w/api.php?action=query&prop=revisions&revids=375536&rvdiffto=prev&format=xml',
  onload: function(response) {
    var xml = new DOMParser()
            .parseFromString(response.responseText, "text/xml");
    unsafeWindow.console.log("The response was: ", xml);
  }
});

0 个答案:

没有答案