WebExtensions/Contribution Onramp
If this is your first contribution to the Firefox codebase, welcome! It can be scary to get started contributing to a large and complex codebase, but we’ve prepared some tips to help you fix a good-first-bug and land a patch in Firefox.
If we haven’t addressed your question in this document, please ask us by leaving a comment in the bug or by joining us on irc.mozilla.org in the #webextensions channel. For a general overview of how to contribute to Firefox, please go here.
General Tips
- If you see a bug that looks interesting, please leave a comment saying that you would like to work on it, or upload your patch to phabricator and request review. Note: we will only assign the bug to you when a patch is uploaded.
- It's ok to ask questions in Bugzilla comments! It's best if you ask specific questions, like, "Can you help me find the line of code that needs changing," and not general questions like, "can you help me."
- It's normal to try things out and get stuck when you're working on your bug. When that happens, we encourage you to try a few different approaches before you ask for help. A good rule of thumb is to try to only needinfo your mentor once a day.
- It might take mentors a day or two to get back to you. If you haven't heard a response in more than two days, please feel free to ping them on irc.mozilla.org in the #webextensions channel.
Getting Started
- If you haven't already done so, create an account on https://bugzilla.mozilla.org.
- Pick a bug you want to work on from the good-first-bugs list.
- Comment on the bug that you would like to work on it and proceed to set up your developer environment.
Setting Up Developer Environment
- Now, you need to set up your development environment by building Firefox. There are two ways to do this:
- [recommended] Build Firefox using Firefox Artifact builds. If the issue only requires changes to privileged JavaScript code, we recommend you use this method. Artifact builds saves time because it downloads a pre-built version of Firefox sources and applies your local changes on it, instead of rebuilding all of the C++ and Rust pieces from scratch.
- Build Firefox for Android requires some additional setup steps. For a faster local development experience, we recommend to use the Artifact builds and the Android x86 target (which is especially useful to run the tests locally).
- Build Firefox from scratch. Note: doing this can take some time. After the initial build, you can build Firefox using the “mach build” command.
- [recommended] Build Firefox using Firefox Artifact builds. If the issue only requires changes to privileged JavaScript code, we recommend you use this method. Artifact builds saves time because it downloads a pre-built version of Firefox sources and applies your local changes on it, instead of rebuilding all of the C++ and Rust pieces from scratch.
- Next, use Searchfox to find the code associated with your bug.
WebExtensions APIs
You can learn more about how WebExtensions internals are organized and how to work on them by reading this internal API documentation and the WebExtensions Hacking wiki.
Fixing the Bug!
- You get to drive the actual bug fix. :)
- We encourage you to check in with the mentor to make sure you are on the right path, or ask for feedback on a patch in progress. You can attach your patch to a comment in Bugzilla and needinfo the mentor for review.
Testing
In order to land code in Firefox, you will need to create tests for your patches. For an overview of the different test systems Firefox uses, please see this overview of automated testing. In the WebExtension API code, most tests are either xpcshell tests or browser chrome tests. Xpcshell tests are preferred because of the lower overhead. Browser tests need to be written when a test interfaces with browser UI, such as tabs or context menus.
The easiest way to get started with tests is to look at existing tests:
- Xpcshell tests:
- toolkit/components/extensions/test/xpcshell/ (Searchfox link)
- browser/components/extensions/test/xpcshell/ (Searchfox link)
- Browser-chrome tests:
- toolkit/components/extensions/test/browser/ (Searchfox link)
- browser/components/extensions/test/browser/ (Searchfox link)
- Firefox for Android mochitests:
- mobile/android/components/extensions/test/mochitest (Searchfox link)
These tests can be run with the “mach test” command. To run a specific test, use “mach test [paths to test files or directories]”. Sometimes "mach test" has bugs (e.g. bug 1498636 and bug 1495311); in that case use "mach xpcshell-test" or "mach mochitest" instead of "mach test" to run the test.
Add your test to an existing file when it is small and fits in that test. Otherwise, create a new test file, and register the test file in one of the .ini files in the same directory as your test, usually browser-common.ini or xpcshell-common.ini.
A test consists of multiple subtasks, which are defined in the test files via add_task(...). Most tests have the following minimal structure:
add_task(async function someShortAndSimpleDescriptionHere() { // Define a test extension. let extension = ExtensionTestUtils.loadExtension( .... ); // Loads the actual extension. await extension.startup(); // Tests here, often using extension.sendMessage and/or extension.awaitMessage // Unload the extension and remove the temporary files. await extension.unload(); });
ExtensionTestUtils.loadExtension allows you to quickly generate a test extension, and its input parameters are documented at: https://searchfox.org/mozilla-central/rev/ef8b3886cb173d5534b954b6fb7eb2d94a9473d0/toolkit/components/extensions/ExtensionTestCommon.jsm#185-212
Another common action in tests is to load a web page or extension page. In xpcshell-tests, use ExtensionTestUtils.loadContentPage.
In browser-chrome tests, the BrowserTestUtils namespace provides many useful test helpers, such as BrowserTestUtils.openNewForegroundTab to open a new tab. BrowserTestUtils is implemented and documented at https://searchfox.org/mozilla-central/source/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
Running the tests (xpcshell tests and Firefox for Android mochitests) on the Android emulator requires some additional setup of the local development environment.
Submitting a Patch
For an overview of how to submit a patch, please see this page on MDN.
- When you are ready to have your patch reviewed, submit your patch to Phabricator:
- First, create an account and install the arc tool.
- If your contribution consists of multiple separate patches, then moz-phab may be an easier way to submit all patches at once.
If you use git, then the standalone phlay tool can also be used instead.
- If your contribution consists of multiple separate patches, then moz-phab may be an easier way to submit all patches at once.
- Then, use these instructions to submit the patch. Choose your mentor as the reviewer.
- Note that you may go through a few iterations before your code is ready to go.
- First, create an account and install the arc tool.
- If you need to make a change to a patch that has already been submitted to Phabricator, make sure you update the existing revision so the reviewers can check the interdiff and history of changes.
- When working on unrelated changes at the same time, it is useful to work on them into separate hg bookmarks (or entire separate mozilla-central clones if you are not yet feeling confident enough with how the hg bookmarks works)
- When the patch is approved, edit your Phabricator revision and add the “Check-in needed” tag.
- QA will verify your patch after it lands, unless your mentor has added a “qa-not-needed” keyword.
- Once your patch is accepted, you can expect to see your code in an upcoming version of Firefox!
Try server
To verify that the patch works as intended, your mentor may schedule a try job on the Try Server to run tests. Contributors with access to the try server can push try jobs to run tests themselves.
See WebExtensions/Try_Server for more information about using the try server to test WebExtension code.