10

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 are:

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

and to disable:

  • "#enable-asm-webassembly"

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"

If i add these criteria in

puppeteer.launch({args});

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

Thank you very much!

Nathan Edwards
  • 311
  • 1
  • 3
  • 17
zeev_r
  • 151
  • 1
  • 2
  • 7

4 Answers4

8

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

Nam Mai Anh
  • 629
  • 8
  • 9
6
await puppeteer.launch({
      args: [
        '--disable-features=LookalikeUrlNavigationSuggestionsUI'
      ]
})

Try something like this.

You can launch Chromium, switch your flag and then go "chrome://version/", to see what has changed in the command line.

In my case, when i switch "Navigation suggestions for lookalike URLs" to disabled,relaunch Chrommium, then i found --disable-features=LookalikeUrlNavigationSuggestionsUI in the command line。

hlg
  • 1,321
  • 13
  • 29
SONGJP
  • 334
  • 3
  • 8
  • 2
    "You can launch Chromium, switch your flag and then go "chrome://version/", to see what has changed in the command line." BRILLIANT! Thank you. It looks like some of the possible command line directives for controlling flags are not documented. But using this method you can figure out what they are. (Note: you have to relaunch the browser after changing the flag to update the chrome://version page). – Matthew Sep 09 '20 at 21:08
1

Previous answer already points in the right direction, but it can be made simpler. The key point is that you need to split your arguments into an array. The code can simply be:

const browser = await puppeteer.launch({args:["--flag-switches-begin", "--enable-webgl-draft-extensions", "--enable-features=SharedArrayBuffer", "--disable-features=AsmJsToWebAssembly", "--flag-switches-end"]});
Henry Luo
  • 354
  • 4
  • 10
0

The correct args are:

await puppeteer.launch({headless: headless, devtools: true, args: ['--disable-web-security', '--disable-features=IsolateOrigins', ' --disable-site-isolation-trials']});

But puppeteer kept crashing.

The reason was that I used an old puppeteer version, puppeteer 1.8.0. After upgrading to puppeteer@8.0.0, it works.

You can check that isolation is disabled in: chrome://process-internals

Suggested in https://stackoverflow.com/a/51320323/337587

More information on the flag: https://www.chromium.org/Home/chromium-security/site-isolation

james
  • 760
  • 1
  • 9
  • 21