{"record":{"id":"2c57286145bc5da1","repo":"pbakaus/impeccable","slug":"cap-error","errorCode":null,"errorMessage":"${cap.error}","messagePattern":"\\$\\{cap\\.error\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"browser-bundle/50-scan.js","lineNumber":455,"sourceCode":"  window.impeccableScanAsync = scanAsync;\n  // Raw measurement for the URL engine's content-hidden-at-rest pass: it\n  // drives a reveal sweep from Node and thresholds the result itself.\n  window.impeccableMeasureHiddenText = () => JSON.parse(__impeccable.measure_hidden_text());\n  window.impeccableCollectVisualContrastCandidates = collectVisualContrastCandidates;\n  window.impeccableAnalyzeVisualContrast = analyzeVisualContrast;\n  window.impeccableGetLastVisualContrastAnalyses = () => lastVisualContrastAnalyses.slice();\n\n  // The snapshot route (what the extension runs when the page's CSP keeps\n  // WebAssembly out of every world it can reach), exposed here so the two\n  // routes can be A/B'd on the same page: capture, run the same core over\n  // the snapshot (answering its hit-test needs from the live page), and\n  // serialize through it. Deterministic findings only; the visual-contrast\n  // pass over a snapshot is the extension's (see 60-offscreen.js).\n  window.impeccableSnapshotCapture = (options) => __impeccableSnapshot.capture(options);\n  window.impeccableDetectFromSnapshot = function (options = {}) {\n    const t0 = performance.now();\n    const cap = __impeccableSnapshot.capture(options);\n    if (cap.error) throw new Error(cap.error);\n    const t1 = performance.now();\n    let out = JSON.parse(__impeccable.collect_findings_from_snapshot(cap.json, collectConfigJson()));\n    let rounds = 1;\n    while (out.needs) {\n      __impeccable.snapshot_add_facts(JSON.stringify(__impeccableSnapshot.answer(out.needs, cap)));\n      out = JSON.parse(__impeccable.collect_browser_findings(collectConfigJson()));\n      if (__impeccable.snapshot_has_needs()) out = { needs: JSON.parse(__impeccable.snapshot_take_needs()) };\n      rounds++;\n    }\n    const serialized = JSON.parse(__impeccable.serialize_findings(JSON.stringify(out.groups)));\n    const unknownStyleProps = JSON.parse(__impeccable.snapshot_unknown_style_props());\n    __impeccable.snapshot_clear();\n    return {\n      findings: serialized,\n      pageLevel: out.pageLevel,\n      stats: { ...cap.stats, rounds, unknownStyleProps, captureMs: t1 - t0, coreMs: performance.now() - t1 },\n    };\n  };","sourceCodeStart":437,"sourceCodeEnd":473,"githubUrl":"https://github.com/pbakaus/impeccable/blob/2bc2879276c1f321a53c4ca99d3371e411329b52/browser-bundle/50-scan.js#L437-L473","documentation":"impeccableDetectFromSnapshot wraps a snapshot capture plus WASM analysis; if the underlying __impeccableSnapshot.capture() step fails it returns {error}, and this wrapper re-throws that error string verbatim as an Error. The cap.error text describes why the page snapshot could not be captured or processed.","triggerScenarios":"Calling window.impeccableDetectFromSnapshot(options) when capture(options) returns an error field — e.g. the document is in a non-capturable state, the DOM snapshot builder threw, or the core module is unavailable.","commonSituations":"Calling detect-from-snapshot on pages where capture is unsupported (about:blank, cross-origin frames, detached documents); racing the call before the core finishes loading.","solutions":["Read the thrown message: it is the raw capture error, and fix the specific capture problem it names","Ensure the core/agent script is fully initialized before calling impeccableDetectFromSnapshot","Call it only on top-level, fully loaded documents","Wrap in try/catch and fall back to impeccableDetectAsync if snapshot-based detection is optional"],"exampleFix":"// before\nconst findings = impeccableDetectFromSnapshot();\n// after\nlet findings;\ntry { findings = impeccableDetectFromSnapshot(); }\ncatch (e) { console.warn('snapshot capture failed:', e.message); findings = null; }","handlingStrategy":"try-catch","validationCode":"function canDetectFromSnapshot() {\n  return typeof window.impeccableDetectFromSnapshot === 'function' &&\n    document.readyState === 'complete';\n}","typeGuard":null,"tryCatchPattern":"try {\n  const out = impeccableDetectFromSnapshot(options);\n} catch (e) {\n  console.warn('impeccable snapshot detect failed:', e.message);\n  // fall back to impeccableDetectAsync or skip\n}","preventionTips":["Only call after window load and full core initialization","Confirm capture succeeded (no .error) when using the capture API directly","Pin one version of the embed script across the page"],"tags":["snapshot","browser","error-propagation"],"backgroundTag":"http-error-response","analyzedSha":"2bc2879276c1f321a53c4ca99d3371e411329b52","analyzedAt":"2026-09-08T04:51:14.109Z","contentChangedAt":"2026-09-08T04:51:14.109Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}