Advertisement
Guest User

Untitled

a guest
Oct 12th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @ manifest.json:
  2.  
  3. {
  4.     "manifest_version": 2,
  5.  
  6.     "name": "My extension",
  7.     "description": "My extension does something",
  8.     "version": "1.0",
  9.  
  10.     "permissions": [ "https://*.mysite.com/*" ],
  11.  
  12.     "background": {
  13.         "scripts": [ "src/background.js" ]
  14.     },
  15.  
  16.     "content_scripts": [
  17.         {
  18.             "matches": [ "https://*.mysite.com/*" ],
  19.             "js": [ "src/content.js" ]
  20.         }
  21.     ],
  22.  
  23.     "browser_action": {
  24.         "default_icon": "src/popup/icon.png",
  25.         "default_popup": "src/popup/popup.html"
  26.     }
  27. }
  28.  
  29. @ src/content.js
  30.  
  31. var scriptToInject = '(function () { alert(window.globalVariable); })();';
  32. var scriptElement = document.createElement('script');
  33. scriptElement.textContent = scriptToInject;
  34. (document.head || document.documentElement).appendChild(scriptElement);
  35.  
  36. // window.globalVariable always returns undefined.
  37.  
  38. // I've tried adding a long setTimeout() in scriptToInject to see if it's an issue of timing and the result is the same.
  39.  
  40. // 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