Rayrun
← Back to Discord Forum

Playwright CDP Connection Issue

Hi playwright team!

We are trying to run puppeteer on local Google Chrome instance. We are facing an issue while trying to use connectOverCDP method. If the Chrome Instances are newly created, playwright is able to connect, but if the browser has been open for a while, it's having issues connecting. Some observations -

  1. The browser is able to display the ws link properly on localhost:9222/json/version
"Browser": "Chrome/114.0.5735.198",
   "Protocol-Version": "1.3",
   "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
   "V8-Version": "11.4.183.25",
   "WebKit-Version": "537.36 (@c3029382d11c5f499e4fc317353a43d411a5ce1c)",
   "webSocketDebuggerUrl": "ws://127.0.0.1:9222/devtools/browser/7f40aaee-1efb-4dc1-9e80-c6e3063c7e29"
}```

2. We are able to manually send CDP commands reliably using simple node websocket connection over CDP / postman. 

3. Puppeteer.connect method is showing sporadic behavior (sometimes able to connect, sometimes cannot).

4.  This playwright scripts, times out on `const browser = await chromium.connectOverCDP('http://localhost:9222');` this line.

import {chromium } from 'playwright'

console.log('666starting');

(async () => { console.log('connecting'); const browser = await chromium.connectOverCDP('http://localhost:9222'); console.log('connected'); const context = await browser.newContext(); const page = await context.newPage(); await page.goto('https://news.ycombinator.com');

browser.on('disconnected', () => {
    console.log('disconnected');
});

})();

5. We tried running this with playwright python. Had similar issues. (Error trace attached as google doc link)

This is surprising because the browser is able to receive CDP commands directly, but having connection issues with puppeteer (sporadic) and playwright (never connects). Any input would be really helpful!!

This thread is trying to answer question "Why is Playwright unable to connect to a local Google Chrome instance using the `connectOverCDP` method if the browser has been open for a while?"

2 replies

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].