0

I am writing a chrome extension that is a 'content script'

I want to inject a google map on to a webpage.

Problem: It appears that i have no way to add functions on to the window object, thus i cannot define a callback function for googlemaps to call when it loads.

How do people usually go about mucking with the window?

--
someone on the interwebs suggested i do this:

You can do this easily with a JavaScript URL: window.location = "javascript:obj.funcvar = function() {}; void(0);"

but when i did this i got an access denied error. it seems like a lot of search results about this problem are outdated.

mkoryak
  • 57,086
  • 61
  • 201
  • 257

1 Answers1

3

Content scripts have a separate JavaScript execution ennvironment from the page they run on, so they cannot alter JS variables in the page itself. However, the content script shares the DOM with the page, so you can inject a <script> tag into the DOM which will be loaded and run in the actual page's execution environment.

apsillers
  • 112,806
  • 17
  • 235
  • 239