I am creating a chrome extension. I am calling this code in background.js
fetch('http://localhost:5000/receive_html', {
method: 'GET'
})
.then(response => {
if (!response.ok) {
return response.text().then(text => {
throw new Error(`HTTP error! status: ${response.status}, body: ${text}`);
});
}
return response.json();
})
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
It’s a simple get request, to the backend. I am making this call to test if the rest is working. But in response to this request, I am getting 403 response from the server. This is the code on the server side.
@app.route('/receive_html', methods=['GET'])
def receive_html():
print("Received request")
return jsonify({"message": "HTML received and saved successfully"}), 200
This is the manifest.json for the extension.
{
"manifest_version": 2,
"name": "Fuuufuufuf",
"version": "1.0",
"description": "BLA Bla bla",
"permissions": [
"activeTab",
"storage"
],
"host_permissions": [
"http://localhost:5000/*",
"https://localhost:5000/*"
],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"browser_action": {
"default_popup": "popup.html",
"default_title": "Find"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
]
}
I tried to send request to the backend from POSTMAN, and its working fine(i.e. I am getting 200 response). But when the request is sent from the extension, it gives 403 error.. I can’t seem to figure out what the problem is. I suspect it is CORS issue. I tried changing many things in this line of code but nothing seems to help
app = Flask(__name__) CORS(app)