×

Uh-oh, it looks like your Internet Explorer is out of date.

For a better shopping experience, please upgrade now.

Hacking Firefox: More Than 150 Hacks, Mods and Customizations
     

Hacking Firefox: More Than 150 Hacks, Mods and Customizations

by Mel Reyes
 

They dreamed of a better browser . . . and before you could say "explore no more," Firefox was born. But already you want more. Tighter security, greater functionality. A custom installation for Linux. Maybe even that unique extension you've always dreamed of creating. Well, if you want to tweak the Fox, here are over 400 pages of ways to do it. From hacking

Overview

They dreamed of a better browser . . . and before you could say "explore no more," Firefox was born. But already you want more. Tighter security, greater functionality. A custom installation for Linux. Maybe even that unique extension you've always dreamed of creating. Well, if you want to tweak the Fox, here are over 400 pages of ways to do it. From hacking profile settings to cracking links and cleaning out the cookie jar, this is the stuff that puts you in control.

Step-by-step instructions for these hacks and dozens more

  • Settings, content, and extension hacks
  • Hacking the interface and themes
  • Performance boosters
  • Anti-phishing and security hacks
  • Toolbar and status bar tweaks
  • Navigation, download, and search hacks
  • Hacks for common plugins
  • Extension and theme creation

Editorial Reviews

bn.com
The Barnes & Noble Review
As befits one of the world’s hottest open source projects, Firefox is 100 percent tweakable and extensible. Don’t like something? Got a great new idea? Nobody’s stopping you, and plenty of people will welcome your contribution. Hacking Firefox brings together all the knowledge you need to make it happen.

You’ll start by exploring the many tools and resources available to Firefox hackers, including the Document Inspector, basic text editors, the JavaScript console, and Firefox’s personalized profile settings. (Thankfully, author Mel Reyes explains how to back up your Firefox installation before you start messing with it.)

You’ll walk through the fundamentals of hacking Firefox “manually,” through its about:config screen and prefs.js and user.js files. Next, Reyes introduces extensions, showing how they’re packaged and how to tweak troublesome or older ones to work properly with the latest versions of Firefox.

Reyes covers editing themes and icons, then introduces a remarkably wide array of performance tweaks -- ranging from page rendering optimizations to caching. You’ll learn how to modify security and privacy settings, then control the way Firefox displays banner ads, images, and other content.

Hacking Firefox guides you through tweaking menus, toolbars, the status bar, navigation and tabbed browsing, download behavior, and more. You’ll also learn how to use external download managers, control plug-ins, and customize Firefox’s built-in Google search capabilities.

If you’re in an organizational setting, you’ll appreciate Reyes’s coverage of installation and deployment, including creating custom installers. Finally, there’s a full section on Mozilla programming, in which Reyes walks you through creating both extensions and themes. Whether you want to improve your own personal Firefox experience or everyone's, start right here. Bill Camarda, from the October 2005 Read Only

Product Details

ISBN-13:
9780764596506
Publisher:
Wiley
Publication date:
07/25/2005
Series:
ExtremeTech Series , #22
Pages:
456
Product dimensions:
7.40(w) x 9.20(h) x 1.00(d)

Related Subjects

Read an Excerpt

Hacking Firefox


By Mel Reyes

John Wiley & Sons

ISBN: 0-7645-9650-0


Chapter One

Boot Camp

in this chapter

* Installing the Document Inspector

* Editing text tools

* Using the JavaScript Console

* Your profile explained

* Backing up before hacking

Gearing up to hack Mozilla Firefox is as simple as understanding some basic Internet browser features, installing some tools, and being able to find files on your computer system. Then it gets just a tad more complicated. This chapter starts things off by discussing the different methods for hacking Firefox that are covered in this book and how things will progress. Try not to get bogged down with the onslaught of topics that are covered here, because many of them are covered in depth throughout the book.

If you understand some basic web programming tools, such as CSS, JavaScript, and XML, you are one step ahead of the game. Conversely, if you are not well versed in these technologies, you will find plenty of examples and references to guide you along your hack training.

