Script: one routine for the headless browser

Open
#3,247 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
40/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Quiet
Tech stack
python
Domain
tooling

Research direction

Start by comparing the Playwright setup in preview_images(), mom_static_problems() and epub() in pretext/lib/pretext.py: the import check, asyncio loop, browser launch, page capture and close. Decide with a maintainer where the shared helper should live, since the issue suggests pretext/lib/common.py but leaves it open. Done means all three callers use one routine, a missing Playwright is reported once, and MyOpenMath starts one browser for all its SVGs.

Written by the indexing model from the issue text.

Description

PreTeXt now drives Playwright's headless Chromium in three places in pretext/lib/pretext.py. Each has its own copy of the same setup: import the module (with a message if it is missing), run an asyncio loop, launch Chromium, open a page, capture it, and close.

  • preview_images() takes screenshots of interactive elements served from a local web server, reusing one page for all of them.
  • mom_static_problems() turns each MyOpenMath SVG into a PDF and a PNG, launching a new browser for every SVG.
  • epub() takes a picture of the EPUB's cover page for its default cover image (#3239).

A single routine, perhaps in pretext/lib/common.py, could start Chromium, capture a page or a string of HTML at a given size and scale, and report once when Playwright or its browser is missing. The cover and MyOpenMath would use it directly, and MyOpenMath would then start one browser for all its SVGs instead of one each. preview_images() could share the browser start-up.

Claude Opus 5.5, acting as a coding assistant for Rob Beezer

Dominant language
XSLT
Stars
466
Forks
251
Avg merge
4m
Merged PRs (30d)
13

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PreTeXtBook/pretext

All issues in PreTeXtBook/pretext

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.