fix: document silent catch handlers in browser-tools (#1037)

Add descriptive comments to all empty catch blocks explaining why the
error is intentionally swallowed. Covers networkidle timeouts, optional
screenshots, best-effort file writes, response body reads, route
cleanup, and page metadata refreshes.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
TÂCHES 2026-03-17 18:33:00 -06:00 committed by GitHub
parent 236e576d1e
commit 9201c0ce16
6 changed files with 8 additions and 8 deletions

View file

@ -103,10 +103,10 @@ export function attachPageListeners(p: Page, pageId: number): void {
try {
const body = await response.text();
entry.responseBody = body.slice(0, 2000);
} catch {}
} catch { /* non-fatal — response body may be unavailable or already consumed */ }
}
logPusher(networkLogs, entry);
} catch {}
} catch { /* non-fatal — request may have been aborted or page closed */ }
});
p.on("requestfailed", (request) => {

View file

@ -60,7 +60,7 @@ export function registerNavigationTools(pi: ExtensionAPI, deps: ToolDeps): void
let buf = await p.screenshot({ type: "jpeg", quality: 80, scale: "css" });
buf = await deps.constrainScreenshot(p, buf, "image/jpeg", 80);
screenshotContent = [{ type: "image", data: buf.toString("base64"), mimeType: "image/jpeg" }];
} catch {}
} catch { /* non-fatal — screenshot is optional, navigation result is still valid */ }
}
return {
@ -207,7 +207,7 @@ export function registerNavigationTools(pi: ExtensionAPI, deps: ToolDeps): void
data: buf.toString("base64"),
mimeType: "image/jpeg",
}];
} catch {}
} catch { /* non-fatal — screenshot is optional, reload result is still valid */ }
return {
content: [

View file

@ -161,7 +161,7 @@ export function registerNetworkMockTools(pi: ExtensionAPI, deps: ToolDeps): void
const cleanup = async () => {
try {
await p.unroute(pattern, handler);
} catch {}
} catch { /* cleanup — route may already be removed or page closed */ }
};
const routeInfo: ActiveRoute = {

View file

@ -137,7 +137,7 @@ export function registerPageTools(pi: ExtensionAPI, deps: ToolDeps): void {
try {
remaining.title = await remaining.page.title();
remaining.url = remaining.page.url();
} catch {}
} catch { /* non-fatal — page may have been closed or navigated away */ }
}
const pages = registryListPages(pageRegistry);
const lines = pages.map((p: any) => {

View file

@ -69,7 +69,7 @@ export function registerStatePersistenceTools(pi: ExtensionAPI, deps: ToolDeps):
// Ensure .gitignore covers the state dir
const gitignorePath = path.resolve(process.cwd(), STATE_DIR, ".gitignore");
await writeFile(gitignorePath, "*\n!.gitignore\n").catch(() => {});
await writeFile(gitignorePath, "*\n!.gitignore\n").catch(() => { /* best-effort — .gitignore may already exist or dir may be read-only */ });
const cookieCount = storageState.cookies?.length ?? 0;
const localStorageOrigins = storageState.origins?.length ?? 0;

View file

@ -55,7 +55,7 @@ export function registerVisualDiffTools(pi: ExtensionAPI, deps: ToolDeps): void
// Ensure .gitignore
const gitignorePath = pathMod.join(baselineDir, ".gitignore");
await writeFile(gitignorePath, "*\n!.gitignore\n").catch(() => {});
await writeFile(gitignorePath, "*\n!.gitignore\n").catch(() => { /* best-effort — .gitignore may already exist or dir may be read-only */ });
// Generate baseline name
const url = p.url();