Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't get port.emit and port.on to work in a Firefox add-on
    text
    copied!<p>I am sending a message like this:</p> <pre><code>self.port.emit("nodes_grubed", textNodesValues); </code></pre> <p>And want to react to it:</p> <pre><code>worker.port.on("nodes_grubed", requestRenderedtext); </code></pre> <p>But it doesn't work. What should I change? You can try my add-on <a href="https://builder.addons.mozilla.org/addon/1051796/latest/" rel="nofollow">here</a>.</p> <p><code>main.js</code>:</p> <pre><code>var widgets = require("widget"); var tabs = require("tabs"); var self = require("self"); function requestRenderedtext(textNodesText) { console.log('text nodes requesting'); } var widget = widgets.Widget({ id: "mozilla-link", label: "Mozilla website", contentURL: "http://www.mozilla.org/favicon.ico", onClick: function(worker) { tabs.activeTab.attach({ contentScriptFile: self.data.url("process.js") }); worker.on("nodes_grubed",requestRenderedtext); worker.port.on("nodes_grubed",requestRenderedtext); }, onAttach: function(worker) { worker.on("nodes_grubed",requestRenderedtext); worker.port.on("nodes_grubed",requestRenderedtext); } }); widget.on("nodes_grubed",requestRenderedtext); widget.port.on("nodes_grubed",requestRenderedtext); </code></pre> <p><code>process.js</code>:</p> <pre><code>function getTextNodes() { var walker = document.createTreeWalker( document.body, NodeFilter.SHOW_TEXT, null, false ); var node; textNodes = []; var textNodesValues=[]; while(node = walker.nextNode()) { if (node.parentNode.tagName!='SCRIPT') { textNodesValues.push(node.nodeValue); textNodes.push(node) } } if (textNodesValues.length!=0) { console.log('emmiting nodes'); self.port.emit("nodes_grubed", textNodesValues); } } getTextNodes(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload