I've built a chrome extension that will rely upon ajax calls from the background script, but for some reason the ajax function is not registered as a function at the time I make my call. I thought first that it was a problem in my manifest, but realized that it would be throwing an error about $
being undefined if jquery wasn't being injected for use. I'm wondering now if it might be some sort of securities issue? I would think that if that was the case, though, that the function would still execute, but throw an error when the transport to say an illegal URL occurred. I'm really at a loss here.
Before trying $.ajax()
I was using $.getScript()
, but it throws the similar error that getScript is not a function.
In my manifest.json, I have this:
"background": {
"scripts": ["vendor/jquery.js", "background.js"]
},
And this is in my background.js:
chrome.runtime.onInstalled.addListener(function(){
...
var Core = {
...
load: function(name){
var src = EXTERNAL+name+".js";
$.ajax({
url: src,
type: "script",
success: function(result) {
console.log(result);
}
});
},
};
function initialize(){
...
Core.load(name);
}
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
var request = message.data;
var type = request.type;
switch(type){
case 'popup_handshake':
sendResponse({data:{domain: domain, seed: seed}});
break;
case 'seed':
domain = request.domain;
uW = request.uW;
seed = uW.seed;
cm = uW.cm;
delete uW.seed;
delete uW.cm;
initialize();
break;
}
});
});
What could the problem possibly be?