Skip to content

Add a script to conveniently compare screenshots on this site#2136

Open
dscho wants to merge 11 commits intogit:gh-pagesfrom
dscho:compare-screenshots
Open

Add a script to conveniently compare screenshots on this site#2136
dscho wants to merge 11 commits intogit:gh-pagesfrom
dscho:compare-screenshots

Conversation

@dscho
Copy link
Member

@dscho dscho commented Feb 17, 2026

Changes

  • Adds a Node.JS script to generate screenshots, mainly to support opening PRs.

Context

In PRs like #2133, it is good to accompany the code changes and the explanation (including rationale!) with a before/after comparison. This is oddly involved at the moment!

Historically, I used to whip out my trusty interactive 🪟ShiftS screenshot shortcut, and kind of aimed to catch the same areas before and after making my change. Then, I pasted them into the PR description and surrounded them by Markdown table markup. Quite tedious, if I'm honest!

So here's a script that automates a lot of that. It can even be used to re-build the site locally from two given revisions, and then take snapshots of those pages, using Playwright. It also allows to clip the areas to capture via specifying pixel values, which is admittedly not that convenient, but I couldn't find a better way.

The output is a copy/paste'able bit of Markdown/HTML with the images' absolute paths inserted: There is no API to upload images to GitHub PRs, and therefore they have to be uploaded manually. At least this way, the user can copy the entire Markdown, paste it into the PR description editor, then cut the first path to the clipboard, click the "Paste, drop, or click to add files" button below the editor, paste the path, then repeat with the second path.

This is precisely what I did over in #2133, with the tell-tale <!-- Generated by 'node compare-screenshots.js --clip=256x256+900+0 https://git-scm.com/about https://dscho.github.io/git-scm.com/about' --> comment in the PR body (can be seen here: https://api.github.com/repos/git/git-scm.com/pulls/2133).

dscho added 11 commits February 17, 2026 13:39
This is a script (developed using Claude Opus' assistance) which uses
Playwright to generate before/after screenshots.

Its functionality is quite basic for now.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Thanks, Claude Opus!

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Extract the duplicated screenshot logic into a takeScreenshot() function
to prepare for adding more screenshot options.

Assisted-by: Claude Opus 4.5
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This allows clipping the screenshots to a specified region using the
ImageMagick-style geometry format WxH+X+Y. The viewport is automatically
expanded to accommodate the clip region, and the output now includes
both the clip dimensions and the full page dimensions.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
When a path to a git-scm.com worktree is given instead of a URL, the
script now automatically builds the site with Hugo and starts a local
server to serve it. The server is torn down immediately after taking
the screenshot.

Due to indentation changes, this commit is best viewed with `-w`.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Allow specifying a specific page to navigate to when using a worktree
by appending a colon and the page path, e.g. /path/to/worktree:/docs/git-config

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Allow specifying a commit to checkout before building by appending
@commit to the worktree path, e.g. .@Head~2 or /path/to/worktree@main.
The original branch or detached HEAD state is restored after taking
the screenshot.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
As a convenience, @Head~2 is now equivalent to .@Head~2, meaning
the current directory will be used as the worktree.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Treat @{u} as equivalent to @@{u} since refs cannot start with a
curly brace. This allows conveniently comparing the upstream branch
against the current worktree.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
When the first argument specifies a page path (either via URL or
worktree:/path syntax), the second argument will automatically
use the same page path if none is specified.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
After taking screenshots, output an HTML table template that can be
copied into a PR comment. The absolute paths serve as placeholders
that can be selected and replaced by uploading the images.

The paths are placed on their own lines so that users can easily
triple-click to select the entire path, copy it, and then paste
the uploaded image URL in its place.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho dscho self-assigned this Feb 17, 2026
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

Comments