I have read this at least 3x and I keep thinking it says I will always be able to do Cross-Origin requests
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
let headers = new Headers();
headers.append('Authorization', 'Basic ' + btoa(username + ":" + password));
headers.append("Content-Type","text/plain");
var url = "http://172.16.0.1/show_traffic.htm";
fetch(url, {
headers: headers
})
.then(function(response) {
if (response.status !== 200) {
console.log(
"Looks like there was a problem. Status Code: " + response.status
);
return;
}
// Examine the text in the response
response.json().then(function(data) {
console.log(data);
});
})
.catch(function(err) {
console.log("Fetch Error :-S", err);
});
return true; // Will respond asynchronously.
});
And the error:
Access to fetch at 'http://172.16.0.1/show_traffic.htm' from origin 'chrome-extension://lfjdabjkhbhdbnfgohpbaghohmimbgme' has been blocked by
CORS policy: Response to preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested resource.
If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.