Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

How to Send CDP Commands with Puppeteer

Create a page CDP session with Puppeteer, send protocol commands with send(), handle events, and cleanly detach.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To send a Chrome DevTools Protocol (CDP) command with Puppeteer, create a session for the target page with await page.createCDPSession(), then call await client.send('Domain.command', params). The command returns a promise for its result. Detach the session when you are done sending commands and receiving events.

Send a CDP command

This complete example assumes you already have a Puppeteer page object:

As an Amazon Associate I earn from qualifying purchases.

const client = await page.createCDPSession();

try {
  const result = await client.send('Runtime.evaluate', {
    expression: '1 + 1',
  });
  console.log(result);
} finally {
  await client.detach();
}

Page.createCDPSession() returns a Promise<CDPSession> attached to that page. CDPSession.send() takes the protocol method name and its parameters, and resolves with the method’s mapped result. The example illustrates the call shape; choose a command and parameter names supported by the Chrome version you run.

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

For current Puppeteer API details, see Page.createCDPSession() and CDPSession.send(). Those references displayed Puppeteer 25.12.0 when checked on October 3, 2026; check the documentation for the version installed in your project because API signatures and protocol support can change.

Get a page and run the command

In a browser automation script, the session must be attached to the page that should receive the command. This runnable example launches a browser, opens a page, evaluates a simple expression through CDP, then cleans up both session and browser:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  try {
    const page = await browser.newPage();
    await page.goto('https://example.com');

    const client = await page.createCDPSession();
    try {
      const result = await client.send('Runtime.evaluate', {
        expression: '1 + 1',
      });
      console.log(result);
    } finally {
      await client.detach();
    }
  } finally {
    await browser.close();
  }
})();

Use your existing launch or connection setup if the browser is managed elsewhere; the CDP workflow begins once you have the intended page.

Choose the command and parameters

CDP methods are named as Domain.command, such as Runtime.evaluate. Pass the command’s parameters as the second argument, using the exact field names and value types in the protocol definition for the browser you are automating. The returned value depends on that command: retain it when you need the result, or await the call when completion is all that matters.

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

Commands and parameter schemas are browser-protocol details, not interchangeable guesses. A command may also require its protocol domain to be enabled before use; follow the requirements for that command and browser version.

Listen for protocol events

Use client.on() to handle events emitted by a protocol domain. Enable that domain first when its protocol definition requires it. Puppeteer’s documented example creates a session, enables the Animation domain, listens for an animation event, reads the playback rate, and sets it:

const client = await page.createCDPSession();

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

const { playbackRate } = await client.send('Animation.getPlaybackRate');
await client.send('Animation.setPlaybackRate', { playbackRate });

See the Puppeteer CDPSession class reference for its session and event examples. That page is the Next documentation, so confirm details against the Puppeteer release you use.

Detach when finished

Call await client.detach() when the session is no longer needed. Once detached, it cannot send commands and no longer emits events. A try/finally block, as in the examples above, ensures detachment even if a command fails.

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.

Avoid the obsolete page-target pattern

Older examples may create a session with page.target().createCDPSession(). Puppeteer marks Page.target() obsolete and directs users to call Page.createCDPSession() directly. The legacy method is documented in the Page.target() reference (version 25.11.0 when checked October 3, 2026); use the direct page method in new code.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting

  • The session cannot be created or commands fail: confirm that page is the intended, active Puppeteer page and that the browser connection is still open.
  • The command rejects or returns an error: verify the method spelling, parameter names and types against the protocol supported by the browser you run. Check whether the command’s domain must be enabled first.
  • No event handler runs: subscribe with client.on('Domain.eventName', handler), confirm the event name, and enable the relevant domain when required. A detached session cannot receive events.
  • Later commands fail after cleanup: detachment ends the session. Create a new session from the page if you need to resume CDP communication.

Or skip the browser setup

If your goal is a website screenshot rather than custom CDP control, ScreenshotNeo takes a screenshot or PDF from a single GET request. For example, save a WebP capture with cURL:

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

See the ScreenshotNeo documentation for request options. It accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and response headers report the page verdict and billing status. ScreenshotNeo also provides an MCP server with screenshot, page-info and PDF-capture tools for AI agents. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

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

Frequently Asked Questions

What does CDP stand for?

CDP is the Chrome DevTools Protocol, the browser protocol that Puppeteer’s CDPSession can communicate with.

Can I reuse a detached CDPSession?

No. After detachment, that session cannot send commands or receive events; create another session from the 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.