سؤال

I've made a add-on for Firefox using it's add-on builder SDK. At first it works just fine, but then when I switch tabs it starts acting weird and loose its functionality. I know I must be missing something and it's probably related to the communication between scripts, but I don't know what.

Instead of posting the code I made the extension public and here is the link .

If you still need me to post the codes , witch you shouldn't, just ask me to and I'll do it. Tell me what am I supposed to do to make my extension work on many tabs separately, but simultaneously.

هل كانت مفيدة؟

المحلول

Looks like to me that lines 59-64 should actually be in the attachTabWorker function. You only need to save the workers for the panel to current worker communication.

I'd connect your port communication like this:

function attachTabWorker(tab) {
    // Attach and store
    var tabWorker = tabWorkers[tab.id] = tab.attach({
        contentScriptFile: [data.url("clear.js"),data.url("jquery.js")]
    });
    // Clean up
    tabWorker.on("detach", function() {
        if (getTabWorker(tab) === tabWorker) {
            delete tabWorkers[tab.id];
        }
    });
    tabWorker.port.on('hiderOn',function(tag){
        panel1.port.emit('hiderOn', tag);
    });
    tabWorker.port.on('hiderOff',function(tag){
        panel1.port.emit('hiderOff', tag);
    });
}

Otherwise you're only getting the port communication link setup for the activeTab when it's first run instead of for every tab like I believe you want. The code getActiveTabWorker().port.on... runs once at startup of the add-on which only creates a listener for the activeTab and not all tabs. I hope that makes sense.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top