Chrome extensions API states that cross-origin calls using the XMLHttpRequest object should be allowed with proper permissions:
An extension can communicate with remote servers beyond its origin by requesting cross-origin permissions.
Following the Google tutorial closely, but encountering an error message in the code below:
XMLHttpRequest cannot load http://www.google.com/search?hl=en&q=ajax. Origin chrome-extension://bmehmboknpnjgjbmiaoidkkjfcgiimbo is not allowed by Access-Control-Allow-Origin.
Despite allowing requests to google.com and other websites, I am still unable to make successful requests. Can someone assist?
This is the content of my manifest file:
{
"name": "The popup",
"version": "0.1",
"popup": "popup.html",
"permissions": [
"http://*/*",
"https://*/*",
"https://www.google.com/*",
"http://www.google.com/*"
],
"browser_action": {
"default_icon": "clock-19.png",
"default_title": "This is title",
"default_popup": "popup.html"
}
}
The actual request being made:
function sendRequest() {
document.write("Sending request");
var req = new XMLHttpRequest();
req.open("GET", "http://www.google.com/search?hl=en&q=ajax", true);
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
alert(req.responseText);
document.write("OK");
}
}
};
req.send();
}