有没有人有幸从 Google Chrome 中的用户脚本执行跨源 XHR?请求通过服务器(我可以在日志中看到它们)但是,readystatechanged
事件永远不会被触发。
扩展权限似乎不起作用。 JSONP 也不是。
最佳答案
当前版本的 Chrome(13.0.781 或更高版本)现在支持大部分或全部 GM_xmlhttpRequest()
Doc功能--包括跨域请求 .
见 Issue 18857: Support cross-site XMLHttpRequest in content scripts .
所以这个脚本现在在 Chrome(当然还有 Firefox)上运行得非常好:
// ==UserScript==
// @name _Cross domain (XSS) GM_xmlhttpRequest, Chrome too
// @include http://stackoverflow.com/*
// @grant GM_xmlhttpRequest
// ==/UserScript==
GM_xmlhttpRequest ( {
method: "GET",
url: "http://www.google.com/",
onload: function (response) {
console.log ( response.status,
response.responseText.substring (0, 80)
);
}
} );
(安装该脚本,然后浏览任何 SO 页面。该脚本会将 Google 主页的前 80 个字符写入控制台。)
关于google-chrome - 来自 Google Chrome 中用户脚本的跨源 XHR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1936639/