I'm trying to inject a script to the page inside a content-script.
The injected script should define an object abc
onto the window
-object. However, after the injected script is loaded, trying to read from the content-script results in window.abc = undefined
Could this be due to content-scripts living in isolated environments? On first thought this would seem weird, as I would expect the content-script and the script dynamically injected from the content-script to live in the same environment (and thus share the same window object)
Background: as part of an extension I need to load a content-script on a wide variety of pages. It seems a complete waste of bandwidth/performance to have to load big scripts for every one of these pages even if the extension might not be used on that page to begin with. Therefore, I'd like the content-script be as lightweight as possible and only load in (lazy load) the heavier scripts (using injection as described) once the user has indicated he wants to use the extension on said page. (by picking up some event such as clicking the extension icon)