Skip to content

Robust Chrome rendering: persistent session, deterministic font wait, data: URLs - #26

Merged
milkway merged 2 commits into
mainfrom
feat/chrome-robustness
Jul 26, 2026
Merged

Robust Chrome rendering: persistent session, deterministic font wait, data: URLs#26
milkway merged 2 commits into
mainfrom
feat/chrome-robustness

Conversation

@milkway

@milkway milkway commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Reworks the chromote-based conversion pipeline (svg_to_png_chrome(), svg_to_pdf_chrome(), batch_svg_to_*_chrome()) with robustness patterns from production HTML→PDF services:

Changes

  • Deterministic readiness wait — conversions await the page load event and document.fonts.ready instead of a fixed Sys.sleep(). Captures never happen before web fonts render, and no time is wasted over-waiting. New timeout argument (default 10s); load_wait now means extra wait after readiness and defaults to 0.
  • Persistent Chrome session — a single health-checked ChromoteSession is reused across calls and replaced transparently when dead (self-healing), removing the ~1–2s startup per conversion. Closed in .onUnload.
  • No temp files — pages load via data: URLs (temp file fallback only for very large documents), avoiding file:// path/permission issues on Windows.
  • Real alpha transparencybackground = "transparent" now yields a PNG with a true alpha channel.

Validation

  • Smoke-tested locally: PNG/PDF output byte-identical across repeated conversions, Jost rendered correctly, vector PDF with text layer, batch 10/10, self-heal after killed session.
  • Warm conversions: ~0.7s vs ~2.4s cold (session reuse).
  • New tests/testthat/test-chrome.R (pure helpers everywhere; rendering tests skip_on_cran()). Suite: 102 passing.
  • R CMD check --as-cran: 0 errors, 0 warnings, 0 notes.

Part of the 0.2.5 CRAN submission.

🤖 Generated with Claude Code

milkway and others added 2 commits July 26, 2026 19:08
… wait, data: URLs)

Rework the chromote-based conversion pipeline inspired by production
HTML-to-PDF services:

- Deterministic readiness: wait for the page load event and
  document.fonts.ready instead of fixed Sys.sleep() calls, so captures
  never happen before web fonts render and never over-wait. New `timeout`
  argument (default 10s); `load_wait` now means extra wait after
  readiness and defaults to 0.
- Persistent Chrome session: a single health-checked ChromoteSession is
  reused across calls and replaced transparently when dead, removing the
  ~1-2s session startup per conversion. Closed in .onUnload.
- No temp files: pages load via data: URLs (temp file only for very
  large documents), avoiding file:// path issues on Windows.
- Real alpha transparency: background = "transparent" now yields a PNG
  with a true alpha channel via Emulation.setDefaultBackgroundColorOverride.

Adds tests for the new helpers (Chrome tests skipped on CRAN).
R CMD check --as-cran: 0 errors, 0 warnings, 0 notes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The wrapper HTML declares charset=utf-8, so the base64-encoded bytes
must be UTF-8 regardless of the session's native encoding (relevant on
Windows with R < 4.2).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@milkway
milkway merged commit 8f80914 into main Jul 26, 2026
@milkway
milkway deleted the feat/chrome-robustness branch July 26, 2026 22:27
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