Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to localhost from Chrome extension

Tags:

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?

like image 430
Jeremy Avatar asked Oct 05 '11 22:10

Jeremy


People also ask

Why localhost is not opening in Chrome?

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.

Why does my localhost not work?

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.

How do I run Chrome extensions locally?

Go to chrome://extensions/. At the top right, turn on Developer mode. Click Load unpacked. Find and select the app or extension folder.


2 Answers

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.

like image 82
smfoote Avatar answered Oct 10 '22 22:10

smfoote


You can use custom ports.

manifest.json

"permissions": ["http://localhost/*"] 

background.js (using jQuery)

$.post('http://localhost:5000/some-endpoint'); 
like image 25
Steve Brush Avatar answered Oct 10 '22 22:10

Steve Brush