Why is createCDPSession not working in Puppeteer for my project?

I’m working on a web scraping project using Puppeteer on Windows 10 with Node.js version 14.17. I’m trying to use the createCDPSession method to interact directly with the Chrome DevTools Protocol. However, whenever I attempt to create a session, I encounter an error that says “Session creation failed.”

I expected it to work without issues since I followed examples from the documentation. I’m unsure whether this is related to how I’m initializing the browser, the page lifecycle, or version compatibility. Are there any prerequisites, setup requirements, or common mistakes that could cause createCDPSession to fail?

A common reason for this error is calling createCDPSession() before properly initializing or navigating the page. The method must be called on a valid page target.

Make sure:

The browser is launched successfully.

A page is created.

The page has been properly initialized (preferably navigated).

Example:

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.target().createCDPSession();
})();

The key point is that createCDPSession() should be called on a valid page target. If you attempt to call it too early, session creation may fail.

Also, verify that your Puppeteer version matches the bundled Chromium version. Version mismatches can sometimes cause DevTools Protocol errors.

Another frequent cause is a version compatibility issue between Puppeteer and Chromium. Since createCDPSession() interacts directly with the Chrome DevTools Protocol (CDP), even small mismatches can break session creation.

To avoid this:

Use the Chromium version bundled with Puppeteer.

Avoid manually connecting to a separate Chrome instance unless versions match exactly.

Check your installed Puppeteer version using:

npm list puppeteer

If needed, reinstall Puppeteer to ensure Chromium is properly downloaded:

npm install puppeteer

Version alignment is critical when working with low-level CDP methods.