I am working on a Chrome extension that tracks time, and uses Google App Engine for the backend.
For testing, I'm trying to connect a local version of the extension to a local version of the App Engine app. When I try to send a POST request, I'm getting:
XMLHttpRequest cannot load http://localhost:8080/report. Origin chrome-extension://mbndmimplohfkkcincjodnfpaapbbmei is not allowed by Access-Control-Allow-Origin.
But it works when I change the URL so that it posts to the appspot.com URL.
What is the Access-Control-Allow-Origin, and why is it stopping me from getting results from localhost?
Go to Chrome setting > Privacy and Settings > See all the cookies and site data, search for localhost and delete it. Then refresh your site it will be working.
The localhost simulates a web server running on your computer. When the “localhost refused to connect” error appears, it is likely due to misconfigured port. Other common reasons include insufficient permissions and the Apache webserver not running properly.
Go to chrome://extensions/. At the top right, turn on Developer mode. Click Load unpacked. Find and select the app or extension folder.
I believe this is because you cannot make calls to a server that is not included in the permissions section of your manifest. The permissions section of manifest.json should look something like this:
"permissions": [ "http://myapp.appspot.com/*", "http://localhost/*" ]
Note, I haven't tested this, but it sounds like that is where your problem is coming from.
You can use custom ports.
manifest.json
"permissions": ["http://localhost/*"]
background.js (using jQuery)
$.post('http://localhost:5000/some-endpoint');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With