laywill / laywill/laywill.github.io

refactor: share one headless-Chrome helper between check-render and build-og-card

Open
#171 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ci infra
Dominant language
HTML
Stars
0
Forks
0
Avg merge
8h 17m
Merged PRs (30d)
58

Description

Branch off master and PR into master, not main. This is the v1 site.

scripts/build-og-card.mjs (#130) needs headless Chrome for exactly the same reasons scripts/check-render.mjs does, and it now carries its own copy of the same four pieces of plumbing:

  • findChrome() — the CHROME_PATH override and the per-platform install locations
  • launchChrome() — the flag set, and scraping the DevTools URL out of stderr
  • stopChrome() — waiting for the exit rather than the signal, because Windows keeps the user-data-dir locked until Chrome has gone
  • connect() / withTimeout() — the minimal CDP client over one browser-level socket

The card builder's copy is the smaller of the two: it drives one page, so it drops the event waitFor and the per-target session bookkeeping check-render needs. Nothing about the Chrome handling itself differs.

This is the shape #162 was about. There, check-canonicals and check-render had a static.yml allowlist parser each, and they had already drifted in a way that mattered: the render check read only the first cp ... _site/, so a page added in a later cp deployed but was never rendered. One parser in scripts/static-allowlist.mjs fixed it. The same argument applies here before these two copies drift — a fix to Chrome discovery, or a new flag needed for a future Chrome, currently has to be made twice, and only one of the two runs in CI, so the other can rot unnoticed.

Not urgent: the copies are identical today, and build-og-card.mjs is a manual tool run rarely rather than a check. Filed so it is a decision rather than an accident.

Proposal

Extract the shared parts into scripts/chrome.mjs, alongside scripts/static-allowlist.mjs, and have both scripts import it. check-render.mjs keeps whatever is genuinely specific to rendering every page (the viewport list, the is-loading and image-ratio measurement, the page loop).

Worth deciding as part of it: whether PAGE_TIMEOUT_MS belongs to the module or stays per-caller, since the two have no reason to agree.

Acceptance criteria

  • One copy of Chrome discovery, launch, shutdown and the CDP client
  • npm run check-render behaves identically — same failures on a broken image, a distorted aspect ratio and a stuck is-loading
  • npm run og-card still produces a byte-comparable card
  • Neither script reaches into the other

Refs #130, #162

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Read scripts/check-render.mjs and scripts/build-og-card.mjs, then compare their Chrome discovery, launch, shutdown, and CDP client code. Extract the shared parts into scripts/chrome.mjs while leaving rendering-specific behavior and the callers' PAGE_TIMEOUT_MS decisions in place. Run npm run check-render and npm run og-card; done means the render failures remain identical and the card remains byte-comparable.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
tooling
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.