Can't connect to localhost from Chrome extension

4 views
Skip to first unread message

Steve Brush via StackOverflow

unread,
Jul 6, 2016, 2:04:04 PM7/6/16
to google-appengin...@googlegroups.com

If you're attempting to make a cross-domain request to localhost (with a port) from your background.js file, you'll need to update your local machine's host file with a pseudo-hostname, as demonstrated below. Chrome extensions don't like playing around with localhost for some reason, so you need to trick the extension into believing it's an actual domain.

etc/hosts file

127.0.0.1 localhost.com

manifest.json

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

background.js (using jQuery)

$.post('http://localhost.com:5000/some-endpoint');


Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/7668502/cant-connect-to-localhost-from-chrome-extension/38230785#38230785

Steve Brush via StackOverflow

unread,
Jul 6, 2016, 2:14:04 PM7/6/16
to google-appengin...@googlegroups.com

You can use custom ports.

Steve Brush via StackOverflow

unread,
Jul 6, 2016, 2:24:05 PM7/6/16
to google-appengin...@googlegroups.com

You can use custom ports.

manifest.json

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

background.js (using jQuery)

$.post('http://localhost:5000/some-endpoint');
Reply all
Reply to author
Forward
0 new messages