Repository navigation
Capture: name a route that is not an HTML page - #63
Merged
Merged
Conversation
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>
This was referenced Oct 29, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 SVGpage.addStyleTag: TypeError: Cannot read properties of null), or it got screenshotted as Chromium's file viewer. Now it fails with:How it works (src/capture.ts only): the existing
responselistener keeps the last main-frame navigation response per page (adocWeakMap besidenetwork). Redirect hops fire too, so the last one is the final document. Iframe navigations are filtered out.capture()resets it beforegoto. A download makesgotothrow, and if a non-HTML document arrived, that error is swapped for the document's response. The status check runs first, so atext/plain404 still readsHTTP 404. There is no HEAD probe and no extra request: the type is the one Chromium actually got. The new error is a plainError, so it is never retried and composes with the shot deadline from #61.What counts as HTML
text/htmlorapplication/xhtml+xmlin 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/jsonandtext/plain. The tool diffs rendered pages, and Chromium's viewer for a raw file is not a page. SVG documents already could not get pastaddStyleTag(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/htmlserved as an attachment, still shows the rawDownload is startingerror, as before.How tested
tests/visual/guardrails.test.ts(render gate):/shared/doc.pdfcovers the branch where goto throws and/shared/img/azure.svgthe 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.doc.pdffixture totests/fixtures/shared/and.pdfto the test server's content types. No new page dir.npm run typecheck,lint,format:check,npm test(290 pass) andnpm run test:visual(330 pass) all pass locally. No accepted hashes recorded.Fixes #57
🤖 Generated with Claude Code