Before web extensions, I used NativeWindow.menu.add
and achieved this on firefox android.
Add menuI can do this frombrowser_action.default_title
.- Update text from the addon (like '936')
How do I do this in web extensions?
previous code
// getWindow
const { Cu } = require('chrome');
/**
* get current browser window for firefox addon
*
* @returns {ChromeWindow|null} browser window
* @see https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWindowMediator#getMostRecentWindow()
*/
module.exports = () => {
/* global Services:false */
Cu.import('resource://gre/modules/Services.jsm');
return Services.wm.getMostRecentWindow('navigator:browser');
};
// index.js
menuId = getWindow().NativeWindow.menu.add({
name: 'Page for Hatebu (-)',
callback: handleClick,
});
getWindow().NativeWindow.menu.update(
menuId,
{
name: `Page for Hatebu (${piece})`,
});
After Firefox 57 you have to use WebExtensions (aka Browser Extensions) for all Firefox extensions.
You can use browserAction to add an item to the Firefox menu on Android. And especially browserAction.setTitle to change the text.