The live viewer lets you inspect a running browser and manually interact with it during development or debugging.
Open the Viewer
Create a viewer URL from the session cdpUrl:
https://viewer.driver.dev?ws=<cdp-url>
const session = await client.browser.session.create({ type: "hosted" });
const viewerUrl = `https://viewer.driver.dev?ws=${session.cdpUrl}`;
console.log(viewerUrl);
Keep the Driver session active while the viewer is connected. Stop the session when you are finished debugging.
Viewer Parameters
| Parameter | Description |
|---|
ws | CDP WebSocket URL from the session response. |
theme | Optional viewer theme: light or dark. |
Poll Session Status
Use the session status to wait for a browser to become available or to detect that it has ended.
async function waitForActiveSession(sessionId: string, timeoutMs = 30000) {
const startedAt = Date.now();
while (Date.now() - startedAt < timeoutMs) {
const session = await client.browser.session.get({ sessionId });
if (session.status === "active" && session.cdpUrl) return session;
if (session.status === "completed" || session.status === "error") {
throw new Error(`Session ended with status: ${session.status}`);
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
throw new Error("Timed out waiting for session");
}
Status Values
| Status | Meaning |
|---|
starting | Session is being created. |
active | Session is running and can accept CDP connections. |
completed | Session has stopped successfully. |
error | Session failed or ended with an error. |