Better HTML5Zip thumbnail generation
The studio code has a much better way to generate thumbnails from zip files with web content: load the index.html in a headless browser and take a screenshot. See https://github.com/learningequality/studio/blob/f57e27a8898faecd99f4d4d97109cb50eab7e74a/contentcuration/contentcuration/utils/files.py#L342-L407
We should use this approach for create_image_from_zip, but not implemented with PhantomJS.
Waiting on https://github.com/learningequality/ricecooker/issues/176 to be fixed first so we can use the same tooling.
Hi @ivanistheone We can improve HTML5 ZIP thumbnail generation by replacing PhantomJS with a headless browser like Playwright. The approach would be: Extract the ZIP file Locate index.html Open it using Playwright (file:// URL) Capture a screenshot and use it as the thumbnail
Triage: blocked on a premise mismatch with #691
This issue asks to render an archive's entry point and capture a viewport screenshot, reusing "the headless Chromium capability from #691." On investigation, #691 (merged as PR #697) doesn't provide a screenshot primitive:
- What #691 actually shipped is
ricecooker/utils/singlefile.py::render_page(url, output_dir)— a wrapper aroundsingle-file-clithat saves a URL into a self-contained HTML file.single-file-cli's job is HTML page-archiving, not image capture; it emits anindex.html, never a PNG. - There is no screenshot code anywhere on
main, andrender_pageexposes no reusable Chromium binary path (browser_executable_pathis an optional caller-supplied arg; it otherwise defers to single-file's own resolution).
So AC "No browser dependency beyond #691's headless Chromium is added" can't be met by reusing render_page as-is, and #691 hands us no Chromium handle to drive a screenshot ourselves.
Which direction do you want?
- Drive Chromium directly for the screenshot — resolve a
chromium/chromebinary (from PATH, or single-file's bundled one) and run--headless --screenshot=... --window-size=...on thefile://entry point. Reuses the environmental Chromium #691 implies, but is new code, not a reuse of #691's API, and needs a defined Chromium-detection/feature-gate story. - Add Playwright (as suggested above) purely for the render-and-screenshot path — cleanest API, but adds a browser dependency, which the current AC forbids.
- Extend #691 first to expose a screenshot helper (and a discoverable Chromium path), then build #335 on top.
Option 1 seems closest to intent but conflicts with a literal reading of the "reuse #691" framing and the detection is unspecified. Could you confirm the intended mechanism (and whether the "no new browser dependency" AC still holds) before implementation?
I think option 1 seems simplest, and doesn't add a new dependency.
Plan: Generate HTML5-zip and KPUB thumbnails by rendering the archive's entry point in a headless Chromium and screenshotting it, falling back to the biggest-image heuristic when Chromium is absent.
- [ ] HTML entry-point resolver in
utils/zip.py - [ ] Chromium detection + render-and-screenshot in
utils/images.py - [ ] Wire render + Chromium-absent fallback into
ExtractedHTMLZipThumbnailFile - [ ] KPUB thumbnail wiring
@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly
How was this generated?
- Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
- Ran the project's full test suite and linter before committing
- For UI changes: captured live screenshots to verify rendering
- For backend changes: verified with example API/CLI output
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.