Search code examples
firefoxfirefox-addoncontextmenumenuitemfirefox-addon-sdk

Get the source url of link by custom firefox MenuItem


I have tried to:

  • Add menu item to the mozilla firefox menu,
  • It should appear only if the user click on link ,
  • If the user click on the menuItem, the source url will be looged in the console.

that is my code , which fail to show menu item at all :

 var contextMenu = require("sdk/context-menu");
 var menuItem = contextMenu.Item({
                              label         : "Show the url",
                              context       : contextMenu.SelectorContext("a[href]"), 
                              contentScript : 'self.on("click", function (node , data) {' + '  self.postMessage(node.src);' +'});',
                              onMessage: function (url) { console.log(url);}
                             });

I have got the following log :

console.log: rd-addon: null


Solution

  • change:

    context       : contextMenu.SelectorContext("a[href]"), 
    

    to

    context: contextMenu.URLContext("*"),