First, we cover some of the key tools you should use to get an edge when hacking Firefox. Tools covered include the Document Inspector, basic text editors, and JavaScript Console. A good portion of this chapter helps you find your personalized Firefox settings in your Profile directory and then highlights the key features of most of the files. As you continue to read this book, you will tap into many of the key components of yourprofile. Then we will approach the different methods of hacking the browser using some of the functionality included with the browser, such as about:config and the JavaScript Console. Finally, you'll learn the basics of changing your preferences and interface by manually hacking the prefs.js, user.js, userChrome.css, and userContent.css files. After getting all your gear, you will begin your quest to understand the core technologies involved in hacking just about every aspect of Mozilla Firefox.

Installing the Document Inspector Gadget

Out of the box, the Firefox Installer has two installation modes: Standard and Custom. If you have already done a Standard installation, you will be missing a key hacking and programming component: the Document Inspector, or DOM Inspector.

The Document Inspector extension is a development tool used to analyze the Document Object Model (DOM) of web pages or the Firefox interface, and is very useful in digging deeper into the core structure of web pages, the Firefox browser window, and browser elements. Currently, this browser development tool is available only from Firefox's main installation process. Later in this chapter and throughout the book, you will begin to see how web page document model standards fit into Firefox's interface customization.

So you want to install the Document Inspector (also called the DOM Inspector), but you already have Firefox installed? No problem. Simply reinstall Firefox, but instead of choosing the Standard installation type, choose the Custom installation type.

Follow the prompts until you get to the Select Components screen. Select Developer Tools, by clicking the checkbox as shown in Figure 1-1, to install the Document Inspector tool.

Once you have completed this installation or reinstallation, you will notice the DOM Inspector in your Tools menu is now available to all profiles on the system. You can use this tool as a resource for dissecting bits and pieces of web pages and the Firefox interface. Figure 1-2 shows the DOM Inspector view of a web page that is currently loaded in the main browser. Note that the hierarchy for the currently loaded web page is displayed in the left-hand panel, with each level or node grouped by the HTML-defined hierarchy and code. Additionally, details on the currently selected node are displayed in the right-hand panel; this panel becomes useful when hacking the Firefox interface.

Occasionally, I have noticed that running the DOM Inspector on a fresh install or reinstall did not yield the desired results or did not work at all. To correct this, I have tried either uninstalling Firefox and then reinstalling with the Developer Tools option enabled, or creating a new Firefox profile. Unless you are running an older version of Firefox that prompts you if you want to delete all the program files, the Firefox uninstaller retains all the supporting plugins and other files that it might need. If prompted to delete all Firefox program files, do not confirm this prompt; doing so will require reinstallation of plugin support for features such as Macromedia Flash, Shockwave, QuickTime and/or RealPlayer. Historically, uninstalling and reinstalling and/or creating a new profile have been the two methods that I have used to resolve mysterious Firefox issues when I could not consistently reproduce them.

Note

For information on how to use the Profile Manager to create a new Firefox profile, visit the incredibly useful MozillaZine Knowledge Base at kb.mozillazine.org/Profile_ Manager.

While having a pretty hierarchy tree of your HTML is nice, the real benefit of the DOM Inspector is using it to hack Firefox itself. Firefox is built on a cross-platform extensible user interface language called XUL, which is based on XML standards and was created to support Mozilla applications. The user interfaces for the Mozilla Suite, Firefox, Thunderbird, and Sunbird all use XUL to create and display the user interface. This interface foundation is the core element that helps all these programs run on different operating systems. The interface is a collection of object definitions used to create each of the elements on the screen.

Using the DOM Inspector can easily help you walk through the hierarchy used to create the actual windows displayed by Firefox. To load the browser window's XUL hierarchy, just follow these steps:

1. In the main browser window navigate to any external web site, such as mrtech.com.

2. Open the DOM Inspector from the Tools menu. At this point, the web site opened in the previous step will be parsed.

3. From the File menu, choose the entry from the Inspect a Window menu option that corresponds with the site opened in the first step, in this case, "MRTech.com - Mozilla Firefox."

After following these steps, the nodes or page elements for the main browser window are loaded and available for visual inspection, as shown in the left-hand Document - DOM Nodes panel of Figure 1-3. For future reference, you can use the following location or URL for the main Firefox browser window to quickly browse the node tree: chrome://browser/ content/browser.xul.

