Skip to main content
Revolutionize your testing approach with our latest products - Test Observability, Test Management & Accessibility Testing.

Change browser window size on Playwright

Learn how to change the browser window size in your Playwright tests on BrowserStack Automate

By default, the Playwright tests run on a default viewport size of 1280x720. But that might not be the screen resolution of the OS where your test in running. While you have the option of selecting the desktop screen resolution of your choice, you can also use the option shown below to maximize the browser window during your Playwright test.

Sample script for maximizing browser window
const { chromium } = require('playwright');

const cp = require('child_process');
const clientPlaywrightVersion = cp.execSync('npx playwright --version').toString().trim().split(' ')[1];

(async () => {
  const caps = {
    'browserstack.username': process.env.BROWSERSTACK_USERNAME || 'YOUR_USERNAME',
    'browserstack.accessKey': process.env.BROWSERSTACK_ACCESS_KEY || 'YOUR_ACCESS_KEY',
    'client.playwrightVersion': clientPlaywrightVersion
  };
  const browser = await chromium.connect({
    wsEndpoint: `wss://cdp.browserstack.com/playwright?caps=${encodeURIComponent(JSON.stringify(caps))}`,
  });
  const context = await browser.newContext({
    viewport: null
  });
  const page = await context.newPage();
  await page.goto('https://www.google.com/ncr');
  await browser.close();
})();

You can also choose any other viewport while creating the newContext. Read more about viewport options while creating contexts in Playwright.

Note: Your Playwright tests run on desktop browsers with a default resolution of 1024x768. You can change desktop screen resolution and set it according to your needs.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Download Copy