fix(browser-tools): document intentional silent catches, add debug logging for others (#1013)

Replaces 11 silent `.catch(() => {})` patterns with descriptive comments
(for intentional best-effort operations like networkidle waits, dialog
dismissal, browser close) or GSD_DEBUG-gated error logging (for page.goto
restore in device emulation and ensureMutationCounter in settle).

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
TÂCHES 2026-03-17 18:01:44 -06:00 committed by GitHub
parent b1ad5c431f
commit 5ecb6c6abb
6 changed files with 11 additions and 11 deletions

View file

@ -137,7 +137,7 @@ export function attachPageListeners(p: Page, pageId: number): void {
pageId,
});
// Auto-accept all dialogs to prevent page freezes
await dialog.accept().catch(() => {});
await dialog.accept().catch(() => { /* cleanup — dialog may already be dismissed */ });
});
// Frame detach handler — clears activeFrame if the selected frame detaches
@ -236,7 +236,7 @@ export async function ensureBrowser(): Promise<{ browser: Browser; context: Brow
newPage.waitForLoadState("domcontentloaded", { timeout: 5000 })
.then(() => newPage.title())
.then((title) => { entry.title = title; })
.catch(() => {});
.catch(() => { /* best-effort title fetch — page may have closed or navigated away */ });
});
return { browser, context, page: getActivePage() };
@ -264,7 +264,7 @@ export function getActivePageOrNull(): Page | null {
export async function closeBrowser(): Promise<void> {
const browser = getBrowser();
if (browser) {
await browser.close().catch(() => {});
await browser.close().catch(() => { /* cleanup — browser may already be closed */ });
}
resetAllState();
}

View file

@ -126,7 +126,7 @@ export async function settleAfterActionAdaptive(
// Install mutation counter + read initial state in one evaluate sequence.
// ensureMutationCounter must run first (installs the observer), then we
// read the baseline via the combined reader.
await ensureMutationCounter(p).catch(() => {});
await ensureMutationCounter(p).catch((e) => { if (process.env.GSD_DEBUG) console.error("[browser-tools] ensureMutationCounter failed:", e.message); });
const initial = await readSettleState(p, checkFocus);
let previousMutationCount = initial.mutationCount;
let previousFocus = initial.focusDescriptor;

View file

@ -175,7 +175,7 @@ export function registerAssertionTools(pi: ExtensionAPI, deps: ToolDeps): void {
switch (step.action) {
case "navigate": {
await p.goto(step.url, { waitUntil: "domcontentloaded", timeout: 30000 });
await p.waitForLoadState("networkidle", { timeout: 5000 }).catch(() => {});
await p.waitForLoadState("networkidle", { timeout: 5000 }).catch(() => { /* networkidle timeout — non-fatal, page may still be usable */ });
return { ok: true, action: step.action, url: p.url() };
}
case "click": {

View file

@ -134,7 +134,7 @@ export function registerDeviceTools(pi: ExtensionAPI, deps: ToolDeps): void {
// Navigate back to previous URL if it wasn't about:blank
if (currentUrl && currentUrl !== "about:blank") {
await page.goto(currentUrl, { waitUntil: "domcontentloaded", timeout: 15000 }).catch(() => {});
await page.goto(currentUrl, { waitUntil: "domcontentloaded", timeout: 15000 }).catch((e) => { if (process.env.GSD_DEBUG) console.error("[browser-tools] device goto restore failed:", e.message); });
}
const viewport = deviceDescriptor.viewport;

View file

@ -39,7 +39,7 @@ export function registerExtractTools(pi: ExtensionAPI, deps: ToolDeps): void {
const { page: p } = await deps.ensureBrowser();
// Wait for network idle before extraction
await p.waitForLoadState("networkidle", { timeout: 10000 }).catch(() => {});
await p.waitForLoadState("networkidle", { timeout: 10000 }).catch(() => { /* networkidle timeout — non-fatal, page may still be usable */ });
const schema = params.schema as any;
const scopeSelector = params.selector;

View file

@ -31,7 +31,7 @@ export function registerNavigationTools(pi: ExtensionAPI, deps: ToolDeps): void
beforeState = await deps.captureCompactPageState(p, { includeBodyText: true });
actionId = deps.beginTrackedAction("browser_navigate", params, beforeState.url).id;
await p.goto(params.url, { waitUntil: "domcontentloaded", timeout: 30000 });
await p.waitForLoadState("networkidle", { timeout: 5000 }).catch(() => {});
await p.waitForLoadState("networkidle", { timeout: 5000 }).catch(() => { /* networkidle timeout — non-fatal, page may still be usable */ });
await new Promise(resolve => setTimeout(resolve, 300));
const title = await p.title();
@ -110,7 +110,7 @@ export function registerNavigationTools(pi: ExtensionAPI, deps: ToolDeps): void
};
}
await p.waitForLoadState("networkidle", { timeout: 5000 }).catch(() => {});
await p.waitForLoadState("networkidle", { timeout: 5000 }).catch(() => { /* networkidle timeout — non-fatal, page may still be usable */ });
const title = await p.title();
const url = p.url();
@ -154,7 +154,7 @@ export function registerNavigationTools(pi: ExtensionAPI, deps: ToolDeps): void
};
}
await p.waitForLoadState("networkidle", { timeout: 5000 }).catch(() => {});
await p.waitForLoadState("networkidle", { timeout: 5000 }).catch(() => { /* networkidle timeout — non-fatal, page may still be usable */ });
const title = await p.title();
const url = p.url();
@ -189,7 +189,7 @@ export function registerNavigationTools(pi: ExtensionAPI, deps: ToolDeps): void
try {
const { page: p } = await deps.ensureBrowser();
await p.reload({ waitUntil: "domcontentloaded", timeout: 30000 });
await p.waitForLoadState("networkidle", { timeout: 5000 }).catch(() => {});
await p.waitForLoadState("networkidle", { timeout: 5000 }).catch(() => { /* networkidle timeout — non-fatal, page may still be usable */ });
const title = await p.title();
const url = p.url();