After you have the nodes listed in the left panel for the browser.xul page, just click on Inspect to the right of the location bar to open a window to browse the actual page on the bottom half of the screen (also shown in Figure 1-3).

To find the internal name or id of a specific Firefox window element, I like to use the Select Element By Click option from the Search menu. Once you have selected this, you can click on any of the screen elements on the bottom half of the window and the DOM Inspector jumps to the actual definition for that element within the hierarchy. There you can easily access the internal id associated with the element and use that for future coding or manipulation.

Note

The Select Element By Click option works only after you have clicked on Inspect next to the location bar.

Using the DOM Inspector and Figure 1-3, I will now explain how XUL is used to build the main Firefox browser window. As you see from this figure, there is a XUL object or node called toolbox with an id of navigator-toolbox. This object defines the top-level toolbar container on the main browser window. This container holds the three individual toolbar objects that are visible in the main window. They are toolbar-menubar, nav-bar, and PersonalToolbar. Digging deeper, the nav-bar toolbar object has a toolbarbutton object defined as back-button. This object holds the object information for the Back button, which is displayed on the browser window's navigation toolbar, and the fun continues from there with the rest of the interface XUL definitions.

All in all, the DOM Inspector is the most useful tool to begin digging around and understanding the interface elements that make up the Firefox windows.

Editing and Programming Text Tools

Another tool you will need is a good text-file editor. While the basic text editor that comes with the operating system works for some people, I have found that more functionality is desirable when working with web or Firefox files. Choose an editor with good code syntax highlighting or with other advanced options.

Key attributes to look for in a good programming editor or interface include the following:

* Is it actively developed?

* Can it support Windows, UNIX, Mac OS, and Unicode text-file formats?

* Does it have customizable tab stops or multi- or tabbed-file support?

* Is it free?

Using the editor provided by your operating system may work for you for now, but you may find yourself being a little more productive if you opt for a more up-to-date editor. Several good freeware text editors are actively developed and contain features that even the most diehard vi expert could grow to appreciate and love. Additional coverage on better programming editors is available in Chapter 16. One text editor that I have used in the past is EditPad, which works on Windows and Linux-based systems. I have also used the following Windows-based editors: Notepad++, PSPad, and the quick and simple Win32Pad.

You also have a few options for Linux distributions, including KDevelop, Nedit, Kate for KDE, or GEdit for GNOME. Apple Mac users have a lot of options for editors, including BBEdit, jEdit, and Mellel.

Tip

In addition to these editors, you can download and install the chromeEdit extension, featured in Chapter 2, for basic editing of the user.js, userChrome.css, and userContent.css files. For more information or to download chromeEdit, visit cdn.mozdev.org/chromedit/.

To download any of the aforementioned editors, just visit their sites:

* BBEdit: barebones.com/products/bbedit/

* EditPad: just-great-software.com/

* jEdit: jedit.org/

* Kdevelop: kdevelop.org/

* Mellel: redlers.com/

* Nedit: nedit.org/

* Notepad++: notepad-plus.sourceforge.net/uk/site.htm

* PSPad: pspad.com/en/

* Win32Pad: gena01.com/win32pad/

Tip

For more options and information on programming editors and software, visit thefreecountry.com/programming/editors.shtml.

Using the JavaScript Console

The JavaScript Console is a very handy debugging tool, is a built-in feature of Firefox, and does not require special installation. If you are a web developer or are planning on creating Firefox extensions, the JavaScript Console is the tool that you want to tap into to make sure you use the proper JavaScript syntax and to help you find your coding bugs.

To open the console, select JavaScript Console from the Tools menu. The console shows you three different types of information: Errors, Warnings, and Messages.

When first opened, JavaScript Console shows all messages for your current browser session, as illustrated in Figure 1-4. The console shows errors only if there are any; this includes errors for all sites visited since Firefox was last opened up. If there are no messages displayed, Firefox has not encountered JavaScript errors on any of the pages you have navigated to so far.

A key feature of the console is its ability to jump to the offending code if you click the Source File: link just below the error message. Doing so opens the View Source window directly to the line number referenced in the message, as shown in Figure 1-5.

Cross-Reference

