How can I register selected text with Firefox Addon Builder?

I followed several textbooks without success. I think this is a classic example, but I can't get it to work. I can save my project, install the add-on, and I can see the context menu item "Journal Selection" when I select some text, but when I click on it, nothing happens.

exports.main = function() { var contextMenu = require("context-menu"); var request = require("request"); var selection = require("selection"); var menuItem = contextMenu.Item({ label: "Log Selection", context: contextMenu.SelectionContext(), contentScript: 'self.on("click", function () {' + ' var text = window.getSelection().toString();' + ' self.postMessage(text);' + '});', onMessage: function (selectionText) { alert(selectionText); } }); } 

Even if my addon contains only one warning, the addon is installed, but the warning does not appear.

 exports.main = function() { alert("Hello world"); } 

Additional Information:

+3
source share
1 answer

You cannot use alert directly in lib / module. There simply is no window that can display a warning, and therefore there is no alert function.

Take a look at the logging documentation .

If you really want to display something, you can, for example, use notifications or alert using nsIPromptService (example this page ) or from a content document (widget, etc.).

Here is an example demonstrating different methods .

+3
source

Source: https://habr.com/ru/post/951743/


All Articles