Firefox add-on get the tab body content

后端 未结 3 706
余生分开走
余生分开走 2020-12-20 07:54

Hello everyone i have an question about firefox add-on:

How i can get the body content from a tab, for example.

var content = require(\"tabs\").activ         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-20 08:32

    The Add-on SDK doesn't allow direct access to the tab contents - the idea is that the add-on and the tab might end up living in different processes eventually. What you do is injecting a content script into the tab to get you the necessary data, something like this:

    var tab = require("tabs").activeTab;
    tab.attach({
      contentScript: "self.postMessage(document.body.innerHTML);",
      onMessage: function(data)
      {
        console.log("Tab data received: " + data);
      }
    });
    

提交回复
热议问题