Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to maximize the Window size in Playwright? [duplicate]

I'm running my Playwright test scenarios and facing an issue while trying to run scenarios with windows “maximized” / full window.

I set viewport as null for browser context, and it works in maximized view on local, but on remote-cloud-providers like LambdaTest/SauceLabs it works only with reduced size.

I tried with view port it does not work: https://playwright.dev/docs/api/class-browser/#browser-new-context-option-viewport.

like image 322
HomeLander Avatar asked Oct 20 '25 15:10

HomeLander


2 Answers

First Way - Via playwright.config file

  1. Add args: ["--start-maximized"] to the launchOptions
  2. Remove the DeviceDescriptor from your project
  3. Set viewport: null in your project

Example playwright.config.ts file:

// playwright.config.ts file
import { defineConfig, devices } from "@playwright/test";

export default defineConfig({
  use: {
    launchOptions: {
      // 1
      args: ["--start-maximized"],
    },
  },

  projects: [
    {
      name: "chromium",
      use: {
        // 2 (Make sure device is not set)
        // ...devices["Desktop Chrome"],

        // 3
        viewport: null,
      },
    },
  ],
});

Second Way - In the test itself

const browser = await chromium.launch({
    headless: false,
    args: ["--start-maximized"],
});
const context = await browser.newContext({ viewport: null });
const page = await context.newPage();

Again, note that you follow these steps:

  1. Add args: ["--start-maximized"] to the launchOptions
  2. Remove the DeviceDescriptor from your project configuration
  3. Set viewport: null in the BrowserContext
like image 90
I.sh. Avatar answered Oct 22 '25 05:10

I.sh.


Best Practice for Cloud

const browser = await playwright.chromium.launch();

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

This works reliably across all cloud environments.

Reference:

Playwright - Javascript - Maximize Browser

like image 45
Vishal Aggarwal Avatar answered Oct 22 '25 04:10

Vishal Aggarwal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!