0

My Chrome extension background.js checks if a condition is true, and if so, download a script from my server which makes changes to the DOM. Now I'm trying to make a jquery getJSON call from that downloaded script, again, to my server, but I'm getting a XMLHttpRequest cannot load https://www.mydomain.com/loadit.php?h=&fr=0&type=5&category=. Origin http://thisdomain.com is not allowed by Access-Control-Allow-Origin.]`

Now, my manifest file has the following:

 "permissions": [
 "tabs",
 "http://*/*",
 "https://*/*"

Which I thought was supposed to allow cross origin requests from any url, so why am I getting the error?

EDIT: What's even stranger is that I'm inserting both an external css file and another js file (jquery) from that downloaded script, and both give me no problems. It's just that getJSON request that does...

Phil
  • 1,719
  • 6
  • 21
  • 36
  • The problem seems to be that you're adding a ` – apsillers Jun 17 '13 at 20:14
  • To elaborate a little further: the main page and the injected content script have separate [JavaScript execution contexts](https://developer.chrome.com/extensions/content_scripts.html#execution-environment), but share the same DOM. Adding that ` – apsillers Jun 17 '13 at 20:39
  • @apsillers thanks for your comments. Can I ask what you mean by "execute in the content script context"? I'm not sure I understand the two different contexts... – Phil Jun 17 '13 at 21:32
  • @Phil When you put your extension together, in your `manifest.json` you have scripts listed. Those are the "main" scripts apsillers is talking about. Any scripts linked from your html page are your "content" scripts. Those two types of scripts have different permissions and runtimes. – Don Rhummy Jun 17 '13 at 22:12
  • @DonRhummy Ah, thanks. As it happens to be, I'm not using the "content_scripts" at all. I just have the background script which downloads another script from my server. – Phil Jun 17 '13 at 22:15
  • @Phil, can you post the code for a full working example that also exhibits this problem? (Including some simple php code for the server side). I'll try it out if you want. – Don Rhummy Jun 17 '13 at 22:53
  • @DonRhummy thanks, but I just found a solution. I'll post it in a minute. – Phil Jun 17 '13 at 23:14

1 Answers1

0

ALthough I still don't know exactly why the extension wasn't allowing the cross-domain request, I was able to complete the request by using jquery.Ajax with Jsonp instead of the getJSON.

Phil
  • 1,719
  • 6
  • 21
  • 36