puppeteer: [Bug]: Failed to launch the browser process when headless set to "new"

Minimal, reproducible example

const puppeteer = require("puppeteer");
const paths = process.cwd() + "/extension";
(async () => {
  const browser = await puppeteer.launch({
    headless: "new",
    args: ["--no-sandbox", 
    "--disable-setuid-sandbox",
    `--disable-extensions-except=${paths}`,
    `--load-extension=${paths}`],
    userDataDir: "./tmp",
  });
  const page = await browser.newPage();
  await page.goto("https://www.google.com/");

})();

Error string

Failed to launch the browser process! undefined

Bug behavior

  • Flaky
  • PDF

Background

i’ve been trying to run puppeteer with headless “new” because headless true will be deprecated soon

Expectation

it will run properly

Reality

it’s not , it crash and show the error like this

Error: Failed to launch the browser process! undefined
[27051:27051:0707/132159.274812:ERROR:process_singleton_posix.cc(334)] Failed to create /home/fdciabdul/PROJECT/fbchat/tmp/SingletonLock: File exists (17)


TROUBLESHOOTING: https://pptr.dev/troubleshooting

    at ChildProcess.onClose (/home/fdciabdul/PROJECT/fbchat/node_modules/@puppeteer/browsers/lib/cjs/launch.js:259:24)
    at ChildProcess.emit (node:events:525:35)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12)

Node.js v18.14.2

but when i set headless to false it’s work

Puppeteer configuration

No response

Puppeteer version

20.7.4

Node version

18.14.2

Package manager

npm

Package manager version

9.5.0

Operating system

Linux

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 8
  • Comments: 40 (5 by maintainers)

Most upvoted comments

Another way to avoid this is ensuring user data is unique:

const PUPPETEER_DIR = path.join(TMP_FOLDER, `puppeteer-${randomUUID()}`)
const DATA_DIR = path.join(PUPPETEER_DIR, 'profile')

Passing the flag:

`--user-data-dir=${DATA_DIR}`

So even the browser is not gracefully browser, a new browser spawn will have associated a different folder.

On the other hand, even using browser.close the directory is not cleaned, so that is clearly buggy.

making unique userdatadir is not what i want , because in here i wanna save the session

This is being fixed in https://bugs.chromium.org/p/chromium/issues/detail?id=1463328 The fix is on the Chromium side and it is expected to roll out in M119.

tested with puppeteer@21.4.0 and still happening

upgrade your puppeteer version to latest , i never face this issue again

and dont forget using chrome / chromium newer version

The latest version of Puppeteer at the time of writing this comment is 21.4.1 which comes with Chrome Chrome/118.0.5993.70 so the problem is still present.

I still have the same issue with v21.5.1 and v21.5.0

        this.browser = await puppeteer.launch({
            headless: 'new',
            userDataDir: `./userdata`,
            pipe: true
        });

using different folders for userDataDir suggested here fixes the issue

I upgraded version to 21.5.0 , tested it now, I confirm that the issue is fixed.

I see the solution in this case now. It is check before launch in user datadir SingletonLock and if it exists delete this

that’s not solution

When can we expect puppeteer to download / install M119? I’m not sure how puppeteer decides on its latest version. Is it when the version is considered stable by google i.e When the stable date is hit on this https://chromiumdash.appspot.com/schedule ?

Looks like this happens if the browser is not closed via browser.close and instead killed via the process termination.