Chrome Extension Firefox Migration — Developer Guide
2 min readChrome Extension Migration to Firefox
Guide for porting Chrome extensions to Firefox, covering API compatibility and best practices.
Overview
Porting Chrome extensions to Firefox is straightforward. Firefox’s WebExtensions API is largely compatible with Chrome’s.
Browser Namespace
Firefox supports both chrome.* and browser.* namespaces. Use browser.* for Promise-based APIs:
// Chrome (callback-based)
chrome.storage.local.get('key', (result) => console.log(result.key));
// Firefox (Promise-based)
const result = await browser.storage.local.get('key');
WebExtensions Polyfill
Use webextension-polyfill for consistent Promise APIs:
import browser from 'webextension-polyfill';
await browser.storage.local.set({ key: 'value' });
Manifest Differences
Manifest V2
Firefox still supports MV2. Use browser_action instead of action.
Manifest V3
Firefox has limited service worker support for MV3 backgrounds.
Background Scripts
Firefox supports both persistent and event-based backgrounds:
{
"background": {
"scripts": ["background.js"],
"persistent": false
}
}
Content Scripts
Content scripts are mostly compatible between Chrome and Firefox. Both support:
- Programmatic injection via
chrome.scripting.executeScript - Declarative injection in manifest
- Access to DOM and Chrome/Firefox extension APIs
Building for Both Browsers
Use conditional code or build-time configuration:
const isFirefox = typeof browser !== 'undefined' && !chrome.runtime?.id;
if (isFirefox) {
// Firefox-specific code
}
Or use build tools to swap polyfills based on target browser.
Storage API
The browser.storage API is fully compatible: storage.local, storage.sync, and storage.managed.
Messaging
Message passing works identically in both browsers:
browser.runtime.sendMessage({ greeting: 'hello' });
browser.runtime.onMessage.addListener((message) => console.log(message));
APIs Not Available in Firefox
chrome.sidePanel- Usebrowser.sidebarActioninstead- Some
chrome.declarativeNetRequestfeatures
Firefox-Only APIs
browser.sidebarAction- Sidebar controlbrowser.find- Page search
Testing
Use web-ext tool: npm install -g web-ext && web-ext run
Use about:debugging for Firefox extension inspection.
Packaging
Firefox uses .xpi format: web-ext build
Publishing
- Create account at addons.mozilla.org (AMO)
- Upload
.xpifile - Undergo review
- Publish after approval
Cross-Reference
Related Articles
Related Articles
Part of the Chrome Extension Guide by theluckystrike. Built at zovo.one.