Skip to content

fix(browser): accept HAR files that begin with a byte-order mark - #1509

Merged
kaoru0822-kitauji merged 1 commit into
mainfrom
fix/har-byte-order-mark
Oct 10, 2026
Merged

kaoru0822-kitauji merged 1 commit into
mainfrom
fix/har-byte-order-mark

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

inspect_web_network_capture rejected any HAR file that starts with a UTF-8 byte-order mark:

$ rea inspect-web-network-capture bom.har har --format json
{"code":"invalid_request", … "issues":[{"path":["capture_path",""],"reason":"invalid_format","message":"HAR is malformed JSON."}]}

The HAR 1.2 specification's encoding section says the file must be UTF-8, that the reader must ignore a byte-order mark if one exists, and that the writer may emit one. Some HAR writers do emit it.

The cause is a WHATWG naming trap in HarCaptureProcess.ts:

new TextDecoder("utf-8", { fatal: true, ignoreBOM: true })

ignoreBOM: true means "do not treat the BOM specially", so it stays in the output ("{…}") and jsonc-parser then reports malformed JSON. The default (ignoreBOM: false) skips one leading mark.

Change

  • New decodeHarText(bytes) in HarCapture.ts decodes strict UTF-8 with the default BOM handling and keeps the existing HAR is not valid UTF-8 JSON. failure. HarCaptureProcess uses it.
  • Only one leading mark is skipped. A second mark is content and still fails as malformed JSON.
  • The artifact SHA-256 and byte count are still computed over the exact selected file bytes.

Verification

  • A new test in src/browser/history/HarCapture.test.ts covers four cases: a BOM-prefixed fixture decodes to the same capture as the plain one, a double BOM is still malformed, and invalid UTF-8 still fails. It fails on main at the first assertion.
  • npx vitest run src/browser/history passes (61 tests).
  • npm run test:focused -- tests/boundary/browser/historicalCaptureDecoder.test.ts tests/boundary/mcp/webNetworkCaptureMcp.test.ts tests/acceptance/tools/historicalCaptureResources.test.ts src/browser/history/CaptureFailures.test.ts passes (28 tests).
  • I ran the CLI by hand: the BOM-prefixed HAR now returns one record, as the plain file does.
  • npm run check:fast and npm run docs:check pass.

🤖 Generated with Claude Code

HAR 1.2 lets writers emit a UTF-8 byte-order mark and requires readers to
ignore it. The decoder passed ignoreBOM: true to TextDecoder, which keeps
the mark in the decoded text, so a BOM-prefixed export failed as "HAR is
malformed JSON." Decoding now uses the default, which skips one leading
mark. The artifact digest still covers the selected file bytes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@kaoru0822-kitauji
kaoru0822-kitauji merged commit 93ca276 into main Oct 10, 2026
21 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/har-byte-order-mark branch October 10, 2026 08:31
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…luto#1509)

HAR 1.2 lets writers emit a UTF-8 byte-order mark and requires readers to
ignore it. The decoder passed ignoreBOM: true to TextDecoder, which keeps
the mark in the decoded text, so a BOM-prefixed export failed as "HAR is
malformed JSON." Decoding now uses the default, which skips one leading
mark. The artifact digest still covers the selected file bytes.
@morluto morluto added the bug Something isn't working label Oct 14, 2026
@morluto morluto added the area: runtime Process capture and runtime observation label Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: runtime Process capture and runtime observation bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants