puppeteer: Ability to exit a script while keeping browser running

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

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 3
  • Comments: 15 (1 by maintainers)

Most upvoted comments

Let me re-classify this a feature but it’d be a very low priority for us.

To keep file image and script files in cache and to connect fastly to a dynamic page (because pupetter and chromium are too slow to launch and open a page: almost 2 seconds). When chromium is still stared, it takes some only 100ms. We can see a huge difference if I need to convert 10 pages to different PDF.