Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Puppeteer’s page-scoped API: const client = await page.createCDPSession();. It returns a CDPSession attached to that page. Call client.send() for Chrome DevTools Protocol (CDP) commands, subscribe with client.on(), and call client.detach() when the session is no longer needed.

This is the supported replacement for creating a page session through page.target(). The official signature is documented in Puppeteer’s Page.createCDPSession() API reference.

Create a CDP client from a Puppeteer page

Once you have a Puppeteer Page object, create the protocol client with one awaited call:

const client = await page.createCDPSession();

The returned promise resolves to a CDPSession associated with that page. The session is Puppeteer’s low-level bridge to the raw Chrome DevTools Protocol, while the Page API remains the higher-level interface for normal navigation and interaction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

A complete runnable example looks like this:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  await page.goto('https://example.com');

  const client = await page.createCDPSession();
  console.log('CDP session attached:', !client.detached);

  await client.detach();
  await browser.close();
})();

If your project uses ECMAScript modules, replace the import style while keeping the same await page.createCDPSession() call.

Send protocol commands and receive events

Invoke a CDP method with send()

Use client.send(method, parameters) to invoke a protocol method. The method name is the CDP domain and command separated by a dot; parameters are passed as an object when the command requires them. The promise resolves with the protocol response.

Puppeteer’s official example uses the Animation domain:

const client = await page.createCDPSession();

await client.send('Animation.enable');

const response = await client.send('Animation.getPlaybackRate');
console.log('playback rate is ' + response.playbackRate);

await client.send('Animation.setPlaybackRate', {
  playbackRate: response.playbackRate / 2,
});

In this sequence, the domain is enabled first, the current playback rate is read, and then a new rate is sent back. Keep the await on each command when order matters; otherwise a later call can run before an earlier domain setup has completed.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Subscribe to protocol events with on()

Register a listener with the event name documented by CDP:

client.on('Animation.animationCreated', () => {
  console.log('Animation created!');
});

Event callbacks run when Chrome emits that protocol event. Register listeners after creating the session and before the activity that should trigger them. Keep handlers short or hand work to your own queue so event processing does not block the rest of your automation.

Inspect state and detach cleanly

The detached property tells you whether the session has been detached. When finished, explicitly close it:

if (!client.detached) {
  await client.detach();
}

After detachment, the session no longer emits events and cannot send protocol messages. Detach in a finally block when a script can fail between setup and cleanup:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
let client;
try {
  client = await page.createCDPSession();
  await client.send('Animation.enable');
  // Perform the work that needs CDP here.
} finally {
  if (client && !client.detached) {
    await client.detach();
  }
}

Choose the right session scope

Puppeteer exposes two related entry points. Choose based on the object you already have and the target to which the protocol traffic should belong.

Entry point Attachs to Use it when Reference
page.createCDPSession() The current Page Your workflow is page-oriented and you already hold a Page instance. Page API
target.createCDPSession() A Puppeteer Target You are managing targets directly and need the session attached to that target. Target API

For ordinary page automation, the page method makes the intended scope explicit. Do not obtain a target through page.target() merely to create this session: Puppeteer’s Page API marks that approach deprecated and directs callers to Page.createCDPSession() instead. See the Page API documentation for the deprecation note.

A production-friendly page workflow

Keep page operations and CDP operations separate

Use the Page API for navigation and user-facing actions, then use the CDP client only for protocol features that your workflow needs. This separation makes it clear which calls are Puppeteer abstractions and which are raw protocol commands.

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  let client;

  try {
    await page.goto('https://example.com');
    client = await page.createCDPSession();

    client.on('Animation.animationCreated', () => {
      console.log('Animation event received');
    });

    await client.send('Animation.enable');
    const { playbackRate } = await client.send('Animation.getPlaybackRate');
    await client.send('Animation.setPlaybackRate', {
      playbackRate: playbackRate / 2,
    });
  } finally {
    if (client && !client.detached) {
      await client.detach();
    }
    await browser.close();
  }
})();

Handle command failures explicitly

