Firefox/Dev Cheatsheet

From MozillaWiki
Jump to: navigation, search

Firefox Developer Cheatsheet

Originally by Brian Bondy, posted here.


   mozilla-central (Latest for Firefox):
   Mozilla Aurora:
   Mozilla Beta:
   Mozilla Release:
   comm-central (Latest for Thunderbird, SeaMonkey, Lightning/Sunbird):
   Mozilla Inbound (Push changes here to get them on mozilla-central):


   Edit, debug, and monitor JavaScript, CSS, HTML, and external XUL
   Chromebug (Requires a matching Firebug version)
   Debug Firefox itself's XUL, XBL, Javascript, ... (debug chrome)
   Extension Developer
   Interactive JavaScript shell, live preview HTML and XUL editors, regular expression and XPath testers, and packaging tool


   Copy to: <installDir>\Plugins
   Environment variable MOZ_DEBUG_CHILD_PROCESS=1 can be used to delay 30 seconds when loading plugin-container before the plugin is loaded.
   Plugin development


   Use Firebug and Chromebug to debug XUL, XBL, JavaScript
   Debug C++ src in Windows: Open VS2010, select open project, select dist/bin/firefox.exe in your obj dir. Press F5. Change source, do an incremental build, open the source and set breakpoints in VS2010.

Command Line

   -purgecaches use when changing XUL, XBL, JSM, ...
   -no-remote allows you to run multiple instances of the program with different profiles
   -console starts the application with a debug console
   -ProfileManager starts the application with the profile manager
   -P "profilename" starts the application with the specified profile
   Other command line options


   about:crashes gives you links to your crashes
   Online crash reports and stats

Getting help

   Some channels: #developers, #introduction, #xul, #planning, #jsapi, #gfx
   More info on IRC
   NNTP Server
   Google group
   Mailing list

Useful links when getting started

   Ability to edit bugs on bugzilla (editbugs privs)
   Getting commit access
   Mozilla source code directory structure 

Useful links forever

   Mozilla central push log
   Mozilla central Nightly builds
   MXR (Browse source code online)
   DXR (Search source code online)
   Tinderbox (Tool to ensure compiles on various platforms and all automated)
   Modules and module owners (for code reviews and questions)
   Top crash reports
   License Boilerplate

