Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Playwright opens a small window instead of a full-size one

ErrorPlaywright window won't launch full screen

Short answer

Playwright gives every page a fixed 1280x720 viewport, so the page never fills the window. Set viewport to null to make it follow the window, or set an exact size with setViewportSize. If you see no window at all, headless mode is on: it defaults to true.

  • Applies to Playwright (current 1.x release), Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the viewport Playwright applies to the page. A value of 1280 by 720 means the default fixed viewport is in use.

    console.log(page.viewportSize());
  2. 2Match what you see, then jump to its fix

    1. 1page.viewportSize() returns { width: 1280, height: 720 }The default fixed viewport of 1280x720 is in useFix
    2. 2playwright.config has devices['Desktop Chrome'] in a project, and your own viewport has no effectA device preset in the config sets its own viewportFix
    3. 3The test passes or fails with nothing on screenThe browser runs headless, so no window is visibleFix

What does the error look like?

  • Playwright window won't launch full screen
  • page.viewportSize() is 1280x720 on a larger monitor

Cause 1 of 3

The default fixed viewport of 1280x720 is in use

1Check

Playwright emulates a consistent viewport for each page, and the documented default is 1280x720. A bigger window does not change it.

console.log(page.viewportSize());

2Fix

Set an exact size you want, or pass viewport: null so the page depends on the window size.

// exact size
const context = await browser.newContext({ viewport: { width: 1920, height: 1080 } });

// follow the window (not deterministic)
const context2 = await browser.newContext({ viewport: null });

3Verify

Read the size again from the page.

console.log(page.viewportSize());
console.log(await page.evaluate(() => [innerWidth, innerHeight]));

Confirmed by playwright.dev

Did this fix it?

Cause 2 of 3

A device preset in the config sets its own viewport

1Check

A device descriptor includes a viewport, and the docs say you can override it for some tests with page.setViewportSize.

grep -n "devices\[" playwright.config.*

2Fix

Override the viewport in the project's use block, or resize inside the test.

// playwright.config.ts
projects: [{
  name: 'chromium',
  use: { ...devices['Desktop Chrome'], viewport: { width: 1920, height: 1080 } },
}]

// inside a test
await page.setViewportSize({ width: 1600, height: 1200 });

3Verify

Run the test and print the viewport.

npx playwright test --headed

Confirmed by playwright.dev

Did this fix it?

Cause 3 of 3

The browser runs headless, so no window is visible

1Check

headless defaults to true in both browserType.launch and the test runner options.

grep -n "headless" playwright.config.* *.js

2Fix

Turn headless off for the run, or pass --headed on the command line.

// library
const browser = await chromium.launch({ headless: false });

// test runner
// use: { headless: false }

3Verify

A browser window now opens during the run.

npx playwright test --headed

Confirmed by playwright.dev

Did this fix it?

How do I stop it coming back?

  • Pick one viewport per project in the config, so a test run looks the same on every machine.
  • Use viewport: null only for local demos; Playwright documents it as making runs non-deterministic.
  • Resize with page.setViewportSize inside the test when a case needs another size.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.