Apify Discord Mirror

Updated 5 months ago

How to resize Playwright browser window?

At a glance

The community member is asking how to set the size of the browser window when using the Crawlee/PlaywrightCrawler. The community members in the comments suggest two ways to do this:

1. Pass the viewport option in the launchOptions of the PlaywrightLaunchContext.

2. Use the page.setViewportSize() method in the preNavigationHooks of the PuppeteerCrawlerOptions.

There is no explicitly marked answer, but the community members have provided two potential solutions to the problem.

Useful resources
There is the method page.setViewportSize() (https://playwright.dev/docs/api/class-page#page-set-viewport-size)
to resize Playwright browser window.

With Crawlee/PlaywrightCrawler, How can I set the size of browser window ?

const crawler = new PlaywrightCrawler({ // Stop crawling after 5 pages maxRequestsPerCrawl: 5, // https://crawlee.dev/api/playwright-crawler/interface/PlaywrightLaunchContext launchContext: { // https://crawlee.dev/api/playwright-crawler/interface/PlaywrightLaunchContext#launchOptions launchOptions: { stealth: true, headless: false, }, ????? }, .....
L
1 comment
You can pass any Playwright params to the launchOptions so this should work:

Plain Text
launchOptions: {
   stealth: true,
   headless: false,
   viewport: {
      width,
      height,
   }      
}


But you can also use page.setViewportSize() in preNavigationHooks
https://crawlee.dev/api/puppeteer-crawler/interface/PuppeteerCrawlerOptions#preNavigationHooks
Add a reply
Sign up and join the conversation on Discord