Fix Playwright Browser Closed Errors in Microsoft Edge
In this article
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
- Update Playwright and Edge. Run
npm install -D @playwright/test@latestin your project. Then update Edge to the latest version via your system's update mechanism. Outdated browsers or libraries often cause random crashes. - Run the exact command that fails, with verbose logging. In your terminal, run your test with
DEBUG=pw:browser* npx playwright test(Linux/macOS) orset DEBUG=pw:browser* && npx playwright test(Windows). This shows why the browser is closing—look for lines like "browser process exited" or "crash". - 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, runnpx playwright install-depsto cover all. - 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. - 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. - 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. - 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. - Handle graceful shutdown. If your test calls
browser.close(), ensure it's in afinallyblock or use Playwright's test fixtures so the browser is closed properly. Improper closing can cause "browser closed" errors on subsequent tests. - 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. - 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 installafter 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: falsebut 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
viewportanddeviceScaleFactorexplicitly 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: 1to 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 -20to 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
--debugto 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.