I've looked at other global variable questions on Chrome Extension with manifest ver 2, but found nothing.
Assume I have 2 files:
// content.js
var myVariable = myVariable(someDiv);
var myVarWithGlobe = VarWithGlobe.fromVariable(myVariable);
and
// VarWithGlobe.js
var withGlobe = withGlobe || { };
withGlobe.WithGlobe = (function(global) {
var myLocalVar = global.myVariable;
....
WithGlobe.fromVariable = WithGlobe;
both of them are added to web_accessible_resources, content_scripts but I can't access global.myVariable in second file since it is undefined.
How can I get it if I'm not allowed to change VarWithGlobe.js?
Content scripts have own execution context (it is even different from the webpage context they are executing in). The only way is to pass messages to/from background page with variable. Check this answer for code samples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With