Verified Production Fix
[nodejs/node] Playwright tests failing to launch due to internal assertion error in Node.js
GH-nodejs/node#62106 • Mar 08, 2026
### ROOT CAUSE
The issue is caused by an internal assertion error in Node.js, specifically related to the `firstWindow` property being undefined during the cleanup process in the `test-environment-helpers.ts` file. This suggests that the environment setup or teardown logic is not properly handling the browser context, leading to an undefined state.
### CODE FIX
To resolve this issue, you need to ensure that the browser context is properly initialized and cleaned up. Here is a potential fix for the `test-environment-helpers.ts` file:
typescript
import { chromium } from 'playwright';
let browser: any = null;
export async function setupTestEnv() {
browser = await chromium.launch();
}
export async function tearDownTestEnv() {
if (browser) {
await browser.close();
}
}
In your `playwright.config.ts`, ensure that the `setupTestEnv` and `tearDownTestEnv` functions are called appropriately:
typescript
import { defineConfig } from '@playwright/test';
import { setupTestEnv, tearDownTestEnv } from './tests/test-environment-helpers';
export default defineConfig({
testDir: './tests',
use: {
browserName: 'chromium',
},
globalSetup: async () => {
await setupTestEnv();
},
globalTeardown: async () => {
await tearDownTestEnv();
},
});
Additionally, ensure that your test files are correctly importing and using these setup and teardown functions. For example:
typescript
import { test, expect } from '@playwright/test';
import { setupTestEnv, tearDownTestEnv } from '../test-environment-helpers';
test.beforeAll(async () => {
await setupTestEnv();
});
test.afterAll(async () => {
await tearDownTestEnv();
});
test('Main window state', async ({ page }) => {
// Your test code here
});
By ensuring that the browser context is properly initialized and cleaned up, you should be able to resolve the internal assertion error and allow your Playwright tests to run successfully.
Deploy with Vultr
Use this fix in production instantly. Claim your high-performance developer credit.
Get Started with Vultr →
digital