#8261·puppeteer

Ability to exit a script while keeping browser running

Author: SuperPat45Created Apr 21, 2022Updated Sep 16, 2026
Labelsgood first issueconfirmedP3feature

My java server need to convert some HTML pages to PDF. Today I call a script who use process.launch(). All work fine except I take seconds to complete, and it is too slow. After investigations, 1.5 to 3 seconds are needed just to launch() chromium and open newPage()...

Bug description

To speed up this, I try to create a new script that use puppeteer to launch a headless chromium instance, save the browserWSEndpoint on the file system and exiting the script leaving the browser opened.

So, other puppeteer scripts can connect to this browserWSEndpoint later to speed up it.

const puppeteer = require("puppeteer");

(async () => {
       const browser = await puppeteer.launch({
		handleSIGINT : false, 
		handleSIGTERM : false, 
		handleSIGHUP : false,
	});

	try {
		const browserWSEndpoint = browser.wsEndpoint();
		console.log("Endpoint: " + browserWSEndpoint);
 
               // Save browserWSEndpoint to the file system
         } finally {
		browser.disconnect();
                process.exit(0);
	}
})();

My main problem is that the script hang without calling browser.close();

So I try with the 3 parameters: handleSIGINT : false, handleSIGTERM : false, handleSIGHUP : false They seem to have no effect, pressing Ctrl+c kill the script and chromium too. I try with adding process.kill(0); at the end of the script function to force exit, but the chromium is killed too.

Are-there another way to let the chromium process alive after script execution?

Puppeteer version

13.4.0

Node.js version

v16.14.2

npm version

8.5.0

What operating system are you seeing the problem on?

Windows

Relevant log output

No response