Description
Hi there,
apologies if this has been asked before but I didn't find anything.
Up until v1.3.0
it was possible to .connect
to a vanilla browser websocket URL (either created through launching Chrome with --remote-debugging
) or using Puppeteer).
v1.4.0
introduced the new "New Client / Server Wire protocol", since then it's not possible to use .connect
with other original CDP websocket servers anymore (it will hang here). I also noticed through logging that the new wire protocol looks much different from the regular CDP chatter.
My question would be if there's still a way to use chromium.connect
with the traditional CDP websocket URLs or if there are pointers on how to best write a translation layer to accomplish that.
My use-case is to have a single websocket url which exposes a fleet of chromium browsers by proxying the websocket connections (similar to browserless.io) and both puppeteer & playwright being able to connect
to it and control the browsers.
The following worked prior to v1.4.0
:
const puppeteer = require("puppeteer")
puppeteer
.launch({
headless: true,
defaultViewport: null,
args: [
"--remote-debugging-port=9222",
"--remote-debugging-address=0.0.0.0",
],
})
.then(async (browser) => {
console.log(browser._connection.url())
})
// => ws://0.0.0.0:9222/devtools/browser/490a2b32-ce62-4b6b-a530-d4931fdeb046
const pw = require("playwright")
;(async () => {
const browser = await pw.chromium.connect({
wsEndpoint: "ws://0.0.0.0:9222/devtools/browser/490a2b32-ce62-4b6b-a530-d4931fdeb046",
})
const context = await browser.newContext()
const page = await context.newPage()
await page.goto("https://www.example.com/")
await page.screenshot({ path: "example.png" })
await browser.close()
})()