I am trying to create an add-on for Firefox which enables me to input password from a REST based server to input field.
To achieve this, I added context menus with the add-on to Firefox.
The listener for these context menus is implemented as follows:
add_listener(menu_id, listener) {
const click_listener = function(info, tab) {
if ('' + info.menuItemId == menu_id + '') {
console.debug(info.targetElementId);
listener(browser.menus.getTargetElement(info.targetElementId));
}
};
this.listeners.push(click_listener);
browser.contextMenus.onClicked.addListener(click_listener);
}
for (const pwDataEntry of pwDataSet.entries) {
const entryId = menu_service.create_sub_menu(null, pwDataEntry.key, setId);
menu_service.add_listener(entryId, element => {
console.debug(element);
element.value = pwDataEntry.content;
});
}
I am working of the documentation from Firefox for creating a menu and the documentation for ClickData (=info). Here the documentation says:
targetElementI integer. An identifier of the element, if any, over which the context menu was created. Use menus.getTargetElement() in the content script to locate the element. Note that this is not the id attribute of the page element.
As you can see I have implemented the retrieval of the element exactly as documented. The thing is Firefox tells me, that it did not find the element:
3056573 background.js:32:25
null background.js:120:29
element is null background.js:121
background.js:32:25 -> console.debug(info.targetElementId);
background.js:120:29 -> console.debug(element);
background.js:121 -> element.value = pwDataEntry.content;
If you need the more info about the code, I have uploaded the entire background.js here
I hope you know why it did not work as documented and where I went wrong ...
Thanks for your help and time in advance :)