I'm reading through the Chrome docs trying to learn how to create an extension and am struggling to understand how to share data between content scripts.
Let's say I have three scripts bundled with my extension:
jquery.js
script1.js
script2.js
I need script1.js
and script2.js
to use jQuery, and each script needs to be able to read and write global variables ala window.foo = 'bar'
.
The scripts also add content to the DOM that is event driven, so the global variables they read/write need to be persistent as long as the tab is open.
For example, script1.js
might add a button to the page that when clicked runs a function defined in script1.js
, which in turn sets a global variable and then runs a function in script2.js
which then uses that variable (just an example).
However, content scripts have some limitations. They cannot:
- ...
- Use variables or functions defined by their extension's pages
- Use variables or functions defined by web pages or by other content scripts
Does this mean an extension's content scripts cannot interact with each other at all, or is it saying that content scripts from different extensions can't interact with each other?
In other words, do all of an extensions content scripts run in the same isolated world, or in separate isolated worlds?