How to hide and unhide Menu Bar using Firefox Add-on SDK Javascript?

How Can I hide and unhide Menu Bar using Firefox Add-on SDK Javascript?
I have written these codes.

//This works only for the current window
let toolbarMenubar = viewFor(browserWindows.activeWindow).document.getElementById(“toolbar-menubar”);
toolbarMenubar.setAttribute(“autohide”, “false”);

Sure I can make this code to run on every window and every time a new window gets opened, but I was wondering if there is any better way to do that, just like as if you have set it manually in the “Customize Firefox”.

You can use CustomizableUI.jsm’s setToolbarVisibility.

Your code would look something like the following to show the menubar:

const { CustomizableUI } = require("resource:///modules/CustomizableUI.jsm");

CustomizableUI.setToolbarVisibility(CustomizableUI.AREA_MENUBAR, true);
2 Likes

Thank you very much Martin. This was definitely what I was looking for and it solved my problem.
Thanks again. Wish you all the best!