A CDP command can reject if the domain is not enabled, the parameters do not match the protocol method, the page or browser has closed, or the session has already been detached. Wrap calls that affect a larger job so you can log the method and preserve the original error:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
async function sendCdp(client, method, params) {
  try {
    return await client.send(method, params);
  } catch (error) {
    throw new Error(`CDP command ${method} failed: ${error.message}`);
  }
}

Do not continue issuing commands after a detached-session error. Check the session state, create a new session from the live page if appropriate, or abort the page operation and close the browser cleanly.

Install and browser prerequisites

Puppeteer provides a high-level API for controlling Chrome or Firefox over the DevTools Protocol or WebDriver BiDi. The project distinguishes two packages:

  • puppeteer includes an installation process that downloads a compatible Chrome.
  • puppeteer-core is the library without a downloaded browser; you must provide a browser executable or connection through your own deployment.

Package-manager settings that disable install scripts can prevent the automatic browser download. That problem occurs before a CDP session can be created: first make sure a browser launches successfully, then call page.createCDPSession(). The project’s setup information is maintained in the Puppeteer documentation index.

Troubleshoot common failures

Symptom Likely cause Fix
page.createCDPSession is not a function The variable is not a Puppeteer Page, or the call is being made on a different object. Verify that page came from browser.newPage() or another Puppeteer page-producing API. If you intentionally hold a target, use target.createCDPSession().
Browser launch fails before session creation The browser download was skipped, commonly because package-manager install scripts were disabled, or the executable is unavailable. Use the setup documented for your chosen package, permit the required install step, or configure the browser executable explicitly when using puppeteer-core.
A command rejects immediately The protocol domain may not be enabled, parameters may be invalid, or the browser may not support that method in the current context. Enable the required domain first, compare the method and parameter names with the CDP documentation for the browser you run, and log the rejected method.
Events never arrive The listener was registered after the event occurred, the relevant domain was not enabled, or the session was detached. Attach the listener before triggering activity, send the domain’s enable command, and check client.detached.
Cannot send after detach or similar detached-session error client.detach() was called, or the page/browser closed and invalidated the session. Stop using that client. Keep the page alive for the entire operation, or create a fresh session from a still-live page.
Cleanup hangs or is skipped An exception interrupted the normal path. Put detachment and browser shutdown in finally; guard with a client existence and !client.detached check.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance and reliability considerations

  • Enable only what you need. Protocol domains can produce event traffic; registering broad listeners or doing heavy work inside callbacks increases application overhead.
  • Preserve command order. Await setup commands such as Animation.enable before sending commands that depend on that domain.
  • Bound the lifetime. Create the session close to the operation that needs it and detach it when that operation ends. This avoids listeners remaining active after a test or job has finished.
  • Treat the browser as a dependency. A CDP client cannot outlive its page or browser. If either closes, handle the rejection, record enough context to diagnose it, and let the job fail or retry at the browser-automation layer.
  • Keep protocol assumptions visible. CDP method availability and parameters come from the browser protocol. Pin and document the browser setup used by your deployment rather than assuming every Chrome or Firefox build exposes identical commands.

Or skip the browser setup

If your actual goal is obtaining a clean website image rather than controlling a browser protocol session, ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns PNG, JPEG, WebP, or a PDF. Before capture it accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Only clean shots are billed. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and each response reports the result through X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

See the complete parameter list and authentication details in the ScreenshotNeo documentation. A direct cURL call is:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://pptr.dev -o shot.webp

The same request in Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://pptr.dev"}, timeout=90)
open("shot.webp", "wb").write(r.content)

And in Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://pptr.dev' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots; yearly billing gives two months free, and every feature is included on every plan. Sign up for the free ScreenshotNeo plan.

Key decision

For a Puppeteer page, the correct CDP entry point is await page.createCDPSession(). Use the resulting client’s send() and on() methods for protocol work, and detach it when finished. Use the target method only when your code is intentionally target-scoped, and avoid the deprecated page.target() route.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Where is the authoritative signature for a page-attached session?

See the official Page.createCDPSession() reference, which documents the returned promise and session type.

Which reference covers session events and detachment behavior?

Puppeteer’s CDPSession API reference documents send(), on(), detach(), and the detached property.

Where is the target-scoped alternative documented?

Use the separate Target.createCDPSession() reference when your code owns a Puppeteer Target rather than a page.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.