Issue 1:
System info

Playwright Version: 1.36.0

Operating System: macOS 13.0

Browser: Chromium

Other info: Running on Google Chrome

Source code

I provided exact source code that allows reproducing the issue locally.

Script

import {chromium } from 'playwright'

(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');
});
})();

from playwright.sync_api import sync_playwright
from playwright._impl._browser import Browser, prepare_browser_context_params

print('starting')

def run(playwright):
print('connecting')
chromium = playwright.chromium
browser = chromium.connect_over_cdp('ws://127.0.0.1:9222/devtools/browser/7f40aaee-1efb-4dc1-9e80-c6e3063c7e29')
print('connected')

context = browser.new_context()
page = context.new_page()
page.goto('https://harvard.edu')

with sync_playwright() as playwright:
run(playwright)

Steps

open -a "Google Chrome" --args --profile-directory=Default --remote-debugging-port=9222

Leave the chrome open for 12hrs+`

visit localhost:9222 and get CDP Url

Run python or js script

Expected

Playwright scripts connect to available CDP port and executes.

Actual

Playwright scripts cannot connect and timeout. Browser able to display remote debugging port info and receive CDP commands:

{
"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"
}

this works without any issues, but playwright scripts don't work.

import WebSocket from 'ws';
const client = new WebSocket(
'ws://127.0.0.1:9222/devtools/browser/7f40aaee-1efb-4dc1-9e80-c6e3063c7e29'
);
client.on('open', function open() {
client.send(
JSON.stringify({
id: 1, // Unique identifier for the request
method: 'Target.createTarget',
params: {
url: 'https://yale.edu' // URL of the new target
}
})
);
});
client.on('message', function incoming(data) {
console.log(data);
});

the playwright python script throws this error

(tmp-cdp) ➜ playwright-connect python playwright-test.py
starting
connecting
Traceback (most recent call last):
File "/Users/harshg/code/playwright-connect/playwright-test.py", line 15, in <module>
run(playwright)
File "/Users/harshg/code/playwright-connect/playwright-test.py", line 8, in run
browser = chromium.connect_over_cdp('ws://localhost:9222/devtools/browser/7f40aaee-1efb-4dc1-9e80-c6e3063c7e29')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/harshg/miniconda3/envs/tmp-cdp/lib/python3.11/site-packages/playwright/sync_api/_generated.py", line 15094, in connect_over_cdp
self._sync(
File "/Users/harshg/miniconda3/envs/tmp-cdp/lib/python3.11/site-packages/playwright/_impl/_sync_base.py", line 109, in _sync
return task.result()
^^^^^^^^^^^^^
File "/Users/harshg/miniconda3/envs/tmp-cdp/lib/python3.11/site-packages/playwright/_impl/_browser_type.py", line 172, in connect_over_cdp
response = await self._channel.send_return_as_dict("connectOverCDP", params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/harshg/miniconda3/envs/tmp-cdp/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 66, in send_return_as_dict
return await self._connection.wrap_api_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/harshg/miniconda3/envs/tmp-cdp/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 482, in wrap_api_call
return await cb()
^^^^^^^^^^
File "/Users/harshg/miniconda3/envs/tmp-cdp/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 97, in inner_send
result = next(iter(done)).result()
^^^^^^^^^^^^^^^^^^^^^^^^^
playwright._impl._api_types.TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================
<ws connecting> ws://localhost:9222/devtools/browser/7f40aaee-1efb-4dc1-9e80-c6e3063c7e29
<ws connected> ws://localhost:9222/devtools/browser/7f40aaee-1efb-4dc1-9e80-c6e3063c7e29
============================================================

Other info:

import puppeteer from 'puppeteer-core';

(async () => {
const browser = await puppeteer.connect({
browserWSEndpoint: 'ws://127.0.0.1:9222/devtools/browser/7f40aaee-1efb-4dc1-9e80-c6e3063c7e29'
});
const newPage = await browser.newPage();
await newPage.goto('https://harvard.edu');
})();

This puppeteer script is able to connect sporadically. Tried running 20 times, connected 4 times.

Issue 2:
System info

Playwright Version: [v1.34.0]

Operating System: [All]

Browser: [All]

Source code

public async waitWidgetsLoaded(seconds: number) {
const loadingDots = await this.widgetRefreshOverlay.all();
for (const dot of loadingDots) {
await dot.waitFor({ state: 'hidden', timeout: seconds * 1000 });
}
for (const dot of loadingDots) {
await expect(async () => {
const isDotContainsAttribute = (await dot.getAttribute('class'))!.includes('widget-loading');
expect(isDotContainsAttribute).toBeFalsy();
}).toPass({ timeout: seconds * 1000, intervals: [0.1 * 1000] });
}
}

Steps

[Run the test] that contains step with polling

Note: polling triggers several times in period of time (condition is passed and it's passed not on 1st polling call)

Expected

Step with polling is marked as passed (Green checkmark) in the html report

Actual

Step with polling is marked as failed (Red checkmark) in the html report