Skip to content

parser: a page body without <html> (empty, text, JSON) makes document.head throw; every DOM rule reports a bogus 'Rule error' fail #1270

Closed

Description

@nc9

A page whose body has no <html> element gives linkedom a document with documentElement === null. That covers an empty 200, whitespace only, a comment only, plain text, or JSON served as text/html. linkedom's document.head and document.body getters then throw Cannot destructure property 'firstElementChild' from null or undefined value.

Every DOM rule that touches head or body throws on that page. runner.ts turns each throw into a <rule>-error check with status: "fail" at the rule's own severity. So one degenerate page produces a burst of bogus findings across categories, all naming that page: a11y/aria-hidden-body, perf/lcp-hints, perf/cls-hints, perf/inp-hints, perf/preconnect, perf/render-blocking, perf/font-loading, content/date-agreement, and more. Users see these as real errors, and they lower the score.

Seen in a 656-site batch on v0.0.140 (linux-x64, --offline --passive, 30 pages): 2 sites had this burst on one page each. The same URL fetched on its own returns normal HTML, so the bad body was transient (an empty or interstitial response during the crawl).

Repro, linkedom 0.18.13 as pinned:

import { parseHTML } from "linkedom";
for (const html of ["", "   ", "<!-- c -->", "plain text", '{"json":1}']) {
  const { document } = parseHTML(html);
  document.documentElement; // null
  document.head;            // throws
}

parseDocument in packages/parser/src/index.ts returns linkedom's document unchanged.

Acceptance Criteria

  • parseDocument always returns a document with a non-null documentElement, head and body, for an empty string, whitespace, a comment only, plain text and JSON input. A parser test covers each case.
  • A crawled HTML page with an empty or non-HTML body is reported once, as a page-level finding or a not-evaluated reason (e.g. "empty or non-HTML response"), instead of one <rule>-error fail per DOM rule.
  • An engine-level test audits a fixture site with one empty-body page and asserts no Rule error: checks in the result.
  • Docs are updated if a new finding or not-evaluated reason is added.

Activity

  1. added
    bug
    on Oct 29, 2026
  2. added theissue type on Oct 29, 2026
  3. added
    size: S
    rules
    on Oct 29, 2026
  4. nc9 commented on Oct 30, 2026

    @nc9
    ContributorAuthor

    Fixed in v0.0.142 (73780351), via the stacked release PR #1331.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrulessize: S

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions