{"record":{"id":"cd90ddeee751b64a","repo":"jackwener/OpenCLI","slug":"gov-policy-command-browser-extraction-failed","errorCode":null,"errorMessage":"gov-policy ${command} browser extraction failed: ${error?.message ?? error}","messagePattern":"gov-policy (.+?) browser extraction failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/gov-policy/utils.js","lineNumber":53,"sourceCode":"        context || 'The page structure may have changed or the page did not finish rendering.',\n    );\n}\n\nexport function requireRows(command, rows) {\n    if (!Array.isArray(rows) || rows.length === 0) {\n        throw new CommandExecutionError(\n            `gov-policy ${command} extractor returned no result rows`,\n            'The page structure may have changed or all result cards were missing required title fields.',\n        );\n    }\n    return rows;\n}\n\nexport function wrapBrowserError(command, error) {\n    if (error instanceof ArgumentError || error instanceof EmptyResultError || error instanceof CommandExecutionError) {\n        throw error;\n    }\n    throw new CommandExecutionError(`gov-policy ${command} browser extraction failed: ${error?.message ?? error}`);\n}\n","sourceCodeStart":35,"sourceCodeEnd":55,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/gov-policy/utils.js#L35-L55","documentation":"Thrown by wrapBrowserError as a catch-all: any error thrown during browser automation that is not already an ArgumentError, EmptyResultError, or CommandExecutionError is re-wrapped as `gov-policy <command> browser extraction failed: <message>`. This normalizes low-level failures (Puppeteer timeouts, target closed, navigation aborted) into the library's standard error type while preserving known errors untouched.","triggerScenarios":"Calling a gov-policy command when the underlying browser operation throws a foreign error: page.goto() timeout, browser crashed or target closed, navigation interrupted, PermissionError launching the headless browser, or a TypeError inside the injected script.","commonSituations":"Chromium not installed or blocked by sandboxing in CI containers, slow/blocked network causing navigation timeouts, the site closing connections, or memory pressure killing the browser tab.","solutions":["Read the inner message to identify the root cause (timeout vs crash vs navigation)","Ensure a supported headless browser is installed and launchable (check Puppeteer deps in CI)","Retry the command — transient navigation/timeouts often succeed on a second attempt","Increase any available timeout options or run on a faster/stabler network connection"],"exampleFix":"// before\nawait runGovPolicy('search', { q: '网络安全' });\n// after\ntry { await runGovPolicy('search', { q: '网络安全' }); }\ncatch (e) {\n  if (/timeout|Target closed/i.test(e.message)) return retry(() => runGovPolicy('search', { q: '网络安全' }), 2);\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"// Preflight browser launchability before running extraction\nlet browser;\ntry { browser = await puppeteer.launch({ headless: true }); await browser.close(); }\ncatch (e) { throw new Error('Headless browser unavailable: ' + e.message); }","typeGuard":"function isKnownCliError(e) { return e instanceof ArgumentError || e instanceof EmptyResultError || e instanceof CommandExecutionError; }","tryCatchPattern":"try {\n  await runGovPolicy(command, args);\n} catch (err) {\n  if (/browser extraction failed/.test(err.message)) {\n    const cause = err.message.replace(/.*failed: /, '');\n    if (/timeout|Target closed|Navigation/i.test(cause)) return retryCommand(command, args);\n    if (/browser|sandbox|libnss/i.test(cause)) console.error('Install Chromium deps: check puppeteer setup in this environment.');\n    else throw err;\n  } else throw err;\n}","preventionTips":["Ensure Chromium/Puppeteer and its system libraries are installed, especially in CI containers","Set generous navigation timeouts for slow government sites","Retry transient navigation failures once before surfacing errors","Distinguish known CLI error types from foreign errors to keep messages actionable"],"tags":["browser","puppeteer","web-scraping","gov-policy"],"backgroundTag":"browser-automation-failure","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}