The headless browser for AI agents and web scraping
test: gate modern hydration contracts
SGavrld36809058f49
diff --git a/render-repros/capture_chromium.py b/render-repros/capture_chromium.pynew file mode 100644index 00000000..51957ae0--- /dev/null+++ b/render-repros/capture_chromium.py@@ -0,0 +1,54 @@+#!/usr/bin/env python3+"""Capture one deterministic Chromium reference with Playwright."""++import argparse+import json+from pathlib import Path++from playwright.sync_api import sync_playwright+++def main():+ parser = argparse.ArgumentParser()+ parser.add_argument("url")+ parser.add_argument("output", type=Path)+ parser.add_argument("--width", type=int, default=900)+ parser.add_argument("--height", type=int, default=1000)+ parser.add_argument("--settle-ms", type=int, default=2000)+ parser.add_argument("--executable")+ args = parser.parse_args()++ launch = {"headless": True}+ if args.executable:+ launch["executable_path"] = args.executable++ with sync_playwright() as playwright:+ browser = playwright.chromium.launch(**launch)+ context = browser.new_context(+ viewport={"width": args.width, "height": args.height},+ device_scale_factor=1,+ locale="en-US",+ timezone_id="UTC",+ color_scheme="light",+ )+ page = context.new_page()+ page.goto(args.url, wait_until="load", timeout=30_000)+ page.wait_for_timeout(args.settle_ms)+ page.screenshot(path=str(args.output))+ print(+ json.dumps(+ {+ "browser": "chromium",+ "version": browser.version,+ "viewport": [args.width, args.height],+ "device_scale_factor": 1,+ "settle_ms": args.settle_ms,+ }+ )+ )+ context.close()+ browser.close()+++if __name__ == "__main__":+ main()diff --git a/render-repros/checks.json b/render-repros/checks.jsonindex da917fd0..b31d4e21 100644--- a/render-repros/checks.json+++ b/render-repros/checks.json@@ -25,6 +25,12 @@"mixed-content-block": [{"name": "full-width block child", "color": "#ccddff", "width": 400}],+ "modern-hydration-contracts": [+ {"name": "modern hydration contracts", "color": "#16803c", "width": 360, "height": 90}+ ],+ "modern-streams": [+ {"name": "streamed hydration contracts", "color": "#186aa5", "width": 360, "height": 90}+ ],"tables": [{"name": "content-box fixed cell column", "color": "#ffcc99", "width": 208}],diff --git a/render-repros/modern-hydration-contracts.html b/render-repros/modern-hydration-contracts.htmlnew file mode 100644index 00000000..fcb8f573--- /dev/null+++ b/render-repros/modern-hydration-contracts.html@@ -0,0 +1,72 @@+<!doctype html>+<html lang="en">+<head>+ <meta charset="utf-8">+ <title>Modern hydration DOM contracts</title>+ <style>+ html, body { margin: 0; padding: 0; }+ body { padding: 24px; font: 16px sans-serif; }+ #result {+ box-sizing: border-box;+ width: 360px;+ height: 90px;+ padding: 20px;+ background: #aa3333;+ color: white;+ }+ #result.passed { background: #16803c; }+ </style>+</head>+<body>+ <main id="server-shell">+ <div id="result">hydration contracts failed</div>+ </main>+ <script>+ globalThis.__parserScriptRuns = (globalThis.__parserScriptRuns || 0) + 1;++ // React 19 removes singleton attributes through one retained+ // NamedNodeMap. Its length and numeric entries must remain live.+ const probe = document.createElement("div");+ probe.setAttribute("id", "probe");+ probe.setAttribute("class", "card");+ probe.setAttribute("data-state", "server");+ const attributes = probe.attributes;+ let removed = 0;+ while (attributes.length && removed < 10) {+ probe.removeAttributeNode(attributes[0]);+ removed++;+ }++ // Modern ref callbacks call element.scrollTo({left, top, behavior}).+ const scroller = document.createElement("div");+ scroller.setAttribute("style", "position:absolute;left:-1000px;width:10px;height:10px;overflow:scroll");+ const scrollContent = document.createElement("div");+ scrollContent.setAttribute("style", "width:100px;height:100px");+ scroller.appendChild(scrollContent);+ document.body.appendChild(scroller);+ scroller.scrollTo({left: 12, top: 20, behavior: "auto"});+ scroller.scrollBy(3, -5);++ // Framework hydration may hoist or reorder an existing parser script.+ // Moving it must not execute it again.+ const parserScript = document.currentScript;+ if (globalThis.__parserScriptRuns === 1) document.head.appendChild(parserScript);++ const passed =+ globalThis.__parserScriptRuns === 1 &&+ attributes instanceof NamedNodeMap &&+ attributes === probe.attributes &&+ removed === 3 &&+ attributes.length === 0 &&+ !probe.hasAttributes() &&+ scroller.scrollLeft === 15 &&+ scroller.scrollTop === 15 &&+ document.getElementById("server-shell") !== null;++ const result = document.getElementById("result");+ result.textContent = passed ? "hydration contracts passed" : "hydration contracts failed";+ result.className = passed ? "passed" : "";+ globalThis.__modernHydrationContracts = passed;+ </script>+</body>+</html>diff --git a/render-repros/modern-streams.html b/render-repros/modern-streams.htmlnew file mode 100644index 00000000..9785c232--- /dev/null+++ b/render-repros/modern-streams.html@@ -0,0 +1,56 @@+<!doctype html>+<html lang="en">+<head>+ <meta charset="utf-8">+ <title>Modern hydration streams</title>+ <style>+ html, body { margin: 0; padding: 0; }+ body { padding: 24px; font: 16px sans-serif; }+ #result {+ box-sizing: border-box;+ width: 360px;+ height: 90px;+ padding: 20px;+ background: #aa3333;+ color: white;+ }+ #result.passed { background: #186aa5; }+ </style>+</head>+<body>+ <div id="result">streamed hydration failed</div>+ <script>+ const hydration = {};+ hydration.stream = new ReadableStream({+ start(controller) { hydration.controller = controller; }+ }).pipeThrough(new TextEncoderStream());+ hydration.controller.enqueue('["server",{"hydrated":true}]\n');+ hydration.controller.close();++ (async () => {+ const decoder = new TextDecoder();+ let tail = "";+ const lines = hydration.stream.pipeThrough(new TransformStream({+ transform(chunk, controller) {+ const complete = (tail + decoder.decode(chunk, {stream: true})).split("\n");+ tail = complete.pop() || "";+ for (const line of complete) controller.enqueue(line);+ },+ flush(controller) { if (tail) controller.enqueue(tail); }+ }));+ const first = await lines.getReader().read();+ const parsed = JSON.parse(first.value);+ const passed =+ !first.done &&+ parsed[0] === "server" &&+ parsed[1].hydrated === true;+ const result = document.getElementById("result");+ result.textContent = passed ? "streamed hydration passed" : "streamed hydration failed";+ result.className = passed ? "passed" : "";+ globalThis.__modernStreamContracts = passed;+ })().catch((error) => {+ globalThis.__modernStreamError = String(error);+ });+ </script>+</body>+</html>diff --git a/render-repros/run.sh b/render-repros/run.shindex 77041247..21f6fd13 100755--- a/render-repros/run.sh+++ b/render-repros/run.sh@@ -4,13 +4,11 @@set -uo pipefailROOT="$(cd "$(dirname "$0")/.." && pwd)"BIN="${OBSCURA_BIN:-$ROOT/target/release/obscura}"-CHROME="${CHROME_BIN:-chromium}"+CHROME="${CHROME_BIN:-}"PYTHON="${PYTHON_BIN:-python3}"DIR="$(cd "$(dirname "$0")" && pwd)"OUT="${1:-$DIR/out}"mkdir -p "$OUT"-STAGE="$(mktemp -d "$ROOT/.render-repros-chrome.XXXXXX")"-trap 'rm -rf -- "$STAGE"' EXITstatus=0for f in "$DIR"/*.html; don=$(basename "$f" .html)@@ -22,19 +20,16 @@ for f in "$DIR"/*.html; docontinuefi- # Chromium's snap package has a private /tmp, so stage under the checkout- # and move the completed screenshot into OUT. A fresh profile prevents an- # existing browser process from capturing the command and masking failure.- chrome_shot="$STAGE/$n.png"- if ! timeout 60 "$CHROME" --headless --disable-gpu --no-sandbox --hide-scrollbars \- --disable-background-networking --user-data-dir="$STAGE/$n-profile" \- --virtual-time-budget=2000 --force-device-scale-factor=1 --window-size=900,1000 \- --screenshot="$chrome_shot" "file://$f" >"$OUT/$n.chrome.log" 2>&1 || [[ ! -s "$chrome_shot" ]]; then+ chrome_args=("$DIR/capture_chromium.py" "file://$f" "$OUT/$n.chrome.png")+ if [[ -n "$CHROME" ]]; then+ chrome_args+=(--executable "$CHROME")+ fi+ if ! PYTHONDONTWRITEBYTECODE=1 timeout 60 "$PYTHON" "${chrome_args[@]}" \+ >"$OUT/$n.chrome.log" 2>&1 || [[ ! -s "$OUT/$n.chrome.png" ]]; thenecho "FAILED chromium: $n (see $OUT/$n.chrome.log)" >&2status=1continuefi- mv "$chrome_shot" "$OUT/$n.chrome.png"echo "rendered $n"doneif [[ "$status" -eq 0 ]]; then