Skip to content

har: skip pages with no matching entries instead of throwing#2483

Merged
soulgalore merged 1 commit into
mainfrom
har-empty-page-guard
May 24, 2026
Merged

har: skip pages with no matching entries instead of throwing#2483
soulgalore merged 1 commit into
mainfrom
har-empty-page-guard

Conversation

@soulgalore
Copy link
Copy Markdown
Member

Occasionally a HAR contains a page object whose pageref has no matching
entries — typically a navigation that didn't produce any requests, or
an extension-injected page. Three places in lib/support/har/index.js
treated this shape as impossible: getDocumentRequests dereferenced the
result of shift() without a guard, getFinalURL dereferenced the result
of pop() without a guard, and getMainDocumentTimings wrapped its entire
per-page loop in a single try/catch so one bad page wiped out the
main-document timings for every other page in the same HAR.

The downstream consequence was a noisy and confusing log triplet: a
"page without an URL in the HAR" warning, a "Could not get main
document timings TypeError: Cannot read properties of undefined
(reading 'response')" error, and then in sitespeed.io a coach-data
error because the timings array was empty.

Guard the three known crash points and continue past pages that can't
be resolved. The existing top-level try/catch in
getMainDocumentTimings stays as a safety net; the existing unit tests
still pass.

Co-authored-by: Claude noreply@anthropic.com

Change-Id: I5c6f2d7445bfdf1159c883f7dfc8f70d10bd3b32

  Occasionally a HAR contains a page object whose pageref has no matching
  entries — typically a navigation that didn't produce any requests, or
  an extension-injected page. Three places in lib/support/har/index.js
  treated this shape as impossible: getDocumentRequests dereferenced the
  result of shift() without a guard, getFinalURL dereferenced the result
  of pop() without a guard, and getMainDocumentTimings wrapped its entire
  per-page loop in a single try/catch so one bad page wiped out the
  main-document timings for every other page in the same HAR.

  The downstream consequence was a noisy and confusing log triplet: a
  "page without an URL in the HAR" warning, a "Could not get main
  document timings TypeError: Cannot read properties of undefined
  (reading 'response')" error, and then in sitespeed.io a coach-data
  error because the timings array was empty.

  Guard the three known crash points and continue past pages that can't
  be resolved. The existing top-level try/catch in
  getMainDocumentTimings stays as a safety net; the existing unit tests
  still pass.

  Co-authored-by: Claude noreply@anthropic.com

Change-Id: I5c6f2d7445bfdf1159c883f7dfc8f70d10bd3b32
@soulgalore soulgalore merged commit 33d1763 into main May 24, 2026
16 checks passed
@soulgalore soulgalore deleted the har-empty-page-guard branch May 24, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant