Reputation: 11160
The question is variable scope in chrome extension. But i also want information for scope between background page and content scripts
I have a background html and a content script
I have declared a global variable in the start of background page say for example seltext
The content script is listening for mouse up events and in that code i want to update seltext
If this is not possible then i am planning to send seltext value from content script to background page by using sendresponse or i can use local storage. I hope the later will be taking more resources.
Since i am not having an clear picture of chrome extension working completely i am having this doubt.
Any type of response could be helpful.
A partial of what i wanted can be found here
how to comunicate between a content script and a background page
yet detailed information reference about variable scope in chrome extension would be nice.
Upvotes: 2
Views: 2078
Reputation: 133
You can set a setter
and a getter
for seltext
in background page and use chrome-rpc in content scripts to call seltext
's setter
and getter
for accessing seltext
.
Upvotes: 0
Reputation: 14464
Context isn't shared between the background page and content script. sendRequest is the way to go.
Upvotes: 1