How to set max viewport in Puppeteer?

前端 未结 8 939
一整个雨季
一整个雨季 2021-02-01 02:04

When I run a new page, I must specify size of the viewport using the setViewport function:

await page.setViewport({
    width: 1920,
    height: 108         


        
8条回答
  •  星月不相逢
    2021-02-01 02:37

    It's probably worth mentioning that if you combine puppeteer.launch({defaultViewport: null}) with puppeteer.connect(), again you need to pass {defaultViewport: null}}, otherwise the viewport is adjusted back to default size. So in this case, use:

    await puppeteer.connect({browserWSEndpoint: ws, defaultViewport: null})
    

提交回复
热议问题