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 thatwindow.somethingis 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'. Typingtypeof window.somethinginto 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?