Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ manifest.json:
- {
- "manifest_version": 2,
- "name": "My extension",
- "description": "My extension does something",
- "version": "1.0",
- "permissions": [ "https://*.mysite.com/*" ],
- "background": {
- "scripts": [ "src/background.js" ]
- },
- "content_scripts": [
- {
- "matches": [ "https://*.mysite.com/*" ],
- "js": [ "src/content.js" ]
- }
- ],
- "browser_action": {
- "default_icon": "src/popup/icon.png",
- "default_popup": "src/popup/popup.html"
- }
- }
- @ src/content.js
- var scriptToInject = '(function () { alert(window.globalVariable); })();';
- var scriptElement = document.createElement('script');
- scriptElement.textContent = scriptToInject;
- (document.head || document.documentElement).appendChild(scriptElement);
- // window.globalVariable always returns undefined.
- // I've tried adding a long setTimeout() in scriptToInject to see if it's an issue of timing and the result is the same.
- // When I check the browser console, globalVariable exists and has the expected value, but the injected script prints undefined.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement