Skip to content

feat(web): draw SVG images as PNGs so Read can show them - #379

Merged
SSFSKIM merged 2 commits into
mainfrom
web-svg-raster
Oct 25, 2026
Merged

SSFSKIM merged 2 commits into
mainfrom
web-svg-raster

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Board #134. Read cannot show an SVG, and many pages draw their charts as SVGs. The web clipper now draws each saved SVG as a PNG beside it and points the page's link at the PNG. The design was approved as proposed. web 0.2.2 → 0.3.0 (rebased onto #380).

What behaves differently

  • A page's SVG images. Each assets/NN.svg gets assets/NN.png beside it, and the markdown link names the PNG. The SVG stays, because its text (a chart's labels) is readable too. meta.json's image entry becomes file: assets/NN.png, svg: assets/NN.svg.
  • An SVG fetched by its own URL is saved as image.svg and drawn as image.png, recorded as png in the result.
  • How it draws (web/clipper/src/draw.ts):
    • one launch per page of the render path's Chromium: the filtering proxy and its boundary, the WebRTC/QUIC flags, a fresh profile;
    • each SVG drawn as an <img> from a data: URI on a blank document (Page.setDocumentContent), on white, and screenshotted;
    • at twice its natural size, the long edge at most 2,000 px. An SVG with no width of its own (or a percentage) is sized by its viewBox: Chromium's 300-px default would draw an 800-unit chart at three-eighths scale;
    • every SVG of a page within 20 s and the fetch's deadline.
  • Reply text (agent-facing; Decision Log entry):
    • R2 image list, drawn: …/assets/11.png L85 "alt" (an SVG drawn as PNG; its source: …/assets/11.svg)
    • not drawn (no Chromium, the time budget, an undecodable file): …/assets/11.svg L85 "alt" (an SVG: Read shows its source text, not the picture; not drawn: <why>). The reply used to invite a Read to "see" an SVG.
    • an SVG by URL: Image saved: …/image.png, drawn from the SVG …/image.svg. Read it to see it. Not drawn: Image saved: …/image.svg (an SVG: Read shows its source text, not the picture; not drawn: <why>).
  • Pages without SVGs are byte-identical, meta.json included. No new field appears unless there is an SVG.

The image-mode claim and its proof

Drawn as an image, an SVG runs no script and loads nothing it names except data: URIs, so drawing makes no request. The proxy is a second wall. test/draw.test.ts aims ten channels at the test server under a name the boundary allows:

  • @import, @font-face, and a paint server;
  • <image href>, xlink:href, <use>, and <feImage>;
  • a <foreignObject> <img>;
  • a script's fetch, and a script's Image.

The drawing reaches none of them. As the control, the same browser, proxy and boundary open the same SVG as a document, and that reaches all ten.

Verification

  • cd web/clipper && npm test at 3b5c8654: 145 pass, 0 skipped (Chromium present). New tests:
    • sizes: 400×200 → 800×400, 3000×1000 → 2000×667, viewBox-only 800×200 → 1600×400;
    • an undecodable SVG is not drawn, with the reason;
    • the image-mode trap test and its control;
    • an SVG fetched by its own URL;
    • without Chromium (runs in CI): the SVG stays the link, with the reason;
    • a non-SVG image entry gets no new keys.
  • Mod tests: 55 pass, with exact-text tests for the new reply lines.
  • bash web/tests/run.sh at 3b5c8654: all pass (145 clipper, the bundle check, 55 mod, 55 eval). ci-gate GREEN: https://github.com/SSFSKIM/doperpowers/actions/runs/40236089037
  • Live: go.dev/blog/survey2024-h2-results drew 36 SVG charts in a 4 s fetch, all legible. The direct cloud_platform.svg URL drew as image.png. The driver also works with Google Chrome (--headless=new).

Review

doperpowers:reviewer-medium ran two rounds.

Round 1 found nothing blocking in security. Image mode held: 0 trap requests, with all 10 control channels live. A page without SVGs came out byte-identical, meta.json included. It found two real sizing defects, fixed in 3b5c8654:

  • a viewBox that overflows to Infinity (0 0 1e999 100) made the screenshot size NaN, and the error ended the whole page's drawing;
  • a regex took markup in a leading comment, or a root cut short by a quoted >, for the root's attributes.

Now:

  • the root's width and viewBox are read in the drawing page by DOMParser over the same bytes. Its document is inert: probes made no request, external entities and stylesheets included;
  • a size must be finite and positive;
  • one SVG's failure marks only that SVG, unless the time budget is spent.

Each new test fails on the previous code.

Round 2, on the fix commit, found no material findings.

Eval: the image tasks in configuration B, on this build

20 runs on sol at xhigh (the approved spend), on the build before the rebase onto #380 (d7385f6e; #380 changes only extraction of documents with no <html>/<body>), set beside the last rounds' B numbers. Before is the final run for image-3 to image-5, and development round 3 for image-1 and image-2. Each cell is correct · median fetch calls · median sol tokens · median seconds · Reads of a .png / .svg.

Task Before (B) After (B)
image-3 (peps.python.org, PNG) 4/4 · 1 · 12.1k · 11 s · 4/0 4/4 · 1 · 12.2k · 12 s · 4/0
image-4 (go.dev survey, SVG charts) 4/4 · 1 · 23.5k · 22 s · 0/4 4/4 · 1 · 20.6k · 18 s · 4/0
image-5 (git-scm, PNG) 4/4 · 1 · 19.2k · 10 s · 4/0 4/4 · 1 · 19.2k · 12 s · 4/0
image-1 (archive.apache.org, PNG; dev) 2/2 · 1 · 15.7k · 22 s · 2/0 4/4 · 1 · 18.0k · 32 s · 4/0
image-2 (Rust survey, PNG; dev) 2/2 · 1 · 24.3k · 9 s · 2/0 4/4 · 1 · 24.4k · 12 s · 4/0
  • image-4, the SVG task: every agent now Reads the drawn PNG and answers from the picture. Before, every agent read the chart's SVG source. Tokens fell about 12% and time about 4 s.
  • The PNG tasks are unchanged in answers and calls; their pages have no SVGs, so their output is byte-identical.
  • image-1's longer time is archive.apache.org plus a loaded machine (load average about 100 from other sessions), not drawing: the page has no SVG.

Sminos-Session: web-fetch-plugin#700c5e84 (doperpowers on macbook)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T21:12:50.787915Z d7385f6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Board #134. Read cannot show an SVG, and many pages' charts are SVGs.
Each saved SVG is now drawn as assets/NN.png beside assets/NN.svg, and
the markdown link names the PNG (clipper/src/draw.ts):
- one launch of the render path's Chromium per page, behind the same
  filtering proxy and flags, with a fresh profile;
- each SVG drawn as an <img> from a data: URI on a blank document set
  with Page.setDocumentContent, at twice its natural size (its viewBox's
  when it names no width), its long edge at most 2,000 px, on white;
- every SVG of a page within 20 s and the fetch's deadline.

An SVG fetched by its own URL becomes image.svg plus image.png.

Drawn as an image, an SVG runs no script and loads nothing it names
except data: URIs. The new test aims ten channels at a host the boundary
allows (@import, @font-face, a paint server, <image href>, xlink:href,
<use>, <feImage>, <foreignObject>, a script's fetch and Image): drawing
reaches none of them, and the same browser opening the SVG as a document
reaches all ten.

The reply names a drawn SVG's PNG with its source. An SVG not drawn
(no Chromium, the time budget, an undecodable file) now says Read shows
its source text, not the picture, where the reply used to invite a Read
to see it. Pages without SVGs, and their meta.json, are byte-identical.
Decision Log entry in the design. web 0.3.0.

Sminos-Session: web-fetch-plugin#700c5e84 (doperpowers on macbook)
… no longer ends the page's drawing

Two review findings on the SVG drawing (board #134):

- The size rule found the root with a regex on the raw source. Markup in
  a comment before the root was taken for it (an 800x200 chart drawn as a
  20x20 thumbnail, and the page's link pointed at it), and a '>' inside a
  quoted root attribute hid the real viewBox. The root's width and viewBox
  are now read in the drawing's page, after the image decodes, by a
  DOMParser over the same bytes: Chromium's own XML parser, whose document
  runs no script and loads nothing (a probe of the ten trap channels made
  no request in 2 s; imported into the live page, the same root reached 7).
  The viewBox is used only with four finite numbers and a positive width
  and height; otherwise the natural size.

- viewBox="0 0 1e999 100" passed the > 0 check as Infinity, the screenshot
  size became NaN, Chromium rejected it, and the outer catch marked every
  later SVG on the page not drawn. Now a measured size must be finite and
  positive, and a failure on one SVG marks only that one ("Chromium could
  not draw it (...)"); a spent time budget still kills the browser and
  ends the batch.

Tests: real-Chromium cases for the comment, the quoted '>', a percentage
width with a comma-separated viewBox, a width of its own, and the
out-of-range viewBox followed by an ordinary SVG; stand-in-browser cases
(fake-chrome.mjs now answers the drawing's commands) for a refused SVG
followed by a drawn one, and for a time-out ending the batch. The pure
viewBoxSize test goes with the function. The design's sizing wording
follows.

Sminos-Session: web-fetch-plugin#700c5e84 (doperpowers on macbook)
@SSFSKIM
SSFSKIM merged commit b0b4005 into main Oct 25, 2026
6 checks passed
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