当我浏览另一个网站时,我正在尝试使用Chrome扩展来获取一个网站的内容。我在chrome.webRequest.onCompleted中调用了"XMLHttpRequest“,但是每当我调用方法XHR.Open时,都会得到以下错误: Exception: DOMException in fields和StatusText from XHR object。
有什么想法吗?
谢谢。
我使用的代码如下:
chrome.webRequest.onCompleted.addListener(
function(details) {
if (details.url.substring(0, 23) == "https://www.google.com/") // I know I do not need this
{
console.info("URL :" + details.url);
FindData("www.altavista.com");
}
},
// filters
{
urls: [
"http://*.google.com/*",
"https://*.google.com/*",
],
types: ["image"]
},
["responseHeaders"]);
function FindData(strURL) {
var req = new XMLHttpRequest();
req.open("GET", strURL, true);
req.onreadystatechange=function() {
if (req.readyState==4) {
if (req.status==200)
{
console.info("Sucess!");
console.info("Data: " + req.responseText);
}
else if (req.status==404) console.info("URL doesn't exist!")
else console.info("Error: Status is " + req.status)
}
}
req.send();
}我的manifest.json
{
"name": "Test",
"version": "1.0",
"manifest_version": 2,
"description": "The first extension that I made.",
"browser_action": {
"default_popup": "popup.html"
},
"permissions": ["webRequest", "webRequestBlocking",
"http://www.altavista.com/*",
"http://*.google.com/*",
"https://*.google.com/*"]
}发布于 2012-07-02 20:38:19
您必须添加一个协议。www.altavista.com解析为chrome-extension://..../www.altavista.com。使用http://www.altavista.com应该可以解决您的问题。
https://stackoverflow.com/questions/11293799
复制相似问题