0

Suppose I'm injecting a content script into a webpage that has an attribute window.something.

  • When I do console.log(window) from the content script, the console reports that window.something is present.
  • When I do console.log(window.something) from the content script immediately after the previous line, I get an error.
  • When I do console.log(typeof window.something) from the content script, the console reports 'undefined'. Typing typeof window.something into the console shows a type that's not undefined (like a function or object).

I've tried this with various attributes and they all had this behavior. Do content scripts have restricted access to window for some reason? If yes, is there a more elegant solution than injecting a <script> tag into the page's DOM to access it?

wOxxOm
  • 53,493
  • 8
  • 111
  • 119
Pieter
  • 30,047
  • 75
  • 164
  • 238
  • In Firefox you can use wrappedJSObject. In Chrome the script tag is the only solution for now. – wOxxOm Jun 05 '21 at 15:52

0 Answers0