Addon SDK - context-menu and page-mod workers

后端 未结 3 1761
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-18 08:42

I have been working on a context-menu that communicates with a page mod and come up against an issue.

I am able to send a communication with right click to the page

3条回答
  •  借酒劲吻你
    2020-12-18 09:13

    ZERO is right, the event detach is emitted on reload.
    But when I open a different page in the same tab no detach-event is been emitted!
    So, i.e., when I have loaded some page A in tab 1 and click on a link which opens a different page B in the same tab 1 I have to detach the worker for page A manually(?)

    var workers = [];    
    
    require('page-mod').PageMod({
      include: '*',
      contentScriptWhen: 'end',
      contentScript: [require('self').data.url('bla.js')],
      onAttach: function(worker) {
        var w = workers.length;
        while (w--) {
          if (worker.tab === workers[w].tab) {
            workers.splice(w, 1);
            break;
          }
        }
        workers.push(worker);
        // other stuff
      }
    });
    

提交回复
热议问题