User Agents

Web browsers and everyday web tech, explained

Fix Wallaby Crashes with Headless Chrome

· 5 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Wallaby.js sometimes crashes when it tries to launch or communicate with headless Chrome, usually due to missing flags, resource limits, or version mismatches. This guide walks you through the most reliable fixes, from checking your Chrome installation to adjusting Wallaby's configuration. You'll need access to your project's Wallaby config file and, ideally, a terminal to verify Chrome's version.

What You'll Need

  • Your project's Wallaby configuration file (typically wallaby.js or wallaby.conf.js)
  • Access to a terminal or command prompt
  • Chrome or Chromium installed (or the ability to install it)
  • Your project's package.json (to check dependencies)

Step-by-Step

  1. Verify Chrome is installed and accessible. Run google-chrome --version (Linux), chrome --version (Windows), or chromium --version (macOS/Linux). If you get a 'command not found' error, install Chrome or Chromium. Wallaby needs a real browser binary; it doesn't bundle one.
  2. Check your Wallaby version. In your terminal, run npx wallaby --version (or check the version in your package.json). If you're on an older version, update to the latest. Many headless Chrome crashes are fixed in newer releases. Run npm install wallaby-webpack@latest --save-dev (or the equivalent for your setup) to update.
  3. Set the Chrome path explicitly in your Wallaby config. Wallaby sometimes can't find Chrome automatically. In your wallaby.js, add a env block:
  4. module.exports = function (wallaby) {
      return {
        // ... other config
        env: {
          type: 'node',
          runner: 'node',
          params: {
            env: 'CHROME_PATH=/usr/bin/google-chrome' // adjust path for your OS
          }
        }
      };
    };
  5. Add headless Chrome flags. If Chrome launches but crashes during test execution, it's often due to missing flags. Add the following to your Wallaby config under env.params.env:
  6. env: {
      type: 'node',
      runner: 'node',
      params: {
        env: 'CHROME_FLAGS="--no-sandbox --disable-gpu --disable-dev-shm-usage"'
      }
    }
  7. Increase the Node.js memory limit. Headless Chrome can be memory-hungry. If you see 'JavaScript heap out of memory' errors, add NODE_OPTIONS=--max-old-space-size=4096 to the same env string.
  8. Disable the Wallaby file watcher temporarily. Sometimes crashes happen due to file watching conflicts. In your Wallaby config, set files.watch: false (or in the editor settings, disable 'Run tests on save') to see if that stops the crash. If it does, the issue is likely with your editor's file watcher, not Chrome.
  9. Clear Wallaby's cache. Corrupted cache can cause crashes. Close your editor, then delete the .wallaby folder in your project root (or the cache directory specified in your editor's settings). Restart your editor and re-run Wallaby.
  10. Update your editor's Wallaby extension. If you're using VS Code, JetBrains, or another editor, ensure the Wallaby extension is up to date. Outdated extensions can have compatibility issues with headless Chrome.
  11. Try a different Chrome channel. If you're using Chrome Canary or Beta, switch to stable. Conversely, if stable crashes, try Canary (set CHROME_PATH to the Canary binary). This helps isolate version-specific bugs.

Common Mistakes

  • Forgetting to restart the editor after changing config. Wallaby reads your config at startup. Always restart your editor (or at least stop and restart Wallaby) after editing wallaby.js.
  • Using the wrong Chrome path. On macOS, Chrome is usually at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome, not /usr/bin/google-chrome. On Windows, it's often C:\Program Files\Google\Chrome\Application\chrome.exe.
  • Setting flags in the wrong place. The CHROME_FLAGS environment variable must be inside params.env, not as a separate top-level key. Double-check your syntax.
  • Mixing up Wallaby's env with the browser's environment. Wallaby runs your tests in Node.js by default. If your tests need a browser environment, you must set type: 'node' but also ensure you're using a test framework that works with headless Chrome (like Karma or Jest).

Tips

  • Run Wallaby from the terminal first (npx wallaby) to see the full error output. The editor often hides the actual Chrome error message.
  • Use the --no-sandbox flag if you're on Linux or in a CI environment. Many Linux systems require it for Chrome to run as root or in restricted environments.
  • If you're using Docker or a VM, ensure you have enough shared memory (/dev/shm). The --disable-dev-shm-usage flag helps but also increase the container's --shm-size if possible.
  • Keep your Chrome and Wallaby versions in sync. If you update Chrome, update Wallaby too.

Troubleshooting

If the steps above don't fix the crash, try these in order:

  • Check the full error log. In your editor, open the Wallaby output panel. Look for a line that says 'Chrome failed to start' or 'DevTools listening on ws://...'. The error message will tell you exactly what's wrong (e.g., 'Missing X server' or 'Failed to connect to the bus').
  • Run Chrome manually with the same flags. Open a terminal and run google-chrome --headless --no-sandbox --disable-gpu --disable-dev-shm-usage --remote-debugging-port=9222 about:blank. If this crashes, the problem is with Chrome itself, not Wallaby. Try reinstalling Chrome.
  • Try a different browser. Wallaby supports Firefox and Safari. Temporarily set env: { type: 'node', runner: 'node', params: { env: 'WALLABY_BROWSER=firefox' } } (or use the editor's browser selector) to see if the crash is Chrome-specific.
  • Disable all other extensions in your editor. Some editor extensions interfere with Wallaby's debugging or process management. Disable them one by one to find the culprit.
  • Check your project's dependencies. If you're using puppeteer or selenium in your test setup, they may be launching their own Chrome instance, conflicting with Wallaby's. Ensure you're not starting a browser in a beforeAll hook.
  • Reinstall Wallaby and its dependencies. Delete node_modules and reinstall. Sometimes a partial install causes crashes.

Frequently Asked Questions

Why does Wallaby crash only when I run tests in watch mode?

Watch mode keeps Chrome alive between runs. If Chrome crashes after the first run, it's often due to memory leaks or file watcher conflicts. Try increasing Node's memory limit and disabling the file watcher as described above.

Do I need to install Chrome separately?

Yes. Wallaby doesn't bundle a browser. You need Chrome or Chromium installed on your system. If you don't have it, install it via your package manager or download the official installer.

Can I use Chrome for Testing instead of regular Chrome?

Yes. Chrome for Testing is a dedicated version for automated testing. You can download it and set CHROME_PATH to its executable. It's often more stable for headless use.

What does the --no-sandbox flag do? Is it safe?

It disables Chrome's sandbox, which is a security feature. It's commonly needed in CI environments or when running as root. It's safe for local development, but avoid it in production or untrusted environments.

Why does the crash mention 'DevToolsActivePort file doesn't exist'?

This usually means Chrome couldn't start a debugging port. This happens when Chrome crashes immediately. Check your flags and Chrome installation. Adding --remote-debugging-port=9222 to CHROME_FLAGS can sometimes force it to work.

My tests pass in the terminal but crash in Wallaby. What's different?

Wallaby runs tests in a persistent process with file watching. The terminal runs a one-off command. Differences in environment variables or working directory can cause crashes. Try setting the same environment variables you use in the terminal in your Wallaby config.