First, I know that content scripts cannot access the page's global
scope.
I have a content script that loads on
facebook.com, and I have a
background page that communicates with it for cross-domain XHR,
postMessage handling, etc. It works well.
I need my content script to set a variable in the global scope of the
containing page as soon as it runs. I've seen mention of this:
window.location="javascript:window.globalVar=val;";
and also inserting <script> tags. But both of those are asynchronous
operations (which I don't want) and seem like hacks. I'm fighting
timing issues. I need the global var set before the rest of my content
script runs!
Is there any other work-around? Can the background page itself set a
global variable every time a url is loaded? Without even coding it in
the content script?
Thanks!
Matt Kruse