0

I am coding a chrome extension for first time. Read out their documentation well, specially permission section.

I want to load a JSON response from my localhost with a specific port ex. 3000.

I updated my mainfest.json and persssion section is like

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

But getting XMLHttpRequest cannot load http://localhost:3000/project/data.json Origin null is not allowed by Access-Control-Allow-Origin.

Seems I am missing something.

What am I missing?

Cœur
  • 37,241
  • 25
  • 195
  • 267
arnold
  • 1,682
  • 8
  • 24
  • 31
  • Looks good. Did you reload the extension after adding the permission? Is the AJAX code running in the extension's process or content script? – Rob W Jul 28 '13 at 18:56

2 Answers2

0

You could try any of the following solutions:

  1. Add the following line to the end of your manifest file:

    "content_security_policy": "script-src 'self' http://localhost:3000; object-src 'self'"
    
  2. Instead of localhost,try using the address instead i.e 127.0.0.1

Hope it helps.

Vivek Pradhan
  • 4,777
  • 3
  • 26
  • 46
0

If your request is sent to the same host with other port then this is already a cross domain request (please see http://en.wikipedia.org/wiki/Same_origin_policy#Origin_determination_rules). Cross domain ajax requsts are not allowed. There are two solutions:

  1. To use JSONP request.
  2. To add to the response header an option: Access-Control-Allow-Origin: * But not all browsers support this feature.

Please see:

Community
  • 1
  • 1
phts
  • 3,889
  • 1
  • 19
  • 31
  • 1
    While this information is relevant to ordinary Web pages, is not relevant to Chrome extension development, since Chrome extensions have the ability to [relax the same-origin policy](https://developer.chrome.com/extensions/xhr.html). This questions asks about an attempt to use this ability in a Chrome extension. – apsillers Jul 29 '13 at 13:11