我正在尝试使用 Chrome 扩展程序在浏览其他网站时获取网站内容。我在 chrome.webRequest.onCompleted 发生时调用“XMLHttpRequest”但是每当我调用 XHR.Open 方法时,都会出现以下错误:来自 XHR 对象的 Status 和 StatusText 字段中的 [Exception: DOMException]。
任何想法 ?
谢谢。
我正在使用下面的代码:
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();
}
我的清单.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/*"]
}