简体   繁体   English

Firefox扩展与DOM交互

[英]Firefox extension interacting with the DOM

May be my logic is wrong but I'm trying to send and receive datas between my extension and the content. 可能是我的逻辑有误,但我正在尝试在扩展名和内容之间发送和接收数据。

So I start with something like this to send data from my content to my extension : 所以我从这样的事情开始,将数据从我的内容发送到我的扩展程序:

var images_elements = [];
tabs.activeTab.attach({
  contentScript: "postMessage(document.getElementsByTagName('img'));",
  onMessage: function (message) {
    images_elements = message;
  }
});

Obviously, it doesn't work. 显然,它不起作用。 How can I do something like this ? 我该怎么做? And How can I did it in the other way, example make something on this elements after making a require("sdk/request").Request and replace them in the content. 以及我该如何做,例如在进行require(“ sdk / request”)。Request并在内容中替换它们之后,在此元素上做一些事情。

You can send data, but the API accept only data that is JSON-serializable value . 您可以发送数据,但是API仅接受JSON可序列化的value数据

DOM nodes are not in that category, that's why it doesn't work. DOM节点不在该类别中,这就是为什么它不起作用的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM