Accessing/modifying the Firefox tab context menu from extensions

I recently made a few add-on-relevant changes to Firefox’s tab context menu on the Firefox trunk, and wanted to mention them here. They were triggered by evaluating some of the extension bustage that bug 347930 caused.

Accessing the tab context menu

One of bug 347930‘s changes was moving the tabbrowser context menu from the <tabbrowser>’s anonymous content to the tab container’s anonymous content. The tab container is also no longer a child of the tabbrowser, so some common methods of accessing the context menu <menupopup> element broke. I tried to address this in bug 554165 by making two changes:

  1. Adding a gBrowser.mStrip compatibility shim JS object to keep some of the common references working
  2. Introducing a gBrowser.tabContextMenu property as a supported tabbrowser API. The hope is that extensions will make use of this property rather than the hacky alternatives they’ve been required to use in the past. We can keep this property working regardless of the underlying implementation details, which could potentially change again in the future.

Adding elements to the tab context menu

MozillaZine community member “onemen” pointed out that putting the tab context menu in anonymous content made it a pain to modify (requires modifying it dynamically from code). So I filed and fixed bug 554991, the net effect of which is that the “tabContextMenu” <menupopup> is now defined in browser.xul, and can be modified using normal XUL overlays. It’s also still accessible via gBrowser.tabContextMenu, of course.

Both of these changes only apply to Firefox trunk builds, which means they don’t apply to 3.6 or earlier.

5 thoughts on “Accessing/modifying the Firefox tab context menu from extensions

  1. Pingback: Add-ons Review Update – Week of 2010/04/13 « Mozilla Add-ons Blog

  2. LouCypher

    All my extensions on AMO are using tab context menu, generated dinamically from JS. This changes will make it come in handy to add and modify them from XUL overlay. Thanks.

  3. anonymous

    instead of having the add-ons rely on object events … would it be possible to hook to a global listener? (having a standard global listener will greatly help extension authors of not relying to changes in even and object configuration in xul).

  4. gavin Post author

    @anonymous – not sure exactly what you’re referring to (my post didn’t mention events). If you have any suggestions for tabbrowser improvements, feel free to file a bug and CC me!

Comments are closed.