#!/bin/bash # wi-read.sh v4 (2026-10-20 15:52 CST): a substring starting with "=" matches the URL exactly # Usage: [WIPID=PID:nnn] wi-read.sh [expr-file (default probe-wi.js)] [out.json] # Restarts ios_webkit_debug_proxy (it serves one inspector connection per page per run), picks the # first page whose URL contains the substring (optionally only in process WIPID), evaluates the # expression via wi-eval.mjs and prints/saves the JSON. With out.json it also writes # out.meta.json: read time, tool sha256s, the selected page, and the full inspectable-page list # (URLs not on openpwa.net and not about:blank are redacted to ""). set -u DIR="${DIR:-$(cd "$(dirname "$0")" && pwd)}"; UDID=${UDID:?set UDID to the device UDID (ideviceinfo -k UniqueDeviceID)} pkill -f ios_webkit_debug_proxy; sleep 1 (ios_webkit_debug_proxy -c $UDID:9222 -F > /tmp/iwdp.log 2>&1 &); sleep 4 LIST=$(curl -s localhost:9222/json) REDACTED=$(echo "$LIST" | jq '[.[] | {appId, page: (.webSocketDebuggerUrl | split("/") | last), title: (if (.url|test("^https://openpwa\\.net/|^about:blank|^safari-web-extension:")) then .title else "" end), url: (if (.url|test("^https://openpwa\\.net/|^about:blank|^safari-web-extension:")) then .url else "" end)}]') echo "$REDACTED" | jq -r '.[] | "\(.page) \(.appId) \(.url)"' >&2 SEL=$(echo "$LIST" | jq -c --arg s "$1" '[.[] | select((if ($s|startswith("=")) then (.url == ($s|ltrimstr("="))) else (.url | contains($s)) end) and ((env.WIPID // "") as $p | $p == "" or .appId == $p))][0] // empty') [ -z "$SEL" ] && { echo "no page matching $1 ${WIPID:-}" >&2; exit 3; } WS=$(echo "$SEL" | jq -r .webSocketDebuggerUrl) EXPR="${2:-$DIR/probe-wi.js}" STARTED=$(date -u +%Y-%m-%dT%H:%M:%SZ) OUT=$(node $DIR/wi-eval.mjs "$WS" "$EXPR") || { echo "eval failed: $OUT" >&2; exit 4; } if [ -n "${3:-}" ]; then echo "$OUT" | jq . > "$3" && echo "saved $3" >&2 jq -n --arg started "$STARTED" --arg local "$(date +%Y-%m-%dT%H:%M:%S%z)" --argjson sel "$(echo "$SEL" | jq '{appId, url, page: (.webSocketDebuggerUrl|split("/")|last)}')" \ --argjson pages "$REDACTED" --arg expr "$(basename "$EXPR")" \ --arg exprSha "$(shasum -a 256 "$EXPR" | cut -d' ' -f1)" --arg evalSha "$(shasum -a 256 $DIR/wi-eval.mjs | cut -d' ' -f1)" --arg readSha "$(shasum -a 256 "$0" | cut -d' ' -f1)" \ --arg iwdp "$(ios_webkit_debug_proxy --version 2>&1 | head -1)" \ '{readStartedUtc: $started, readLocal: $local, selected: $sel, expression: $expr, sha256: {expression: $exprSha, "wi-eval.mjs": $evalSha, "wi-read.sh": $readSha}, proxy: $iwdp, inspectablePages: $pages}' > "${3%.json}.meta.json" else echo "$OUT" | jq .; fi