The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Call and await client.detach() on the CDP session when you are finished with it. This detaches that protocol session from its target; it does not mean “close the page” or “close the browser.”
Detach a session
Assuming page is an existing Puppeteer Page, create a session and detach it when its work is done:
As an Amazon Associate I earn from qualifying purchases.
const client = await page.createCDPSession();
// Use client.send(...) and client.on(...) while the session is needed.
await client.detach();
Puppeteer 25.12.0 documents Page.createCDPSession() as returning a Promise<CDPSession>. The CDPSession.detach() reference defines the method as Promise<void>; awaiting it makes the cleanup step explicit.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
What detaching changes
A CDPSession is a connection for sending Chrome DevTools Protocol commands and listening for protocol events. Use send() to send commands and on() to subscribe to events. Puppeteer’s API documentation states: “Once detached, the cdpSession object won’t emit any events and can’t be used to send messages.” See the send method reference and CDPSession class reference.
#1 Best Overall
Do not reuse the detached object
After detaching, do not rely on that session to send further CDP commands or receive events. If you need CDP access later, create a session again with page.createCDPSession() and use the new session object.
Detaching is not page or browser closure
The method documentation describes detaching the CDPSession from its target. It does not say that detach() closes the Puppeteer Page or browser. Treat protocol-session cleanup separately from any page- or browser-lifecycle action your application needs.
Ensure cleanup when work can fail
If session work may throw and you still want to attempt detachment, put the work in a try block and await detachment in finally:
const client = await page.createCDPSession();
try {
await client.send('Runtime.enable');
// Perform the CDP work that needs this session.
} finally {
await client.detach();
}
This pattern makes cleanup part of the control flow. The API reference does not state that detachment is idempotent, so do not assume repeated calls are guaranteed to be harmless.
Rank #3
Optional state and event observation
The CDPSession API documents a readonly detached boolean property, and Puppeteer documents a sessiondetached event in its CDPSessionEvents interface. They are observation surfaces; the cited references do not specify when the property changes or how the event is ordered relative to the detach promise resolving. Avoid making cleanup logic depend on an undocumented timing assumption.
Version note
The method and page-session creation references cited here are for Puppeteer 25.12.0. The event interface reference is for 25.9.0, while the class reference is labeled Next. If you use another installed release, check the API documentation for that version before relying on version-specific behavior.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If your goal is simply to capture a website rather than use raw CDP, ScreenshotNeo provides a website screenshot API and MCP server. One GET request can return an image or PDF without you managing a Puppeteer browser session. The example below saves a WebP response; consult the ScreenshotNeo API documentation for request options.
curl -G "https://api.screenshotneo.com/v1/shot"
-d access_key=YOUR_API_KEY
--data-urlencode url=https://stripe.com
-o shot.webp
- Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; each cleanup step can be turned off.
- Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; responses indicate the page verdict and billing status in headers.
- An MCP server lets AI agents use screenshot tools, including
take_screenshot,get_page_info, andcapture_pdf. - The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.
Sign up for ScreenshotNeo free and get 1,000 screenshots a month with no card.
Frequently Asked Questions
Does detach() return a value?
The Puppeteer 25.12.0 API signature is Promise<void>.
Can I keep listening for CDP events after detaching?
No. Puppeteer documents that the detached session no longer emits events.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




