What is the difference between browser.close and browser.disconnect
Puppeteerbrowser.close() and browser.disconnect() both end your current control flow, but they affect the browser lifecycle differently.
-
browser.close() closes the entire browser process.
-
It closes all pages/tabs and releases browser resources.
-
Use it when your automation run is fully finished.
-
browser.disconnect() only detaches your Puppeteer client.
-
The browser process keeps running with its pages still open.
-
Use it when you want the browser to continue running (for example, shared or remote sessions).
Quick rule:
- Use close() to stop the browser.
- Use disconnect() to stop only your connection.
const browser = await puppeteer.connect({ browserWSEndpoint });
// Keep browser running, just detach this script
await browser.disconnect();
// Fully shut down browser process
// await browser.close();