I’m spawning Playwright on my local machine in one codebase, then connecting to it over websocket in another codebase (also on my local machine). The server is being spawned fine, and as it’s not in headless mode, I can play around with it.
I can see that it has an active context and page, because I can literally navigate the page and interact with it.
However, when trying to connect to the server, the connection works fine but no contexts are found when checked. What am I doing wrong?
Server Code (Typescript):
import { chromium } from 'playwright';
const browserServer = await chromium.launchServer({ headless: false });
const wsEndpoint = browserServer.wsEndpoint();
console.log('wsEndpoint: ', wsEndpoint);
const browser = await chromium.connect({ wsEndpoint });
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://some.example.com');
console.log(browser.contexts()); // This is good, shows the context!
Client Code (Python):
from playwright.async_api import async_playwright
ws_endpoint='################'
playwright = await async_playwright().start()
browser = await playwright.chromium.connect(ws_endpoint=ws_endpoint)
contexts = browser.contexts
// Server is still active, and I can still interact with the page...
// ...but length is 0.
print(len(browser.contexts)
I tried to ensure that the Playwright connection is working from the client, which it is. Everything seems fine. The WS endpoint is correct (if I change it, it crashes), but it cannot find any contexts despite one being active and human-interactable.