genetic-orange
genetic-orange15mo ago

Change viewport from within PlaywrightCrawler router method?

I have a custom Actor that takes screenshots of webpages if the webpage meets certain criteria. I currently set viewport as a pre-navigation hook, like this:
preNavigationHooks: [
async ({ page }) => {
// await page.setViewportSize({ width, height: 1080 });
await blocker.enableBlockingInPage(page);
await page.setViewportSize(iPhone14ProMax.viewport);
},
],
preNavigationHooks: [
async ({ page }) => {
// await page.setViewportSize({ width, height: 1080 });
await blocker.enableBlockingInPage(page);
await page.setViewportSize(iPhone14ProMax.viewport);
},
],
But when I find a page that passes my criteria, I would like to take a screenshot of the page using this viewport size AND a desktop viewport size. How can I change the viewport from within the playwrightRouter function?
1 Reply
Pepa J
Pepa J15mo ago
Hi @kennysmithnanic in routerHandler method you have acces to the Playwright page object, then check for https://playwright.dev/docs/api/class-page#page-set-viewport-size there is and brief exaplanation on how to use it and what issues may occur.
Page | Playwright
* extends: [EventEmitter]

Did you find this page helpful?