2

他のサイトを閲覧しているときに、Chrome拡張機能を使用してサイトのコンテンツを取得しようとしています。chrome.webRequest.onCompletedのオカレンスで「XMLHttpRequest」を呼び出していますが、メソッドXHR.Openを呼び出すと、次のエラーが発生します:[Exception:DOMException] in fields Status and StatusTextfromXHRobject。

何か案が ?

ありがとう。

私は以下のコードを使用しています:

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/*"]
}
4

1 に答える 1

1

プロトコルを追加する必要があります。www.altavista.comに解決されchrome-extension://..../www.altavista.comます。を使用http://www.altavista.comすると、問題が解決するはずです。

于 2012-07-02T12:38:19.090 に答える