2

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.

Community
  • 1
  • 1
Jayapal Chandran
  • 10,600
  • 14
  • 66
  • 91

2 Answers2

1

Context isn't shared between the background page and content script. sendRequest is the way to go.

Kevin Ennis
  • 14,226
  • 2
  • 43
  • 44
0

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.

floydwch
  • 133
  • 1
  • 9