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.
args: ["--start-maximized"]
to the launchOptions
viewport: null
in your projectExample 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,
},
},
],
});
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:
args: ["--start-maximized"]
to the launchOptions
viewport: null
in the BrowserContext
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With