First Way - Via playwright.config file
- Add
args: ["--start-maximized"]
to the launchOptions
- Remove the DeviceDescriptor from your project
- 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:
- Add
args: ["--start-maximized"]
to the launchOptions
- Remove the DeviceDescriptor from your project configuration
- Set
viewport: null
in the BrowserContext