diff options
| author | amankumarsingh77 <amankumarsingh7702@gmal.com> | 2026-05-02 21:59:30 +0530 |
|---|---|---|
| committer | amankumarsingh77 <amankumarsingh7702@gmal.com> | 2026-05-02 21:59:30 +0530 |
| commit | a1df2d3e0998e99176a4bfe3cffb83b9e6a2377e (patch) | |
| tree | f84522e4f08fd6adeaf4954e09fc6e43a59d02f7 /src/client.ts | |
| parent | c9d1605b1e3b8dbe88cd3674a9256aa0465f3e6d (diff) | |
release: v0.3.1 — audit fixes for list_tabs IDs, switch_tab prefix matching, download auto-mkdir, session recovery, docs updates
Bug fixes:
- list_tabs: show full 32-char targetIds (was truncated to 8 chars)
- switch_tab: prefix matching fallback for hex prefixes >= 8 chars
- download: auto-create directory with mkdir -p
- ensureAlive: Runtime.evaluate probe to recover from crashed page targets
Docs:
- dispatch_key: clarify DOM-only event behavior
- navigate: warn about Google anti-bot limitation
- network_log: update deprecated promptSnippet
- SKILL.md: document actual daemon API (evaluateJs, pageInfo, session.call)
- SKILL.md: add troubleshooting for sharp/maxDim and Google navigation
- sharp: add to optionalDependencies for screenshot maxDim auto-resize
Diffstat (limited to 'src/client.ts')
| -rw-r--r-- | src/client.ts | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/client.ts b/src/client.ts index 51dfa9f..1bf7ccc 100644 --- a/src/client.ts +++ b/src/client.ts @@ -108,12 +108,26 @@ export const createBrowserClient = (opts: BrowserClientOptions): BrowserClient = } if (Date.now() - lastHealth < HEALTH_TTL_MS) return ok(undefined); const probe = await transport.request("Target.getTargets", {}, { sessionId: null, timeoutMs: 2_000 }); - if (probe.success) { - lastHealth = Date.now(); - return ok(undefined); + if (!probe.success) { + await stop(); + return start(); } - await stop(); - return start(); + lastHealth = Date.now(); + // Verify the page session is still responsive (handles the case where the + // browser transport is alive but the page target crashed, e.g. localhost died). + const jsProbe = await session.call("Runtime.evaluate", { + expression: "1", returnByValue: true, + }, { timeoutMs: 2_000 }); + if (!jsProbe.success && jsProbe.error.kind === "session_not_found") { + const reattached = await session.attachFirstPage(); + if (reattached.success) { + pageCache = null; + return ok(undefined); + } + await stop(); + return start(); + } + return ok(undefined); }; const evaluateJs = async (expression: string, sessionId?: string): Promise<Result<unknown, CdpError>> => { |
