1
我想建立一個使用xhr請求從外部api獲取響應的chrome擴展。我已經爲擴展名設置了擴展權限,在Chrome擴展文檔中仍然提到xhr請求在網絡中被取消。Chrome擴展xhr請求被取消
的manifest.json
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "Chrome extension title"
},
"permissions": [
"activeTab",
"storage",
"https://*/"
]
在popup.js
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://putsreq.com/4z01VNOBPeD144njWNdi", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && this.status == 200) {
var theValue = "asdfassf";
alert("This is doen");
// chrome.storage.sync.set({'value': theValue},()=> {
// // Notify that we saved.
// document.location.href = "timer.html";
// });
}
}
xhr.send();
1.在chrome:// extensions page 2上重新加載擴展。右鍵彈出「Inspect」,檢查控制檯是否有錯誤。 – wOxxOm
是的,我重新加載了很多次。並且在控制檯的網絡選項卡中,請求顯示取消 –
其他有干擾。發佈的代碼是正確的。 – wOxxOm