web/screenshot.py
Capture a full-page PNG screenshot of a webpage (headless Chromium via Playwright). Pass headers=<json object> to send extra request headers. settle_ms (default 2000) is an extra wait after page load, for pages whose real content only appears after their own async JS runs.
Use when the user wants a picture of a rendered page, or a visual check of a URL rather than its text.
- the file
- web/screenshot.py
- its skill
- web/SKILL.md (the whole web pack)
- as knowledge
- okf/web/screenshot.md
- on GitHub
- web/screenshot.py ↗
Run it
1. Once per machine: install fragletc (Docker must already be running).
curl -fsSL https://raw.githubusercontent.com/ofthemachine/fraglet/main/install.sh | sh
2. Fetch the tool and print its contract.
curl -fsSLO https://tools.ofthemachine.com/web/screenshot.py && chmod +x screenshot.py && ./screenshot.py --fraglet-help
3. Run it.
./screenshot.py -p url="<url>" [-p headers="<headers>"] [-p settle_ms=2000] --output page.png
Parameters
| name | type | requirement | description |
|---|---|---|---|
| url | string | required | Page URL to capture |
| headers | string | optional | JSON object of extra non-secret HTTP headers (e.g. Accept-Language); recorded in plaintext in receipts, so never credentials |
| settle_ms | string | default 2000 | Extra wait after page load for async JS content |
Outputs
page.png
Provenance
- image
- ofthemachine/headless-browser@sha256:f79c496c6737113c0f6e2d648474a67fb1a416fa34c22220d5714d0b7c6a6036
- reach
network=required— output depends on live external state; do not cache indefinitely.- procedure_hash
- sha256:6f4177a6b183d233a0f6f9ba331b1df9983af8df7f0d6d13e704fbbcab146588
- receipt
- add
--receipt run.jsonto any run;receipt/attest.pyverifies it against this hash without re-running.
Source
screenshot.py · 43 lines · sha256 6f4177a6b183…
#!/usr/bin/env -S fragletc --image ofthemachine/headless-browser@sha256:f79c496c6737113c0f6e2d648474a67fb1a416fa34c22220d5714d0b7c6a6036
#: d=Capture a full-page PNG screenshot of a webpage (headless Chromium via Playwright). Pass headers=<json object> to send extra request headers. settle_ms (default 2000) is an extra wait after page load, for pages whose real content only appears after their own async JS runs.
#: when=Use when the user wants a picture of a rendered page, or a visual check of a URL rather than its text.
#: network=required
#: stdin=none
#: param=url:required:d=Page URL to capture
#: param=headers:d=JSON object of extra non-secret HTTP headers (e.g. Accept-Language); recorded in plaintext in receipts, so never credentials
#: param=settle_ms:default=2000:description=Extra wait after page load for async JS content
#: output=page.png
import json
import os
import sys
from playwright.sync_api import sync_playwright
url = os.environ["URL"]
headers_raw = os.environ.get("HEADERS", "")
settle_ms = int(os.environ["SETTLE_MS"])
headers = {}
if headers_raw:
try:
headers = json.loads(headers_raw)
except json.JSONDecodeError as e:
print(f"headers param is not valid JSON: {e}", file=sys.stderr)
sys.exit(1)
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
context = browser.new_context(viewport={"width": 1280, "height": 800}, extra_http_headers=headers)
page = context.new_page()
try:
page.goto(url, wait_until="load", timeout=30_000)
if settle_ms > 0:
page.wait_for_timeout(settle_ms)
page.screenshot(path="/output/page.png", full_page=True)
except Exception as e:
print(f"screenshot failed: {e}", file=sys.stderr)
sys.exit(1)
finally:
browser.close()
print(f"Captured screenshot of {url} -> page.png")