Reputation: 505
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?
Upvotes: 5
Views: 33351
Reputation: 23
In Chromium Version 35.0.1916.114 and probably in all the latest Chrome versions, it is possible to store global variables, while you're testing on the Chrome console.
For example, if you use console.log() for a variable in your code, when you see it on your browser console, you can store it by right clicking on it and select "Store as Global Variable"
I Hope it can help you!
Upvotes: -6
Reputation: 752
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
Upvotes: 6