feat: support connecting to ws directly#59
Conversation
This adds support for using any ws CDP based server to connect to, without breaking existing usage of the browser rendering api. Example usage with Browserbase:
```
import { Browserbase } from '@browserbasehq/sdk';
import { chromium } from '@cloudflare/playwright';
const bb = new Browserbase({ apiKey: env.BROWSERBASE_API_KEY });
const session = await bb.sessions.create({
projectId: env.BROWSERBASE_PROJECT_ID,
});
const browser = await chromium.connectOverCDP(session.connectUrl);
const defaultContext = browser.contexts()[0];
const page = defaultContext.pages()[0];
await page.goto('https://google.com');
page.close();
browser.close();
```
|
As incoming CDP messages may be larger than the 1mb Luckily cloudflare/workers-sdk#6424 introduced Edit: nvm this flag can't be deployed to production atm. |
|
Yes, that would only work in dev, that's why we need chunking :( Eventually we could allow disabling chunks as you are proposing, but we would need to make it very clear that messages greater than 1MB would fail. And we still have the latency to take into account, because CDP is a very low level protocol, and for instance opening a new page can trigger 50 CDP calls. |
|
Yeah totally makes sense for it to chunk when communicating with Cloudflare's Browser Rendering API given you guys control the backend and have built support for it. But in order to support connecting to any arbitrary CDP server using Unclear whether it'll never make it to production or just forgotten (since it got introduced for the debugger in dev mode originally) :) I've asked about this in cloudflare/workerd#4649 and also chatted with @threepointone. Would be a nice unlock for Cloudflare :) |
|
With Cloudflare officially increasing WebSocket message size limit to 32MiB (cloudflare/workerd#5362), disabling chunking should no longer cause message failures in prod! Therefore, I'd love for Cloudflare to now consider merging this PR! It would help our use case a lot, and I'm sure many others. |
This adds support for using any ws CDP based server to connect to, without breaking existing usage of the browser rendering api. Example usage with Browserbase: