User Agents

Web browsers and everyday web tech, explained

Fix Playwright Browser Closed Errors in Microsoft Edge

· 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

Playwright's "browser closed" error with Microsoft Edge usually happens because the browser process exits unexpectedly during a test. This guide shows you how to diagnose and fix the most common causes, from missing dependencies to incorrect launch options, so your Edge tests run reliably.

What You'll Need

  • A Node.js project with Playwright installed (or Python, but examples here use Node.js)
  • Microsoft Edge installed (Chromium-based, version 80 or later)
  • Command-line access (terminal or PowerShell)
  • Basic knowledge of your test scripts

Step-by-Step

  1. Update Playwright and Edge. Run npm install -D @playwright/test@latest in your project. Then update Edge to the latest version via your system's update mechanism. Outdated browsers or libraries often cause random crashes.
  2. Run the exact command that fails, with verbose logging. In your terminal, run your test with DEBUG=pw:browser* npx playwright test (Linux/macOS) or set DEBUG=pw:browser* && npx playwright test (Windows). This shows why the browser is closing—look for lines like "browser process exited" or "crash".
  3. Install system dependencies for Edge. Playwright's bundled Chromium needs certain libraries. Run npx playwright install-deps edge (Linux only; macOS and Windows usually have them). If you're using a custom Edge channel, run npx playwright install-deps to cover all.
  4. Use the correct browser executable path. In your Playwright config, set channel: 'msedge' or 'msedge-beta' etc., instead of relying on the default Chromium. Example:
    use: { channel: 'msedge' }
    This ensures Playwright uses your installed Edge, not a mismatched binary.
  5. Check for resource exhaustion. If your test runs many pages or heavy scripts, the browser may run out of memory. Increase the timeout in your config (timeout: 60000) and reduce parallel workers (workers: 1) to see if that stabilizes it.
  6. Disable hardware acceleration. Some GPU drivers cause Edge to crash. Add launch options:
    use: { launchOptions: { args: ['--disable-gpu'] } }
    If that fixes it, your GPU driver is the culprit—update it or keep the flag.
  7. Clear Edge's user data conflicts. Playwright uses a temporary profile, but if your Edge is running with a real profile, close all Edge windows before tests. Also, in your config, set launchOptions: { args: ['--user-data-dir=/tmp/edge-test-profile'] } to force a clean profile.
  8. Handle graceful shutdown. If your test calls browser.close(), ensure it's in a finally block or use Playwright's test fixtures so the browser is closed properly. Improper closing can cause "browser closed" errors on subsequent tests.
  9. Run tests with a single browser context. If you're creating multiple contexts, reuse one to avoid spawning too many processes. Example: const context = await browser.newContext(); only once per test.
  10. Update your test code to catch the error. Wrap your test in a try-catch to log the full stack trace. This often reveals that the error is actually a timeout or a navigation failure, not a real browser crash.

Common Mistakes

  • Using channel: 'msedge' but not having Edge installed in the default location.
  • Forgetting to run npx playwright install after updating Playwright—this installs the matching browser binaries.
  • Leaving Edge open manually while running tests, which locks the user data directory.
  • Ignoring the actual error message and assuming it's always a crash—sometimes it's a timeout.
  • Setting headless: false but not having a display on Linux servers.

Tips

  • Use Playwright's built-in tracing: npx playwright test --trace on. This records a trace that shows the browser's state before the crash.
  • Set viewport and deviceScaleFactor explicitly to avoid rendering issues that might crash the GPU process.
  • If you're using Docker, ensure you use the official Playwright image and install Edge separately, then set channel: 'msedge'.
  • Run tests sequentially with workers: 1 to isolate the issue—if it passes, it's a concurrency problem.
  • Keep your Playwright and Edge versions in sync; major version mismatches are a common source of instability.

Troubleshooting

If the error persists after following the steps:

  • Check the full error stack. In the terminal output, look for the line that says "browserType.launch" or "page.goto"—that tells you which action triggered the close.
  • Try a different browser. Temporarily switch to Chromium (channel: 'chromium') to see if the issue is Edge-specific. If it works, the problem is with Edge's build or installation.
  • Reinstall Edge. On Windows, go to Settings > Apps > Microsoft Edge > Modify > Repair. On macOS, delete and reinstall Edge from Microsoft's website.
  • Check system logs. On Linux, run dmesg | tail -20 to see if the kernel killed the browser (OOM). On Windows, check Event Viewer under Windows Logs > Application for Edge crash events.
  • Use the Playwright Inspector. Run with --debug to step through your test and see exactly where the browser closes.

Frequently Asked Questions

Why does Playwright say "browser closed" but Edge stays open?

That usually means the browser process Playwright spawned crashed, but your manually opened Edge window is unaffected. Check the debug logs for the exact exit code.

Does this error happen only with Edge, not Chromium?

Yes, sometimes. Edge has its own build and may require different dependencies or flags. If Chromium works, focus on Edge-specific settings like channel and executable path.

Can I use Edge's stable channel in Playwright?

Yes, set channel: 'msedge' in your config. For Edge Beta, use 'msedge-beta', and for Dev, 'msedge-dev'.

How do I fix "browser closed" in headless mode?

Ensure you have all system dependencies installed. On Linux, run npx playwright install-deps. Also, try adding --no-sandbox to launch options if running as root.

What does the error "browserType.launch: Executable doesn't exist" mean?

It means Playwright can't find the Edge executable. Specify the full path using executablePath in your config, or install Edge via Playwright's npx playwright install msedge.

Is there a way to restart the browser automatically on failure?

Yes, you can use Playwright's test retries: set retries: 2 in your config. This will re-run the test in a fresh browser context, which often bypasses transient crashes.