GoogleChrome/lighthouse · error · Error

provided json is not a Lighthouse result

Error message

provided json is not a Lighthouse result

What it means

Thrown by the treemap app's coerceToOptions when none of the candidate shapes — the JSON itself, json.lhr, or json.lighthouseResult — has an 'audits' object. The treemap accepts a raw LHR, a runner-result wrapper ({lhr:...}), or a PSI-style wrapper ({lighthouseResult:...}), and requires at minimum an 'audits' object to be considered a Lighthouse result.

Source

Thrown at treemap/app/src/main.js:985

   * Accepts if json is an lhr, or {lhr: ...} or {lighthouseResult: ...}
   * Throws error if json does not match expectations.
   * @param {any} json
   * @return {LH.Treemap.Options}
   */
  coerceToOptions(json) {
    /** @type {LH.Treemap.Options['lhr']|null} */
    let lhr = null;
    if (json && typeof json === 'object') {
      for (const maybeLhr of [json, json.lhr, json.lighthouseResult]) {
        if (maybeLhr?.audits && typeof maybeLhr.audits === 'object') {
          lhr = maybeLhr;
          break;
        }
      }
    }

    if (!lhr) {
      throw new Error('provided json is not a Lighthouse result');
    }

    if (!lhr.audits['script-treemap-data']) {
      throw new Error('provided Lighthouse result is missing audit: `script-treemap-data`');
    }

    let initialView;
    if (json && typeof json === 'object' && typeof json.initialView === 'string') {
      initialView = json.initialView;
    }

    return {lhr, initialView};
  }

  /**
   * Loads report json from gist URL, if valid. Updates page URL with gist id
   * and loads from GitHub.
   * @param {string} urlStr gist URL

View on GitHub (pinned to 9515cd4e58)

Solutions

  1. Load an actual Lighthouse Result (or wrap it as {lhr: lhr} / {lighthouseResult: lhr}).
  2. Validate the payload has a top-level or nested 'audits' object before passing it to the treemap.
  3. Surface a user-friendly message when the input fails this shape check.

Example fix

// before
treemapApp.load(jsonFromFile); // arbitrary json

// after
function looksLikeLhr(x) {
  return x && typeof x === 'object' && x.audits && typeof x.audits === 'object';
}
const candidate = looksLikeLhr(json) ? json
  : looksLikeLhr(json?.lhr) ? json.lhr
  : looksLikeLhr(json?.lighthouseResult) ? json.lighthouseResult
  : null;
if (candidate) treemapApp.load(candidate); else showInvalidFileError();
Defensive patterns

Strategy: type-guard

Validate before calling

function asLhr(json) {
  const candidates = [json, json?.lhr, json?.lighthouseResult];
  return candidates.find(c => c && typeof c === 'object' && c.audits && typeof c.audits === 'object') ?? null;
}
const lhr = asLhr(json);
if (!lhr) throw new Error('Input is not a Lighthouse result');

Type guard

/** @param {any} x */
function looksLikeLhr(x) {
  return x != null && typeof x === 'object' && typeof x.audits === 'object' && x.audits !== null;
}

Try / catch

try {
  treemapApp.load(json);
} catch (err) {
  if (err.message === 'provided json is not a Lighthouse result') {
    showInvalidFileError();
  } else throw err;
}

Prevention

When it happens

Trigger: Loading arbitrary/wrong JSON into the treemap: passing a plain object, a settings file, or a payload whose audits were stripped. None of the three inspected keys yields an object with an 'audits' property.

Common situations: User drops the wrong file onto the treemap; URL hash carries malformed/truncated JSON; integrating treemap with a custom JSON source that doesn't match the expected LHR shape.

Related errors


AI-assisted analysis of GoogleChrome/lighthouse@9515cd4e58 (2026-08-13). Data as JSON: /api/errors/ee286606ea955d9c. Report an issue: GitHub.