Is it possible to alter globally available JavaScript objects from within a Chrome browser extension? E.g., I want the extension to change what the window.navigator.platform
property returns to the site.
Asked
Active
Viewed 305 times
0

D.R.
- 20,268
- 21
- 102
- 205
-
1No way. [Content scripts](https://developer.chrome.com/extensions/content_scripts) live in an isolated world which doesn't allow them to access any variables or functions created by a web page. Whereas background pages have no (direct) access to web pages at all. – hindmost Dec 03 '19 at 21:19
-
2It's possible and rather simple: insert a DOM script element with the code that redefines the object. More info: [Insert code into the page context using a content script](//stackoverflow.com/a/9517879) – wOxxOm Dec 04 '19 at 07:39
-
Thanks! It's not _that_ easy, because you have to do some more tricks to overwrite read-only properties (https://stackoverflow.com/questions/23202136/changing-navigator-useragent-using-chrome-extension), but it worked in the end. Thank you! – D.R. Dec 04 '19 at 19:44