I am new to chrome extensions, so I maybe using the wrong terms.
I have created a extension
manifest.json
{
"name": "Run code in page",
"version": "1.1",
"manifest_version": 2,
"content_scripts": [{
"js": ["contentscript.js"],
"matches": ["https://*/*"]
}],
"web_accessible_resources": ["*.js"],
"default_locale": "en"
}
contentscript.js
function injectScript(script) {
var s = document.createElement('script');
s.src = chrome.extension.getURL(script);
(document.head || document.documentElement).appendChild(s);
}
injectScript('script.js');
injectScript('otherscript.js');
script.js
console.log('script.js');
otherscript.js
console.log('otherscript.js');
This works, I see this in the output :
script.js
otherscript.js
All is good, both scripts are loading, I need jQuery to be added in the same way so that I can access jQuery from my script.
So, I
injectScript('jquery.js');
But now I get the following error
Denying load of chrome-extension://abdiolbenneaffeaedmfeeanlephlnoo/jquery.js. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.
If I look at the DOM, I see this
<script src="chrome-extension://abdiolbenneaffeaedmfeeanlephlnoo/script.js"></script>
<script src="chrome-extension://abdiolbenneaffeaedmfeeanlephlnoo/otherscript.js"></script>
<script src="chrome-extension://abdiolbenneaffeaedmfeeanlephlnoo/jquery.js"></script>
If I put chrome-extension://abdiolbenneaffeaedmfeeanlephlnoo/jquery.js into the URL I can access it.
-- edit
If I load jquery externally it will load, so I guess I can just do that. eg
function injectExternalScript(script) {
var s = document.createElement('script');
s.src = script;
(document.head || document.documentElement).appendChild(s);
}
injectExternalScript('https://code.jquery.com/jquery-3.3.1.min.js');