Skip to content

Karma Firefox Launcher

Testing exclusively in Chrome misses Firefox-specific rendering and API behavior. This lesson covers karma-firefox-launcher, the standard way to add Firefox and FirefoxHeadless to a Karma suite.

Installing and Using karma-firefox-launcher

karma-firefox-launcher mirrors the Chrome launcher's API closely, providing Firefox (visible window), FirefoxHeadless (no window), and FirefoxDeveloper (Firefox Developer Edition, if installed) launcher configurations.

npm install --save-dev karma-firefox-launcher

// karma.conf.js
config.set({
  browsers: ['ChromeHeadless', 'FirefoxHeadless']
});

Listing both browsers runs the full suite twice, once per engine, and reports results separately for each.

Common Firefox Launcher Names

Firefox              // visible window
FirefoxHeadless        // no window, standard for CI
FirefoxDeveloper         // Firefox Developer Edition, if installed
  • FirefoxHeadless requires a reasonably modern Firefox version with native headless support.
  • Karma looks for Firefox in standard install locations automatically before falling back to FIREFOX_BIN.
  • Firefox and Chrome occasionally diverge on timing-sensitive or CSS-dependent test assertions — that divergence is often the entire point of testing both.
  • Firefox's process startup is sometimes slower than Chrome's; account for this in shared timeout settings.

Firefox Launcher Cheat Sheet

Configuration snippets for common Firefox launcher needs.

Need Configuration
Basic headless run browsers: ['FirefoxHeadless']
Point at a custom binary process.env.FIREFOX_BIN = '/path/to/firefox'
Cross-browser run browsers: ['ChromeHeadless', 'FirefoxHeadless']
Firefox profile preferences customLaunchers with a prefs object

Custom Firefox Preferences via customLaunchers

karma-firefox-launcher supports a prefs object on custom launcher configurations, letting you tweak Firefox profile preferences — for example, disabling animations that can otherwise interfere with timing-sensitive UI tests.

customLaunchers: {
  FirefoxHeadlessNoAnim: {
    base: 'FirefoxHeadless',
    prefs: {
      'toolkit.cosmeticAnimations.enabled': false
    }
  }
},
browsers: ['FirefoxHeadlessNoAnim']

Troubleshooting FIREFOX_BIN

Just like Chrome, when Firefox isn't installed in a location the launcher checks automatically (common on minimal Linux CI images), setting FIREFOX_BIN explicitly resolves the launch failure.

export FIREFOX_BIN=/usr/lib/firefox-esr/firefox-esr
karma start --single-run --browsers FirefoxHeadless

Common Mistakes

  • Assuming Firefox and Chrome will always produce identical results for CSS or timing-sensitive tests.
  • Not installing Firefox at all on a CI image before configuring FirefoxHeadless in the browsers list.
  • Running Firefox and Chrome with identical shared timeouts, without accounting for Firefox's sometimes slower startup.
  • Overlooking FIREFOX_BIN as the fix for a launch failure that looks unrelated to configuration at first glance.

Key Takeaways

  • karma-firefox-launcher provides Firefox, FirefoxHeadless, and FirefoxDeveloper launcher configurations.
  • Adding Firefox alongside Chrome catches genuine cross-browser discrepancies that single-browser testing misses.
  • FIREFOX_BIN is the standard fix when Firefox isn't found in an expected install location.
  • Custom launcher prefs objects let you tune Firefox profile settings without a full custom plugin.

Pro Tip

If you only have bandwidth to test in two browsers, ChromeHeadless plus FirefoxHeadless gives the best coverage-to-effort ratio for most web applications, since they use genuinely different rendering and JavaScript engines.