firefox addon - How can I track which tab or content script a message came from? -
In the Firefox add-on I need to track what tab content is associated with the contents of the script data to the Main.js
. Later, when the user clicks the extension's button in the toolbar, he will see data related to the active tab.
In Chrome Extensions, when a message was received, I could ask which message came from which tab and track messages by tab id in Firefox also, but the content from script to them There is no easy way to reach.
The answer depends on which content you are creating the script. Below is an example of a main.js
file to add the content script below.
var button = required ('sdk / ui / button / action'), pageMod = is required ('Sdk / page-mod'), data = ('sdk / Self '). Data; Map of messages marked with // tab id var messages = {}; PageMod.PageMod ({include: 'http://www.example.com', contentScriptFile: [data.url ('my-script.js')], etet: function (worker) {// received from tab id Save the worker var tabId = worker.tab.id; // Save the message worker.port.on ('Message', function (message) {message [tabId] = message;}); // tab occurs when the tab is To stop / stop a memory leak worker.on ('separate', function () {delete messages [tabId];});}}); Var Button = Button Action button ({id: 'my-extension', label: 'example', icon: {'16': './icon-16.png', '32': './icon-32 Png', '64' : './icon-64.png'}, onClick: function (state) {// // Retrieve messages related to the current active tab, if a var message = message [tabs are ActiveTab.id]; // Do something with}});
I also read what you are doing and also advise how to optimize it in your situation, to better understand it.
Comments
Post a Comment