Einar Egilsson

URL-2-Titlebar Firefox Add-on

Posted: Last updated:

Recently I got a request in the mail from a user of one of my Firefox add-ons. He asked me if I could make an add-on that displayed the url of the current tab in the titlebar instead of the actual title of the page being shown. I'm not interested in creating more add-ons for Firefox or Thunderbird, they take up quite a lot of time with user requests, getting approved by the Mozilla addons site, etc. That is why I've discontinued 6 out of the 9 add-ons I've created. But anyway, I knew that it would be trivial to make this add-on so I decided to help this person out.

You can download the add-on here. This add-on will never be updated or published on AMO, it is offered strictly as-is. The one thing I found interesting about this was figuring out how to do the absolute minimum to get this add-on working. There is no localization, no folder structure, just three files, install.rdf, chrome.manifest and url2titlebar.xul. Put those into a zip file, rename it to .xpi and you have your extension. These of course are not best practices in extension development, just an exercise in making the simplest extension possible. Below is the full content of the three files:


<?xml version="1.0" encoding="UTF-8"> <overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <script> window.addEventListener('load', function() { function setTitle() { document.title = gBrowser.selectedBrowser.contentDocument.location; } gBrowser.tabContainer.addEventListener('TabSelect', setTitle, false); document.addEventListener('pageshow', setTitle, false); setTitle(); },false); <script> </overlay>


content url2titlebar file:./ overlay chrome://browser/content/browser.xul chrome://url2titlebar/content/url2titlebar.xul


<?xml version="1.0" encoding="UTF-8"?> <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"> <Description about="urn:mozilla:install-manifest"> <em:id>url2titlebar@einaregilsson.com</em:id> <em:name>URL-2-Titlebar</em:name> <em:version>0.0.1</em:version> <em:creator>Einar Egilsson</em:creator> <em:description>Set the title of the window to the current url</em:description> <em:targetApplication> <Description> <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> <!-- firefox --> <em:minVersion>3.0</em:minVersion> <em:maxVersion>3.5.*</em:maxVersion> </Description> </em:targetApplication> </Description> </RDF>

So, there you have it, the simplest possible Firefox add-on. Enjoy!

If you read this far you should probably follow me on Twitter or check out my other blog posts.