17 June 2008

Hacking Firefox 3.0 -- Removing unused menu items

A co-worker convinced me to download Firefox 3.0 for Firefox download day, and I took the bait. So far, Firefox 3.0 seems really, really fast, but I haven't been using it for days yet. I'm going to try to be the first guy to release a cool hack for Firefox 3.0. Please play along here.

When I use Firefox, I've noticed that there are perhaps a dozen menu items that I never use. For instance, I never try to open a new window (instead, I use tabs); I never use any of the send link/page/image to variants, since I use gmail and haven't ever set up a email client within firefox. I never use the Work Offline button (I don't really know what it means).

Same thing with the right-click context menus. I don't right click a page to stop loading, instead I hit escape. I never copy image contents, set desktop background (in fact, my window manager is set up so that my background is a terminal window).

Most importantly of all, I never never never mean to hit the File -> Quit menu item; most likely I mean to hit File -> Close Window, which is inconveniently located in the middle of the menu. In terms of keystrokes, ALT-F down down down is much farther away than ALT-F up.

So, If I never use these menu items, why do I have to filter through them every time I use my web browser?

Well, now I don't, and the screenshot at left demonstrates the newer, smoother, less-crufty layout. Here's how you do it yourself:

It turns out that all of the user interface widgets in firefox are defined in a series of XUL files. By modifying these files, we can make our menu layouts match our personal use cases.

A moment of caution, however. XUL files are XML documents, and they are tightly coupled with other parts of the software. Who know how many calls times firefox calls document.getElementById() and doesn't check the return value. Don't risk it. Instead of removing items from this file, or even commenting them out, we're going to set the XUL hidden="true" attribute for undesirable menu items. Similarly, if you are moving elements, you may want to preserve the parent-child structure of the document, or you may break some XPath query hidden in firefox' gut.

It should also go without saying that you should backup every file you modify. Having said that, I'm not responsible for you.

Find your firefox installation directory. On my computer, this is /usr/local/bin/firefox; on windows, I would guess it's in C:\Program\ Files. Within this directory, you will find a subdirectory called chrome/, which contains a series of .jar files. Our target is browser.jar.

Copy browser.jar to browser.jar-old right now, before you forget. Oh yeah, close firefox.

Now copy browser.jar to a temporary directory, and unzip it with whatever tool you use. If you have trouble with this step, rename it to browser.zip, and unzip that.

You should see a directory called content/browser/, and in this directory, a series of .xul files. We are interested in content/browser/browser.xul. Open it up with vi, and look at it until you understand how it works.

For our purposes, you only need to understand the meaning of a new elements.

  • < popupmenuset > - here, popup refers to popup menu. The main popup set is the main menu bar used in firefox, and it contains the File, Edit, View, etc menus.
  • < menupopup > - this can refer to a popup menu (such as the File Menu) or to a context menu (like when you right-click on the page).
  • < menuitem > - this refers to a menu entry, such as Open under the File Menu.
So, to remove an unwanted menu item, first find the offending item, and then add the attribute hidden="true".

And to re-order misplaced menu items, re-order the elements.

When you are done yicking with the innards, re-zip the entire directory tree into an archive called browser.jar, and put it where you found the original. Start firefox, and see how you did.

If you get weird behavior, re-examine your modifications or revert to the original file. Lather, rinse, repeat. Enjoy.

And while we're on the topic, let me throw-in a few about:config tweaks that I find completely necessary for Firefox 3. I got most of these from LifeHacker.
  • dom.disable_window_open_feature.menubar, dom.disable_window_move_resize, dom.disable_window_move_resize, dom.disable_window_move_resize, dom.disable_window_move_resize, dom.disable_window_open_feature.titlebar, dom.disable_window_open_feature.titlebar must all be set to false to avoid annoying behavior;
  • browser.tabs.closeButtons = 2, to put the close tab button on the right, not on each tab (like firefox 1.5);
  • browser.backspace_action = 0, so that backspace is equivalent to the Back button;
  • browser.chrome.toolbar_tips = false, to hide tool-tips; and,
  • browser.tabs.tabMinWidth = 75, so it will show more tabs before scrolling them.


Alex said...

What do you mean "Copy browser.jar to browser.jar-old right now..."? Is it me not knowing something or you making a mistake in your explanation?

Nick Johnson said...

@alex - No, it's saying "make a backup of this file".

I think you may be confused because, on a unix system, there's nothing magic about a period in the file name, and so browser.jar-old is a valid filename.

On windows, you might instead copy it to browser.old

Alex said...

nvm i cant do anything other than find the browser file. windows is probably different.

Martín said...

Alex, just Ctrl+C, Ctrl+V over the browser.jar file. You'll get a "Copy of browser.jar" inmediatly.

Raydancer said...

Y'know...there's a perfectly good extension that allows you to customize your menus without getting your hands dirty. Not that I don't love my hacks...sometimes it's just not worth the trouble when the hard work has been done for you.

Nick Johnson said...


No, actually I didn't know that. But if nothing else, doing it manually has brought the extension to my attention.

cypher-neo said...

You were, without a doubt, the first person to release a hack on Firefox 3.

However, there is already a convenient menu editor available on the Mozilla Plugins site. So while this hack would be extremely useful if the extension wasn't available, may I just say that the convenient menu editor provided in the extension is easier to use than editing a series of .jar files.

@raydancer and I both appear to have found the same extension however the link that I'm showing on the Mozilla plugins site is a newer revision than the one on Mozdev. The Menu Editor extension is found here.

Nice hack though! :)

Anonymous said...

Actually, regarding the javascript annoyance settings in about:config (dom.disable_window_move_resize, dom.disable_window_open_feature.titlebar, etc.), they should be set to true (rather than false) to disable the website's ability to restrict your controls.

chăm sóc sức khỏe said...
This comment has been removed by a blog administrator.