oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.5k stars 2.71k forks source link

Playwright connectOverCDP() not working #9911

Open jasonwillschiu opened 6 months ago

jasonwillschiu commented 6 months ago

What version of Bun is running?

1.1.0+5903a6141

What platform is your computer?

Darwin 23.4.0 arm64 arm

What steps can reproduce the bug?

I'm trying to use Playwright's connectOverCDP to access an existing Chrome browser in debug mode. This is for a web scraping project. I've returned to Nodejs and everything works fine, but keen to try bun more.

My setup

I run chrome using: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --no-first-run --no-default-browser-check --user-data-dir=chrome-user-data-dir --profile-directory=Default

Code:

import { chromium } from 'playwright';
const browser = await chromium.connectOverCDP('http://localhost:9222');
const defaultContext = browser.contexts()[0];
const page = await defaultContext.newPage();
page.goto('https://google.com')
await page.waitForTimeout(5000);
await browser.close();

Bun Error message:

ConnectionRefused: overCDP: Unable to connect. Is the computer able to access the url?
Call log:
  - <ws preparing> retrieving websocket url from http://localhost:9222

In Nodejs it connects and works as expected.

Thanks for all your great work! Jason

What is the expected behavior?

A new Chrome tab is opened to google.com and then closed after 5 seconds.

What do you see instead?

Bun Error message:

ConnectionRefused: overCDP: Unable to connect. Is the computer able to access the url?
Call log:
  - <ws preparing> retrieving websocket url from http://localhost:9222

Additional information

No response

rossanmol commented 5 months ago

Experiencing same issue :/

sohaieb commented 5 months ago

I faced the same issue here as well

blackfan23 commented 5 months ago

I have set up a repo here: https://github.com/blackfan23/bun-test-playwright

It uses nx and has 3 test cases (see readme)

1) node + playwright (connects fine) 2) bun + puppeteer (connects fine) 3) bun + playwright (does not work)

Edit 2024-07-28: I have updated to the latest Bun and deps. Now the bun-playwright connect throws an error:

`error: overCDP: WebSocket error: ws://localhost:9555/devtools/browser/8b68f908-be47-4a64-99d1-81c37df5fccb 200 OK Call log:

nemya9066 commented 2 months ago

Same issue with the latest version bun throw an error message but the problem still persist...

ohroy commented 1 month ago

any news ?

NicolaiSchmid commented 1 month ago

Does anyone know where exactly the issue lies?