While extensions cannot access page variables and vice versa, you can communicate between the page and the extension through events. The following is a brief example of creating custom events:
function fireEvent(name, target) { //Ready: create a generic event var evt = document.createEvent("Events") //Aim: initialize it to be the event we want evt.initEvent(name, true, true); //true for can bubble, true for cancelable //FIRE! target.dispatchEvent(evt); } function foobar() { alert("foobar"); } function testEvents() { window.addEventListener("foobar", foobar, false); //false to get it in bubble not capture. fireEvent("foobar", document); }
(taken from here )
So, if you need to transfer information from a page to an extension, you will need to fire a custom event on the page that you will listen to in your script content.
source share