Skip to content

Capture: name a route that is not an HTML page - #63

Merged
tmashara merged 2 commits into
mainfrom
claude/issue-57-non-html
Oct 29, 2026
Merged

tmashara merged 2 commits into
mainfrom
claude/issue-57-non-html

Conversation

@tmashara

@tmashara tmashara commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

What / why

A route that serves a PDF, a download, an image, JSON or plain text used to fail with a raw Playwright error (page.goto: Download is starting, or for SVG page.addStyleTag: TypeError: Cannot read properties of null), or it got screenshotted as Chromium's file viewer. Now it fails with:

not an HTML page: server sent application/pdf at http://…/report.pdf

How it works (src/capture.ts only): the existing response listener keeps the last main-frame navigation response per page (a doc WeakMap beside network). Redirect hops fire too, so the last one is the final document. Iframe navigations are filtered out. capture() resets it before goto. A download makes goto throw, and if a non-HTML document arrived, that error is swapped for the document's response. The status check runs first, so a text/plain 404 still reads HTTP 404. There is no HEAD probe and no extra request: the type is the one Chromium actually got. The new error is a plain Error, so it is never retried and composes with the shot deadline from #61.

What counts as HTML

text/html or application/xhtml+xml in any case and with any parameters, or no content-type at all. Chromium sniffs a missing type as HTML, and refusing it would break bare static servers.

Everything else is refused, including image/svg+xml, application/json and text/plain. The tool diffs rendered pages, and Chromium's viewer for a raw file is not a page. SVG documents already could not get past addStyleTag (they have no <head>), so refusing them loses nothing and replaces a TypeError with a named cause.

Limits: a download with no content-type, or text/html served as an attachment, still shows the raw Download is starting error, as before.

How tested

  • New visual test in tests/visual/guardrails.test.ts (render gate): /shared/doc.pdf covers the branch where goto throws and /shared/img/azure.svg the branch where it resolves. It asserts both report errors name their type. It fails on main (raw download / addStyleTag errors) and passes with the fix.
  • Added a doc.pdf fixture to tests/fixtures/shared/ and .pdf to the test server's content types. No new page dir.
  • npm run typecheck, lint, format:check, npm test (290 pass) and npm run test:visual (330 pass) all pass locally. No accepted hashes recorded.
  • Docs: added a row to the errors table in skills/renderdiff/reference.md.

Fixes #57

🤖 Generated with Claude Code

tmashara and others added 2 commits October 29, 2026 17:00
A PDF, download, image, JSON or text route now errors with
"not an HTML page: server sent <type> at <url>" instead of
"page.goto: Download is starting" or an addStyleTag TypeError. The type
comes from the main-frame document response Chromium already received.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tmashara
tmashara merged commit df65f79 into main Oct 29, 2026
3 checks passed
@tmashara
tmashara deleted the claude/issue-57-non-html branch October 29, 2026 16:11
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.

Name non-HTML routes instead of a raw ERR_ABORTED

1 participant