Reputation: 602
When executing a content script, for an active Tab is there a way for that content script to return a value to the popup where the script was executed?
There is a similar question like this for Chromen - but not for FF.
There is a virtual beer for something which helps!
Thanks,
Upvotes: 0
Views: 116
Reputation: 5596
Look at this page on MDN about Content Scripts
If you are using the High-Level API Tabs (which I think you are), you need to do the following:
To send a message to the content script, underneath the var my_tab = tab.attach({ ... })
, add the following:
my_tab.port.emit("my_message", "Message from the add-on")
Then inside the script you can use this to listen for the message:
self.port.on("my_message", function(data) {
// Do stuff here!
// data contains the data sent (i.e. "Message from the add-on")
})
index.js
from ScriptThis is the bit you are probably interested in.
To send data from the script, use the following code:
self.port.emit("my_response", "Response from content script")
And to receive it in index.js
:
my_tab.port.on("my_response", function(data) {
// Do stuff here!
// data contains the data sent (i.e. "Response from content script")
})
Upvotes: 1