Created
March 27, 2026 14:30
-
-
Save hjanuschka/ecbedb65e14e49ecc3ea71df4a0e4b6f to your computer and use it in GitHub Desktop.
Render i-480978106 page screenshot on macOS with headless Chrome/Chromium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # Usage: | |
| # ./render_i480978106_macos.sh [page_path_or_url] [output_png] | |
| # | |
| # Examples: | |
| # ./render_i480978106_macos.sh | |
| # ./render_i480978106_macos.sh ~/my-host/static-files/i-480978106/index.html | |
| # ./render_i480978106_macos.sh https://static.januschka.com/i-480978106/ | |
| INPUT="${1:-$HOME/my-host/static-files/i-480978106/index.html}" | |
| OUT="${2:-$PWD/i-480978106-macos.png}" | |
| find_browser() { | |
| local candidates=( | |
| "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" | |
| "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary" | |
| "/Applications/Chromium.app/Contents/MacOS/Chromium" | |
| "$(command -v google-chrome 2>/dev/null || true)" | |
| "$(command -v chromium 2>/dev/null || true)" | |
| "$(command -v chromium-browser 2>/dev/null || true)" | |
| ) | |
| for b in "${candidates[@]}"; do | |
| if [[ -n "${b}" && -x "${b}" ]]; then | |
| echo "${b}" | |
| return 0 | |
| fi | |
| done | |
| return 1 | |
| } | |
| to_url() { | |
| local in="$1" | |
| if [[ "$in" =~ ^https?:// ]]; then | |
| echo "$in" | |
| return 0 | |
| fi | |
| if [[ "$in" =~ ^file:// ]]; then | |
| echo "$in" | |
| return 0 | |
| fi | |
| if [[ ! -e "$in" ]]; then | |
| echo "ERROR: file not found: $in" >&2 | |
| exit 1 | |
| fi | |
| python3 - "$in" <<'PY' | |
| import pathlib, sys, urllib.parse | |
| p = pathlib.Path(sys.argv[1]).expanduser().resolve() | |
| print("file://" + urllib.parse.quote(str(p))) | |
| PY | |
| } | |
| BROWSER="$(find_browser)" || { | |
| echo "ERROR: Could not find Chrome/Chromium on macOS." >&2 | |
| exit 1 | |
| } | |
| URL="$(to_url "$INPUT")" | |
| echo "Browser: $BROWSER" | |
| echo "URL: $URL" | |
| echo "Output: $OUT" | |
| "$BROWSER" \ | |
| --headless=new \ | |
| --disable-gpu \ | |
| --hide-scrollbars \ | |
| --window-size=1400,2600 \ | |
| --virtual-time-budget=5000 \ | |
| --run-all-compositor-stages-before-draw \ | |
| --screenshot="$OUT" \ | |
| "$URL" | |
| echo "Done: $OUT" | |
| # Auto-open on macOS (optional) | |
| open "$OUT" >/dev/null 2>&1 || true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment