Firefox 插件获取标签正文内容 [英] Firefox add-on get the tab body content

查看:24
本文介绍了Firefox 插件获取标签正文内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个关于 Firefox 插件的问题:

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").activeTab.documentContent.body.innerHTML;

非常感谢.

推荐答案

插件 SDK 不允许直接访问选项卡内容 - 其想法是插件和选项卡最终可能存在于不同的环境中最终处理.您所做的是将内容脚本注入选项卡以获取必要的数据,如下所示:

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);
  }
});

这篇关于Firefox 插件获取标签正文内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