I'm trying to inject a JS code into a website, where the code gets executed on all of its pages. I found out that this could be done using the chrome content scripts. Therefore, I've done the following:
-
I've created "contentscript.js".
var x = [] s.src = 'AN EXTERNAL JS FILE'; (document.getElementsByTagName('head')[0] || document.body).appendChild(s);
-
I've created "manifest.json".
{ "name": "Sample", "version": "1.0", "manifest_version": 2, "permissions": [ "tabs", ":///*" ], "icons": { "128":"logo.png" }, "content_scripts": [{ "js": ["contentscript.js"], "matches": [""] }] }
-
Both files exist in the same folder.
- I've loaded them into the chrome extensions.
- The script gets executed as expected.
The script I'm injecting loads an external JS file into the page and places a script element under the head tag. This JS also uses the "x" variable I defined in the injected JS script. But the problem that it can't read it. In the console, it throws an error that the "x" variable is not defined.
How can I define the variable in a way it makes it accessible to the external JS file, mentioning that I don't have access neither to the website nor to the external JS file?
Thanks,
Aucun commentaire:
Enregistrer un commentaire