0

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.

D.R.
  • 20,268
  • 21
  • 102
  • 205
  • 1
    No 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
  • 2
    It'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

0 Answers0