pbakaus/impeccable · error · Error

snapshot did not parse

Error message

snapshot did not parse

What it means

runScan in the offscreen document loads the message's snapshot into the WASM core via snapshot_load(); a return value of 0xFFFFFFFF (u32 -1 sentinel) means the snapshot JSON failed to parse, and the function throws this error. No scan is started on invalid input.

Source

Thrown at browser-bundle/60-offscreen.js:141

  // addVisualContrastResult over id-keyed groups: the two decisions are the
  // core's; this only keeps the map.
  function addVisualContrastResult(wasm, groups, result) {
    const elId = wasm.visual_contrast_result_el(JSON.stringify(result));
    if (!elId) return 0;
    let group = groups.find(g => g.el === elId);
    const existing = group ? group.findings : [];
    const finding = JSON.parse(wasm.visual_contrast_result_finding(elId, JSON.stringify(existing), JSON.stringify(result)));
    if (!finding) return 0;
    if (group) group.findings.push(finding);
    else groups.push({ el: elId, findings: [finding] });
    return elId;
  }

  async function runScan(session, msg) {
    const wasm = await coreReady();
    const n = wasm.snapshot_load(msg.snapshot);
    if (n === 0xFFFFFFFF) throw new Error('snapshot did not parse');
    const config = msg.config || {};
    const IO = createOffscreenVisualIO(wasm, session);
    const vc = createVisualContrast(IO);
    const t0 = performance.now();
    const collected = JSON.parse(await IO.core('collect_browser_findings', configJson(config)));
    const groups = collected.groups;
    const stats = { elements: n, coreMs: performance.now() - t0, unknownStyleProps: JSON.parse(wasm.snapshot_unknown_style_props()) };
    await ask(session, {
      stage: 'findings',
      groups,
      pageLevel: collected.pageLevel,
      serialized: serialize(wasm, groups),
      stats,
    });
    const options = config;
    // An ignoreFiles-waived page (config.skipScan) answers every stage empty:
    // the core already emptied the collect pass, and the visual pass would
    // repopulate it, so it is skipped with everything else (mirrors

View on GitHub (pinned to 2bc2879276)

Solutions

  1. Regenerate the snapshot with the current impeccableSnapshotCapture and resend the scan message
  2. Check that the extension's content script and offscreen bundle are the same version (reload/reinstall the extension)
  3. Log msg.snapshot before sending and validate it is well-formed JSON
  4. Guard the sender: only pass result of a successful capture (no .error field)

Example fix

// before
port.postMessage({ type: 'scan', snapshot: maybeSnapshot });
// after
if (!maybeSnapshot || typeof maybeSnapshot !== 'string') throw new Error('no snapshot');
JSON.parse(maybeSnapshot); // throws early if malformed
port.postMessage({ type: 'scan', snapshot: maybeSnapshot });
Defensive patterns

Strategy: validation

Validate before calling

function snapshotIsParsable(s) {
  if (typeof s !== 'string' || !s) return false;
  try { JSON.parse(s); return true; } catch { return false; }
}
// call before posting the scan message

Type guard

function isSnapshotMsg(msg) { return msg && typeof msg.snapshot === 'string' && snapshotIsParsable(msg.snapshot); }

Try / catch

try {
  await runScan(session, msg);
} catch (e) {
  if (e.message === 'snapshot did not parse') {
    // request a fresh capture from the content script and retry once
  }
}

Prevention

When it happens

Trigger: Sending a runScan/scan message to the offscreen document whose msg.snapshot is malformed JSON, truncated, or produced by an incompatible snapshot version.

Common situations: Version skew between the content-script snapshot serializer and the bundled WASM core; passing a stale or manually edited snapshot string; a capture that failed silently upstream.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of pbakaus/impeccable@2bc2879276 (2026-09-08). Data as JSON: /api/errors/bb0f1f16963ad837. Report an issue: GitHub.