Witam, napotkałem problem podczas tworzenia rozszerzenia chrome. Potrzebuję aby wtyczka komunikowała się z moim serwerem i odbierała wyświetlane odpowiedzi w formacie JSON. Niestety nie działa zarówno rozwiązanie które podam poniżej jak i inne porady z google.
Po wywołaniu zapytania otrzymuje błąd:
,,Access to XMLHttpRequest at {moj serwer} from origin '{...}' 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."
GET {moj serwer} net::ERR_FAILED
content.js
function ajax_request(link){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
xmlhttp.open("GET", link, true);
xmlhttp.send();
}
manifest.json
{
"manifest_version":2,
"name": "",
"permissions": [
"tabs",
"cookies",
"activeTab",
"<all_urls>"
],
"version": "0.1",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js":["content.js"]
}
],
"browser_action": {
"default_popup": "popup.html"
}
}
Pomoże ktoś w naprawieniu tego problemu?