Performance
Reduce unnecessary browser and page work.
With an initialized client and Playwright's chromium import:
await client.withSession({ timeoutSeconds: 300 }, async (session) => {
const grant = await client.sessions.connections.create(session.id, { type: "cdp" });
const browser = await chromium.connectOverCDP(grant.url);
try {
const context = browser.contexts()[0];
const page = context.pages()[0] ?? await context.newPage();
await page.goto("https://example.com", { waitUntil: "domcontentloaded" });
await page.getByRole("heading", { name: "Example Domain" }).waitFor();
} finally {
await browser.close();
}
});| Prefer | Why |
|---|---|
| Wait for the specific content you need | Avoid arbitrary sleeps and unbounded network-idle waits |
| Reuse the existing context | Preserve session configuration and cookies |
| Keep related steps in one browser | Avoid repeated startup and sign-in |
| Retrieve only required outputs | Reduce screenshots and transfer overhead |
| Pick an enabled region | Test caller-to-browser and browser-to-site latency |
Prepared browsers can reduce startup time, but bursts and custom viewports may require a cold start. Measure creation-to-CDP separately from page actions. No fixed latency or throughput guarantee is published.