CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-karma-chrome-launcher

A Karma plugin that provides browser launchers for Chrome, Chrome Canary, Chromium, and Dartium browsers for JavaScript testing.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Karma Chrome Launcher

Karma Chrome Launcher is a Karma plugin that provides browser launchers for Chrome, Chrome Canary, Chromium, and Dartium browsers. It enables JavaScript testing in various Chrome-based browser environments including headless mode, making it essential for cross-browser testing workflows and continuous integration pipelines.

Package Information

  • Package Name: karma-chrome-launcher
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install --save-dev karma-chrome-launcher

Core Imports

// The package exports Karma DI modules, typically used via Karma configuration
const karmaChromeLauncher = require('karma-chrome-launcher');

// Or when installed as a plugin, Karma loads it automatically:
// plugins: ['karma-chrome-launcher']

Basic Usage

// karma.conf.js
module.exports = function(config) {
  config.set({
    // Basic browser configuration
    browsers: ['Chrome', 'ChromeHeadless'],
    
    // Custom launcher with flags
    customLaunchers: {
      Chrome_without_security: {
        base: 'Chrome',
        flags: ['--disable-web-security', '--disable-site-isolation-trials']
      },
      Chrome_with_debugging: {
        base: 'Chrome',
        chromeDataDir: path.resolve(__dirname, '.chrome')
      }
    },
    
    // Include the plugin
    plugins: [
      'karma-chrome-launcher',
      // other plugins...
    ]
  });
};

Capabilities

Browser Launchers

The package provides Karma dependency injection modules for launching different Chrome-based browsers.

// Main module exports - Karma DI configuration object
module.exports = {
  'launcher:Chrome': ['type', ChromeBrowser],
  'launcher:ChromeHeadless': ['type', ChromeHeadlessBrowser], 
  'launcher:ChromeCanary': ['type', ChromeCanaryBrowser],
  'launcher:ChromeCanaryHeadless': ['type', ChromeCanaryHeadlessBrowser],
  'launcher:Chromium': ['type', ChromiumBrowser],
  'launcher:ChromiumHeadless': ['type', ChromiumHeadlessBrowser],
  'launcher:Dartium': ['type', DartiumBrowser]
};

Each launcher supports the following configuration options:

interface LauncherArgs {
  /** Array of command-line flags to pass to the browser */
  flags?: string[];
  /** Custom Chrome user data directory path (overrides default temp directory) */
  chromeDataDir?: string;
}

/** Browser launcher constructor function signature */
type BrowserLauncher = (baseBrowserDecorator: Function, args: LauncherArgs) => void;

/** Browser launcher prototype with required properties */
interface BrowserPrototype {
  /** Browser name identifier */
  name: string;
  /** Platform-specific default command paths */
  DEFAULT_CMD: {
    linux?: string | null;
    darwin?: string | null;
    win32?: string | null;
  };
  /** Environment variable name for binary path override */
  ENV_CMD: string;
  /** Internal method to generate browser command-line options */
  _getOptions(url: string): string[];
}

Chrome Browser

Standard Chrome browser launcher for desktop testing.

// Used in Karma configuration
browsers: ['Chrome']

// Environment variable override
CHROME_BIN=/path/to/chrome karma start

Platform Support:

  • Linux: Searches for google-chrome or google-chrome-stable
  • macOS: Uses /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
  • Windows: Searches Chrome installation directories

Default Flags Added: Chrome automatically adds these flags to all instances:

--user-data-dir=<temp-dir>
--enable-automation
--no-default-browser-check
--no-first-run
--disable-default-apps
--disable-popup-blocking
--disable-translate
--disable-background-timer-throttling
--disable-renderer-backgrounding
--disable-device-discovery-notifications

Chrome Headless Browser

Chrome browser in headless mode for CI/CD environments.

// Used in Karma configuration  
browsers: ['ChromeHeadless']

// Automatically adds headless flags:
// --headless, --disable-gpu, --disable-dev-shm-usage
// --remote-debugging-port=9222 (if not already specified)

Chrome Canary Browser

Chrome Canary browser launcher for testing with bleeding-edge Chrome features.

// Used in Karma configuration
browsers: ['ChromeCanary']

// Environment variable override  
CHROME_CANARY_BIN=/path/to/chrome-canary karma start

// Automatically adds performance flags:
// --js-flags=--nocrankshaft --noopt

Chrome Canary Headless Browser

Chrome Canary browser in headless mode.

// Used in Karma configuration
browsers: ['ChromeCanaryHeadless']

Chromium Browser

Open-source Chromium browser launcher.

// Used in Karma configuration
browsers: ['Chromium']

// Environment variable override
CHROMIUM_BIN=/path/to/chromium karma start

Platform Support:

  • Linux: Searches for chromium-browser or chromium
  • macOS: Uses /Applications/Chromium.app/Contents/MacOS/Chromium
  • Windows: Searches Chromium installation directories

Default Flags Added: Chromium automatically adds these flags to all instances:

