typescript 在非无头(非视口)运行时设置 ppeteer 窗口大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48681145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:12:40  来源:igfitidea点击:

Set pupeteer window size when running not headless (not viewport)

javascriptgoogle-chrometypescripttestingpuppeteer

提问by Bernhard

Is it somehow possible to set the browsers (Chrome[ium]) window size like the viewport size?

是否可以像视口大小一样设置浏览器(Chrome [ium])窗口大小?

Setting only the viewport results in a unhandy appearance when the browser is not running headfully and I want to visually see what's going on within the browser instance.

当浏览器没有快速运行并且我想直观地查看浏览器实例中发生的事情时,仅设置视口会导致外观不方便。

So I would like something like below:

所以我想要如下内容:

const browser = await puppeteer.launch({
      headless: false, // The browser is visible
      ignoreHTTPSErrors: true
}),
page = await browser.newPage();


// This is well explained in the API
await page.setViewport({
    width: options.width,
    height: options.height
});

// But is there something like this (careful this is dummy code)
browser.setWindowSize({
    width: options.width,
    height: options.height
});

Thanks for any help pointing me into the right direction

感谢您为我指明正确方向的任何帮助

回答by Everettss

You can set chrome window size during puppeteer.launchwith flag --window-size

您可以在puppeteer.launch带标志期间设置镀铬窗口大小--window-size

Here is usage in your example:

这是您的示例中的用法:

const browser = await puppeteer.launch({
    headless: false, // The browser is visible
    ignoreHTTPSErrors: true,
    args: [`--window-size=${options.width},${options.height}`] // new option
});