Setting specific chrome flags in puppeteer (enable and disable)

前端 未结 3 1678
栀梦
栀梦 2021-01-12 08:24

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.

The flags I\'m trying to enable

3条回答
  •  心在旅途
    2021-01-12 08:57

    Follow these steps, please.

    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')

    2. Now, add some flags to the array.

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

    3. 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 })

提交回复
热议问题