--user-data-dir=<temp-dir>
--no-default-browser-check
--no-first-run
--disable-default-apps
--disable-popup-blocking
--disable-translate
--disable-background-timer-throttling

Note: Chromium does not include the --enable-automation, --disable-renderer-backgrounding, and --disable-device-discovery-notifications flags that Chrome includes.

Chromium Headless Browser

Chromium browser in headless mode.

// Used in Karma configuration
browsers: ['ChromiumHeadless']

Dartium Browser (Deprecated)

Legacy Dartium browser launcher for Dart applications. Note: Dartium is obsolete as Dart web development now uses standard browsers.

// Used in Karma configuration
browsers: ['Dartium']

// Environment variable override
DARTIUM_BIN=/path/to/dartium karma start

Configuration Examples

Custom Flags

// karma.conf.js
customLaunchers: {
  Chrome_without_security: {
    base: 'Chrome',
    flags: [
      '--disable-web-security',
      '--disable-site-isolation-trials',
      '--allow-running-insecure-content'
    ]
  }
}

Custom User Data Directory

// karma.conf.js
const path = require('path');

customLaunchers: {
  Chrome_with_debugging: {
    base: 'Chrome',
    chromeDataDir: path.resolve(__dirname, '.chrome')
  }
}

JavaScript Flags

The launcher provides special handling for --js-flags parameters:

customLaunchers: {
  Chrome_with_js_flags: {
    base: 'Chrome',
    flags: ['--js-flags="--expose-gc --harmony"']
  }
}

Puppeteer Integration

// karma.conf.js
process.env.CHROME_BIN = require('puppeteer').executablePath();

module.exports = function(config) {
  config.set({
    browsers: ['ChromeHeadless']
  });
};

Test Utilities

The package also exports test utilities for internal function testing:

// Available on module.exports.test
const testUtils = require('karma-chrome-launcher').test;

/**
 * Check if a flag is a JS flags parameter
 * @param {string} flag - Command line flag to check
 * @returns {boolean} True if flag starts with --js-flags=
 */
function isJSFlags(flag);

/**
 * Sanitize JS flags by removing quotes
 * @param {string} flag - JS flags parameter to sanitize
 * @returns {string} Sanitized flag without quotes
 */
function sanitizeJSFlags(flag);

/**
 * Generate headless browser options
 * @param {string} url - Target URL
 * @param {object} args - Launcher arguments
 * @param {function} parent - Parent options function
 * @returns {string[]} Array of command line options
 */
function headlessGetOptions(url, args, parent);

/**
 * Generate Chrome Canary browser options  
 * @param {string} url - Target URL
 * @param {object} args - Launcher arguments
 * @param {function} parent - Parent options function
 * @returns {string[]} Array of command line options
 */
function canaryGetOptions(url, args, parent);

Browser Detection

The package automatically detects browser installations using platform-specific logic:

/**
 * Get Chrome executable path on Windows
 * @param {string} chromeDirName - Chrome directory name ('Chrome' or 'Chrome SxS')
 * @returns {string|null} Path to chrome.exe or null if not found
 */
function getChromeExe(chromeDirName);

/**
 * Get Chromium executable path on Windows  
 * @returns {string|null} Path to chromium chrome.exe or null if not found
 */
function getChromiumExe();

/**
 * Find binary using which command on Linux
 * @param {string[]} commands - Array of command names to search for
 * @returns {string|null} First found command or null
 */
function getBin(commands);

/**
 * Get Chrome path on macOS with user directory fallback
 * @param {string} defaultPath - Default application path
 * @returns {string} Resolved Chrome path
 */
function getChromeDarwin(defaultPath);

Windows Detection

  • Searches environment variables: LOCALAPPDATA, PROGRAMFILES, PROGRAMFILES(X86), ProgramW6432
  • Chrome path: <ENV_VAR>\Google\<ChromeDirName>\Application\chrome.exe
    • Regular Chrome uses directory name Chrome
    • Chrome Canary uses directory name Chrome SxS
  • Chromium path: <ENV_VAR>\Chromium\Application\chrome.exe

Linux Detection

  • Uses the which command to find executables in PATH
  • Chrome: searches for google-chrome, google-chrome-stable
  • Chrome Canary: searches for google-chrome-canary, google-chrome-unstable
  • Chromium: searches for chromium-browser, chromium (prioritizes chromium-browser to avoid conflict with legacy chromium-bsu package)

macOS Detection

  • Uses hardcoded application paths with user home directory fallbacks
  • Chrome: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    • Fallback: $HOME/Applications/Google Chrome.app/Contents/MacOS/Google Chrome
  • Chrome Canary: /Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary
    • Fallback: $HOME/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary
  • Chromium: /Applications/Chromium.app/Contents/MacOS/Chromium

Dependencies

  • which: "^1.2.1" - Used to locate browser executables on Linux platforms
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/karma-chrome-launcher@3.1.x
Publish Source
CLI
Badge
tessl/npm-karma-chrome-launcher badge