Coding style

   line length: 80 chars or less
   indenting: 2 spaces (no tabs)
   Function definitions, braces on newlines
   Conditionals and loops:
   if (condition) {
   Multiline, align with parentheses:
   if (argument1 == paramvalu1 && argument2 == paramvalue2 &&
       argument3 == paramvalue3 && argument4 == paramValue4) {
   Comments, use space after comment indicator
   More info on coding style

Build commands

   Full build of Firefox: (~ 1h)
   make -f
   To rebuild Firefox without pulling the tree: (~25min)
   make -f build_all_depend
   To clean: (~2min)
   make -f distclean
   Incremental builds (~2min, see below section)
   Full build of Thunderbird or other comm-central
   python checkout (which clones a copy of mozilla-central inside a subfolder called mozilla)
   make -f
   Make an objdir for partial tree
   cd $(objdir)
   ../build/autoconf/make-makefile component/path
   cd $(objdir)/component/path

Example .mozconfig files (Gecko 2.0 and up)

   Firefox Debug .mozconfig contents: (Using mozilla-central)
   mk_add_options MOZ_OBJDIR=@TOPSRCDIR@objdir-ff-debug
   ac_add_options --enable-application=browser
   ac_add_options --enable-debug
   ac_add_options --disable-optimize
   ac_add_options --enable-tests
   Firefox Release .mozconfig contents: (Using mozilla-central)
   mk_add_options MOZ_OBJDIR=@TOPSRCDIR@objdir-ff-debug
   ac_add_options --enable-application=browser
   ac_add_options --enable-optimize
   ac_add_options --enable-debug-symbols
   xulrunner .mozconfig contents: (Using mozilla-central)
   mk_add_options MOZ_OBJDIR=@TOPSRCDIR@objdir-xulrunner-debug
   ac_add_options --enable-application=xulrunner
   ac_add_options --enable-debug
   ac_add_options --disable-optimize
   Thunderbird .mozconfig contents: (Using comm-central)
   mk_add_options MOZ_OBJDIR=@TOPSRCDIR@objdir-tb-debug
   ac_add_options --enable-application=mail
   ac_add_options --enable-debug
   ac_add_options --disable-optimize
   #If you also want Lightning
   ac_add_options --enable-calendar
   SeaMonkey .mozconifg contents: (Using comm-central)
   mk_add_options MOZ_OBJDIR=@TOPSRCDIR@objdir-seamonkey-debug
   ac_add_options --enable-application=suite
   ac_add_options --enable-debug
   ac_add_options --disable-optimize
   Sunbird .mozconifg contents: (Using comm-central)
   mk_add_options MOZ_OBJDIR=@TOPSRCDIR@objdir-sunbird-debug
   ac_add_options --enable-application=calendar
   ac_add_options --enable-debug
   ac_add_options --disable-optimize

Incremental builds

   Don't use make in subdirectories from within the source dirs, use the obj dir which is created when you first build (Example: obj-i686-pc-mingw32\widget)
   Example if you have changes to /widget:
   cd obj-i686-pc-mingw32
   make -C widget
   make -C toolkit/library


   Logging Javascript with Firebug/Chromebug:
   console.log("my output");
   console.log("%s is %d years old.", "Bob", 42).
   Netscape portable runtime logging (PR_LOG):
   Environment variables:
   NSPR_LOG_FILE = WinDebug and it will output to the debug output window or use NSPR_LOG_FILE=C:\nspr-log.txt to output to a file by that name
   NSPR_LOG_MODULES can specify which modules to log with the, example NSPR_LOG_MODULES = nsWindowsWidgets:5 (5 is the log level) You can use NSPR_LOG_MODULES=all:5 to enable all module logging

Finding source of regressions

   Do a binary search on the nightly builds until you narrow down a build that introduced the regression
   Use the push log to review changes in that time span
   Use mozregression

Submitting a patch for review

   You don't have commit access at first, instead create a patch.
   Setup your author information (your ~/.hgrc or ~/mercurial.ini on Windows):
   username = Your Name <>
   Use the mq extension, add to your ~/.hgrc or ~/mercurial.ini on Windows
   [extensions] =
   When submitting do this

Creating a patch (and working with patches)

   To create a patch:
   hg qnew bugXXXXXX.patch
   On popup: Bug XXXXXX - Description of your fix
   To take a file out of a patch:
   hg qrefresh -X re:regexp_pattern_of_files_to_remove
   To refresh changes into your patch:
   hg qrefresh
   To see the status of changes: (after you take out files it should re-appear in the changes)
   hg status
   Undo application of a patch in your MQ patch queue: (Removes the patch from your commit tree and working directory)
   hg qpop (To unapply the last applied patch)
   hg qpop -a (To unapply all patches)
   hg qpop name.patch (To unapply all patches up to but not including the specified patch)
   Apply a patch which is in your MQ patch queue: (Re-adds the patch to your commit tree and working directory, you can apply more than one patch)
   hg qpush (To apply the next patch in the series)
   hg qpush -a (To apply all patches)
   hg qpush name.patch (To apply all patches in the series up to and including the named patch)
   List which patches are in your MQ patch queue:
   hg qseries
   List which patches in your MQ patch queue are applied (pushed):
   hg qapplied
   List which patches in your MQ patch queue are not yet applied (pushed):
   To delete a patch from your MQ patch queue: (Patch must first be unapplied)
   hg qdelete
   To turn a patch into a permanent changeset: (Patch must first be applied)
   hg qfinish
   To turn a normal changeset into a patch: (Patch must first be unapplied)
   hg qimport -r tip
   Convert a patch to a finalized changeset: (Patch must first be applied)
   hg qfinish tip
   hg qfinish -a (for all of the patches
   To make a backup of your patches directory: (Saves the patches backup to .hg/patches.N)
   hg qsave
   To import someone else's patch into your MQ patch queue:
   hg qimport patchname.patch (You must later also apply it with qpush)
   To import someone else' patch with a different patch strip count:
   patch -pN (to apply the patch, where N is the strip count of the patch)
   qnew (to create a new patch)
   hg addremove (to pickup any files added/removed by the patch)
   qrefresh (to refresh the patch)
   To change the ordering of how patches are applied
   Manually edit your .hg/patches/series file, one patch name per line.
   To rollup several patches into one
   hg diff -r qparent > rollup.patch
   See last 50 pushed
   hg log -l 50
   Undoing a qfinish or remove last commit into a patch
   hg qimport -r tip (Make sure you have no other patches applied)
   To backout a revision
   hg backout revnumber
   Folding a patch in your queue onto another one
   hg qgoto base_patch.patch
   hg qfold patch_to_fold_in_base_patch.patch
   Renaming a patch
   hg qrename new_patch_name.patch


   How to help with documentation

Testing and QA

   Automated testing link1 link2
   Litmus (Manual testing)
   Mochitest for testing via pages (HTML, XHTML, SVG, XUL, XBL) (mochitest-plain, mochitest-chrome, mochitest-browser-chrome, mochitest-a11y or mochitest-ipc)
   Browser chrome mochitest for testing via JS
   Reftests for testing if 2 pages that should render the same actually do
   Compiled code tests
   xpcshell for testing XPCOM components

Automated test run examples

   TEST_PATH=content/html/content/test make -C $(OBJDIR) mochitest-plain
   mochitest-chrome: (like a mochitest but with chrome privs)
   TEST_PATH=widget/tests/ make -C $(OBJDIR) mochitest-chrome
   mochitest-browser-chrome: (Chrome JS tests)
   TEST_PATH=widget/tests/ make -C $(OBJDIR) mochitest-browser-browser-chrome
   cd $(OBJDIR)
   make -C widget/tests/ xpcshell-tests
   TEST_PATH=modules/libpr0n/test/reftest/reftest.list make -C obj-i686-pc-mingw32 reftest

Troubleshooting build problems

   I built on windows, and had crashes on startup:
   The reason ended up being because I was using the same profile as my FF4 and some extensions were causing the crash (Firebug in particular). Simply disabling the extensions fixed the problem.
   If you are building on Windows with VC2010, and get the error, install the Win7.0 SDK instead. Alternatively if you really want to use 7.1 you may need to patch your guess-msvc.bat 


   Blank page:
   To adjust settings:
   To see how your Firefox was built:
   To see all of your crash reports:

Common about:config prefs

   Allow remote XUL from local computer:
   dom.allow_XUL_XBL_for_file: true;

XPCOM objects in JavaScript

   Creating an XPCOM component:
   var cid = ";1"
   var obj = Components.classes[cid].createInstance();
   obj = obj.QueryInterface(Components.interfaces.IMyInterface)
   Listing XPCOM components:
   for (var c in Components.classes) { print(c); }
   Listing XPCOM interfaces:
   for (var i in Components.interfaces) { print(i); }

How to push to try

   Need commit access level 1
   Try server info
   Try server command line generator
   In .hgrc (or mercurial.ini) add:
   try = ssh://
   To push the applied hg queue patches to the try server:
   hg qrefresh --message "try: -b do -p all -u all -t all"
   hg push -f try

How to push a changeset from your MQ

   If you want your patch to land on Aurora, or Firefox Beta you need to request it in Bugzilla. only for severe security, stability, or regressions recently introduced. Provide risk/reward in ticket.
   Need commit access level 3
   In .hgrc (or mercurial.ini) add:
   mozilla-inbound =
   To push:
   Move your patch to the top of your queue
   hg pull
   hg update
   hg qpush
   hg qrefresh -m "Bug xxx - Blah. Blah. Blah. r=xyz"
   hg qfinish -a
   hg push mozilla-inbound

Bugzilla keywords

   addon-compat: If your change may affect addon compatibility
   dev-doc-needed: If your change may need documentation
   regression: If your bug is a regression
   checkin-needed: If a checkin is needed for a patch but the author can't do it themselves because of privs or some other reason

Firefox UI debugging

   Extesion Developer Extension
   Or in any build of Firefox:
       Type about:
       Open the web console
       Type in the following:
       this.__proto__ = Services.wm.getMostRecentWindow('navigator:browser');
       Now you can use anything you can in the extensions developer extension

Contributor info and Metrics

   Contributor Map / Contribution Trends

Doing Code Reviews

   Code Review Guide
   Quick Points:
       MultiByte vs. Wide character set comm-central defaults to ASCII
       Check if platform API available pre Win2k
       Does it pass try?
       Comments, typos, spelling
       Did you test in scenario X?
       New import libs in toolkit/library?
       Should it have tests?
       Interface change? Change IID, sr required, addon-compat keyword
       Documentation needed?
       Mark keywords for post-fix work: dev-doc-needed, privacy-review-needed, sec-review-needed, user-doc-needed, addon-compat, release tracking flags, in-testsuite flag


   More info on themes