如何在Puppeteer中设置最大视口? [英] How to set max viewport in Puppeteer?

查看:154
本文介绍了如何在Puppeteer中设置最大视口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行新页面时,必须使用 setViewport 函数指定视口的大小:

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

await page.setViewport({
    width: 1920,
    height: 1080
})

我要使用最大视口.

如何根据窗口大小调整视口的大小?

How can I make the viewport resizable according to the window size?

推荐答案

我对此可能很晚.不过,对于其他人,请尝试:

I may be very late on this. Nevertheless for others, try:

const browser = await puppeteer.launch({defaultViewport: null});

如上所述,将 defaultViewport 选项设置为 null ,以禁用800x600分辨率.然后需要最大分辨率.

Set the defaultViewport option to null as above to disable the 800x600 resolution. It takes the max resolution then.

这篇关于如何在Puppeteer中设置最大视口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