Chapter 15 dives deeper into using the console and covers how to enable some of the advanced debugging preferences. The chapter also shows you how the JavaScript Console is a good area to display status messages while debugging and creating your extensions.

What and Where Is My Profile?

Your settings are stored in a Firefox directory or profile, which Firefox creates right after your first install. Your profile contains all your Firefox-specific settings, including but not limited to the following:

* Extensions

* Themes

* Bookmarks

* Saved form values

* Saved passwords

Additionally, your profile contains any imported settings from Internet Explorer, Netscape 6/7, or Mozilla browsers.

Cross-Reference

Losing any part of your profile can be extremely annoying; Chapter 2 covers how to hack settings in your Firefox profile.

To work with your current profile manually, you first need to find the root directory where your personal settings are stored. To do this, you must follow the directions specific to your operating system, shown in the next section. This operating system-dependent "settings" directory is referred to as your %UserPath% as we continue. From there, you will be able to find the path and directory structure in which Firefox has stored your user profile.

Finding Your User Path

Each operating system has a different directory to which it saves your user settings. Most applications take advantage of this operating system "user path" to store their settings, so as not to collide with other users who might log into the same computer. Firefox does the same; it uses this directory to create the user's profile. The challenge is that each operating system uses a different naming and directory structure to store these files and settings. Making life even more complicated, different versions of the same operating system (for example, Windows) use different structures. Peruse the following subsections to find the operating system you are currently using, and read how to find your user path.

Using Windows?

If you are using Windows, your user directory should look similar to this:

* Windows 2000/XP: C:\Documents and Settings\\Application Data\

* Windows NT: c:\Windows\Profiles\\

* Windows 9x/ME: C:\Windows\Application Data\Mozilla\Firefox

Note

The drive (C:\ above) and location of the default Windows directory may vary based on your custom installation.

Using Linux/UNIX?

If Linux/UNIX is your modus operandi, you should expect to find your Firefox profile in a directory similar to ~/.mozilla/firefox.

Using Mac OS?

Finally, for all you Apple aficionados, your directory structure should be something similar to ~/Library/Application Support/Firefox.

Now that you have found your user directory, this will now be referred to as %UserPath% and will be used to track down where Firefox has stored your profile.

Note

For official information on locating your Firefox profile, visit mozilla.org/ support/firefox/edit#profile.

Express Pass to Your Profile Path

One nice feature that Firefox finally enabled is human-readable settings for the profile.ini file with the direct or relative path to the current profile(s). Prior to this, profile information was stored in binary format only, and automating and scripting Firefox profiles was difficult to do. The profiles.ini file lives in the now common path for Firefox Profiles, which is as follows: %UserPath%\Mozilla\Firefox\.

The profiles.ini file will look similar to the following if this was the first time you installed Firefox:

[General] StartWithLastProfile=1

[Profile0] Name=default IsRelative=1 Path=default\zsryldfv.slt

In this first example, notice that the IsRelative setting is equal to 1, which is a Boolean toggle for true. This means that the path is relative to the common Mozilla Firefox path of %UserPath%\Mozilla\Firefox\, so the full directory path would look something like %UserPath%\Mozilla\Firefox\default\zsryldfv.slt.

Note that zsryldfv in the path is a randomly generated directory name and varies from system to system. If you had previously installed earlier builds of Firefox that stored the profiles in other places, the profiles.ini file might look something like this:

[General] StartWithLastProfile=1

[Profile0] Name=default IsRelative=0 Path=%UserPath%\Firefox\Profiles\default\zsryldfv.slt

Moreover, you will notice that IsRelative is zero or false, so the Path entry in the file reads as-is, or absolute, and that is where you will find your current profile.

(Continues...)



Excerpted from Hacking Firefox by Mel Reyes Excerpted by permission.
All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.

Meet the Author

Mel Reyes, a veteran of technology and programming, is an avid fan and user of Firefox and all its predecessors. He programs in several languages, works with a variety of technologies, and runs MRTech.com, which provides free technology news, support, tips, and software. He works in several industries helping clients with web, desktop, and database application development. Mel can be reached by e-mail at mel@mrtech.com.

Customer Reviews

Average Review:

Post to your social network

     

Most Helpful Customer Reviews

See all customer reviews