在操纵up中设置特定的Chrome标志(启用和禁用) [英] Setting specific chrome flags in puppeteer (enable and disable)

查看:349
本文介绍了在操纵up中设置特定的Chrome标志(启用和禁用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将chrome的特定标志(在"chrome://flags/"中找到的标志)添加到测试中浏览器的运行中.

I'm trying to add specific flags of chrome (flags that are found in "chrome://flags/") to the running of my browser in the tests.

我要启用的标志是:

  • #enable-webgl-draft-extensions"
  • #shared-array-buffer"

并禁用:

  • #enable-asm-webassembly"

在常规的chrome命令行中,它看起来像这样:

In the regular chrome command line it looks like this:

"--flag-switches-begin --enable-webgl-draft-extensions --enable-features=SharedArrayBuffer --disable-features=AsmJsToWebAssembly --flag-switches-end"

如果我在

puppeteer.launch({args});

我在"--flag-switches-begin"行之前收到它们(我正在观看chrome在其中运行的命令:"chrome://version").

I receive them before the "--flag-switches-begin" line (I'm watching the command that chrome was ran with in: "chrome://version").

非常感谢!

推荐答案

请按照以下步骤操作.

  1. puppeteer.defaultArgs()将为您提供所有默认标志.您可以使用此方法获取它们,然后过滤数组以删除所需的标志. https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerdefaultargs

  1. puppeteer.defaultArgs() will provide you all default flags. You this method to get them, then filter the array to remove flags that you want to. https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerdefaultargs

const args = puppeteer.defaultArgs().filter(arg => arg !== '--enable-asm-webassembly')

现在,向数组添加一些标志.

Now, add some flags to the array.

args.push('--enable-webgl-draft-extensions', '--shared-array-buffer')

启用ignoreDefaultArgs标志.另外,提供我们在上面所做的论点列表.

Enable ignoreDefaultArgs flag when launch a new instance of browser. Also, provide the list of arguments we made above.

const browser = await puppeteer.launch({ ignoreDefaultArgs: true, args })

这篇关于在操纵up中设置特定的Chrome标志(启用和禁用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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