remote-browser: generalise deck-browser to any device, add a setup workflow
deck-browser assumed one host. remote-browser takes a profile per device (transport ssh or direct, host, port, ws path, inspect URL) and gains 'profiles', 'setup' and 'check': check walks ssh -> port -> websocket handshake -> attach -> tabs and prints the first failure instead of a generic 'could not attach'. The skill ships references/setup.md, a checklist for onboarding a device with the user, including per-browser toggle URLs, the Chrome <136 fallback, and a symptom->cause table.
This commit is contained in:
1 parent
8999c687f9
commit
a21791c630
8 files changed
+466
-201
No files matched your search
@@ -1,142 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# deck-browser — read the Chrome running on the Steam Deck from arceus.
|
||||
#
|
||||
# Chrome on the Deck exposes a CDP WebSocket at 127.0.0.1:9222/devtools/browser once
|
||||
# "Allow remote debugging for this browser instance" is ticked at
|
||||
# chrome://inspect/#remote-debugging. Playwright attaches to a ws:// endpoint directly
|
||||
# (connectOverCDP accepts one), so this is a thin wrapper that opens the SSH tunnel and
|
||||
# drives `playwright-cli` — not a protocol client of its own.
|
||||
#
|
||||
# deck-browser tabs list tabs (index, title, url)
|
||||
# deck-browser text --match linkedin innerText of a tab
|
||||
# deck-browser html --index 3 outerHTML
|
||||
# deck-browser shot --out /tmp/x.png screenshot (default /tmp/deck-shot-<ts>.png)
|
||||
# deck-browser status user agent of the attached browser
|
||||
# deck-browser cli tab-select 2 pass any playwright-cli command through
|
||||
#
|
||||
# Options: --index N | --match SUBSTR (default: current tab), --limit CHARS (default 8000).
|
||||
# Read-only by intent: no click/type/navigate helper exists here, because driving an
|
||||
# authenticated session is what gets accounts restricted.
|
||||
#
|
||||
# Env: DECK_HOST (deck), DECK_CDP_PORT (9222), DECK_SESSION (deck)
|
||||
set -euo pipefail
|
||||
|
||||
HOST=${DECK_HOST:-deck}
|
||||
PORT=${DECK_CDP_PORT:-9222}
|
||||
SESSION=${DECK_SESSION:-deck}
|
||||
WS="ws://127.0.0.1:${PORT}/devtools/browser"
|
||||
|
||||
die() { echo "deck-browser: $*" >&2; exit 1; }
|
||||
|
||||
port_open() { (exec 3<>"/dev/tcp/127.0.0.1/${PORT}") 2>/dev/null; }
|
||||
|
||||
ensure_tunnel() {
|
||||
port_open && return 0
|
||||
ssh -o BatchMode=yes -o ExitOnForwardFailure=yes -f -N \
|
||||
-L "${PORT}:127.0.0.1:${PORT}" "$HOST" \
|
||||
|| die "cannot open tunnel to ${HOST} — is the Deck awake?"
|
||||
for _ in $(seq 1 25); do port_open && return 0; sleep 0.2; done
|
||||
die "no CDP endpoint on 127.0.0.1:${PORT}.
|
||||
On the Deck: chrome://inspect/#remote-debugging → tick
|
||||
'Allow remote debugging for this browser instance', then retry."
|
||||
}
|
||||
|
||||
ensure_attached() {
|
||||
ensure_tunnel
|
||||
playwright-cli -s="$SESSION" eval '1' >/dev/null 2>&1 && return 0
|
||||
playwright-cli -s="$SESSION" attach --cdp="$WS" >/dev/null 2>&1 \
|
||||
|| die "playwright-cli could not attach to ${WS} (is the box still ticked?)"
|
||||
}
|
||||
|
||||
# tab_list → "INDEX<TAB>TITLE<TAB>URL"
|
||||
tab_list() {
|
||||
playwright-cli -s="$SESSION" tab-list 2>/dev/null \
|
||||
| sed -n 's/^- \([0-9]\+\): \(.*\)\[\(.*\)\](\(.*\))$/\1\t\3\t\4/p'
|
||||
}
|
||||
|
||||
resolve_tab() { # args: --index N | --match SUBSTR
|
||||
local idx="" match=""
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--index) idx=${2:-}; shift 2 ;;
|
||||
--match) match=${2:-}; shift 2 ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
done
|
||||
if [ -n "$match" ]; then
|
||||
idx=$(tab_list | awk -F'\t' -v m="$(echo "$match" | tr 'A-Z' 'a-z')" \
|
||||
'tolower($0) ~ m {print $1; exit}')
|
||||
[ -n "$idx" ] || die "no tab matching '$match'"
|
||||
fi
|
||||
printf '%s' "${idx:-}"
|
||||
}
|
||||
|
||||
# json_unquote turns playwright's JSON-quoted eval result into plain text.
|
||||
json_unquote() {
|
||||
python3 -c '
|
||||
import json, sys
|
||||
for line in sys.stdin.read().splitlines():
|
||||
line = line.strip()
|
||||
if line[:1] == chr(34) and line[-1:] == chr(34):
|
||||
try:
|
||||
sys.stdout.write(json.loads(line)); break
|
||||
except Exception:
|
||||
pass
|
||||
'
|
||||
}
|
||||
|
||||
OPTS=()
|
||||
for a in "$@"; do :; done
|
||||
CMD=${1:-}; shift || true
|
||||
|
||||
case "$CMD" in
|
||||
tabs)
|
||||
ensure_attached
|
||||
tab_list | awk -F'\t' '{printf "%2s %-52s %s\n", $1, substr($2,1,52), $3}'
|
||||
;;
|
||||
status)
|
||||
ensure_attached
|
||||
playwright-cli -s="$SESSION" eval 'navigator.userAgent' | json_unquote
|
||||
;;
|
||||
text|html)
|
||||
LIMIT=8000
|
||||
args=()
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--limit) LIMIT=${2:-8000}; shift 2 ;;
|
||||
*) args+=("$1"); shift ;;
|
||||
esac
|
||||
done
|
||||
ensure_attached
|
||||
idx=$(resolve_tab ${args+"${args[@]}"})
|
||||
[ -n "$idx" ] && playwright-cli -s="$SESSION" tab-select "$idx" >/dev/null
|
||||
if [ "$CMD" = text ]; then expr='document.body.innerText'; else expr='document.documentElement.outerHTML'; fi
|
||||
out=$(playwright-cli -s="$SESSION" eval "$expr" | json_unquote)
|
||||
printf '%s' "$out" | head -c "$LIMIT"
|
||||
[ "${#out}" -gt "$LIMIT" ] && printf '\n[deck-browser: truncated %s more characters]\n' "$(( ${#out} - LIMIT ))"
|
||||
echo
|
||||
;;
|
||||
shot)
|
||||
out=/tmp/deck-shot-$(date +%s).png
|
||||
args=()
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--out) out=${2:-$out}; shift 2 ;;
|
||||
*) args+=("$1"); shift ;;
|
||||
esac
|
||||
done
|
||||
ensure_attached
|
||||
idx=$(resolve_tab ${args+"${args[@]}"})
|
||||
[ -n "$idx" ] && playwright-cli -s="$SESSION" tab-select "$idx" >/dev/null
|
||||
playwright-cli -s="$SESSION" screenshot --filename="$out" >/dev/null
|
||||
echo "$out"
|
||||
;;
|
||||
cli)
|
||||
ensure_attached
|
||||
playwright-cli -s="$SESSION" "$@"
|
||||
;;
|
||||
*)
|
||||
sed -n '2,22p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Executable
+321
@@ -0,0 +1,321 @@
|
||||
#!/usr/bin/env bash
|
||||
# remote-browser — read a Chromium browser running on another machine, over CDP.
|
||||
#
|
||||
# Works for any host the agent can reach (an SSH alias, or a direct address) whose
|
||||
# browser exposes a CDP endpoint. Chrome-family browsers expose one when the user ticks
|
||||
# chrome://inspect/#remote-debugging → "Allow remote debugging for this browser instance"
|
||||
# which serves ONLY ws://127.0.0.1:<port>/devtools/browser (HTTP /json/* returns 403).
|
||||
# Playwright attaches to a ws:// endpoint directly, so this is a thin wrapper that opens
|
||||
# the tunnel and drives `playwright-cli`. Setup for a new device: see references/setup.md
|
||||
# in the remote-browser skill, and run `remote-browser check`.
|
||||
#
|
||||
# remote-browser profiles list configured devices
|
||||
# remote-browser setup --name deck --host deck [--port 9222] [--transport ssh]
|
||||
# remote-browser check [--profile deck] step-by-step readiness test
|
||||
# remote-browser tabs | status | text | html | shot
|
||||
# remote-browser cli <playwright-cli args> anything not wrapped (console, requests…)
|
||||
#
|
||||
# Options: --profile/-p NAME, --index N, --match SUBSTR, --limit CHARS, --out FILE.
|
||||
# Read-only by intent: no click/type/navigate helper exists, because driving an
|
||||
# authenticated session is what gets accounts restricted.
|
||||
#
|
||||
# Env: REMOTE_BROWSER_PROFILE (default profile), REMOTE_BROWSER_DIR (config dir).
|
||||
set -euo pipefail
|
||||
|
||||
CONF_DIR=${REMOTE_BROWSER_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/remote-browser}
|
||||
PROFILE_DIR="$CONF_DIR/profiles"
|
||||
PN=$(basename "$0")
|
||||
|
||||
die() { echo "$PN: $*" >&2; exit 1; }
|
||||
info() { echo " $*" >&2; }
|
||||
|
||||
usage() { sed -n '2,24p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; }
|
||||
|
||||
# --- argument parsing ---------------------------------------------------------
|
||||
|
||||
PROFILE=${REMOTE_BROWSER_PROFILE:-}
|
||||
CMD=""
|
||||
ARGS=()
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--profile|-p) PROFILE=${2:-}; shift 2 ;;
|
||||
-h|--help) usage; exit 0 ;;
|
||||
*) if [ -z "$CMD" ]; then CMD=$1; else ARGS+=("$1"); fi; shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# --- profiles -----------------------------------------------------------------
|
||||
|
||||
profile_file() { echo "$PROFILE_DIR/$1.env"; }
|
||||
|
||||
load_profile() {
|
||||
[ -n "$PROFILE" ] || die "no profile given (use --profile NAME, or set REMOTE_BROWSER_PROFILE). Try: $PN profiles"
|
||||
local f; f=$(profile_file "$PROFILE")
|
||||
[ -f "$f" ] || die "unknown profile '$PROFILE' ($f missing). Try: $PN profiles"
|
||||
# shellcheck disable=SC1090
|
||||
. "$f"
|
||||
: "${RB_HOST:?profile $f has no RB_HOST}"
|
||||
RB_PORT=${RB_PORT:-9222}
|
||||
RB_TRANSPORT=${RB_TRANSPORT:-ssh}
|
||||
RB_WS_PATH=${RB_WS_PATH:-/devtools/browser}
|
||||
RB_INSPECT_URL=${RB_INSPECT_URL:-chrome://inspect/#remote-debugging}
|
||||
SESSION="rb-$PROFILE"
|
||||
if [ "$RB_TRANSPORT" = ssh ]; then
|
||||
WS="ws://127.0.0.1:${RB_PORT}${RB_WS_PATH}"
|
||||
else
|
||||
WS="ws://${RB_HOST}:${RB_PORT}${RB_WS_PATH}"
|
||||
fi
|
||||
}
|
||||
|
||||
list_profiles() {
|
||||
[ -d "$PROFILE_DIR" ] || { echo "no profiles yet — create one with: $PN setup --name <name> --host <host>"; return 0; }
|
||||
shopt -s nullglob
|
||||
local found=0 f
|
||||
for f in "$PROFILE_DIR"/*.env; do
|
||||
found=1
|
||||
( . "$f"
|
||||
printf '%-12s %-6s %-24s %s:%s\n' \
|
||||
"$(basename "$f" .env)" "${RB_TRANSPORT:-ssh}" "${RB_HOST:-?}" "${RB_HOST:-?}" "${RB_PORT:-9222}" )
|
||||
done
|
||||
[ $found -eq 1 ] || echo "no profiles yet — create one with: $PN setup --name <name> --host <host>"
|
||||
}
|
||||
|
||||
# --- transport ----------------------------------------------------------------
|
||||
|
||||
port_open() { (exec 3<>"/dev/tcp/${1}/${2}") 2>/dev/null; }
|
||||
|
||||
host_reachable() {
|
||||
case "$RB_TRANSPORT" in
|
||||
ssh) ssh -o BatchMode=yes -o ConnectTimeout=6 "$RB_HOST" true >/dev/null 2>&1 ;;
|
||||
direct) port_open "$RB_HOST" "$RB_PORT" ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
ensure_tunnel() {
|
||||
if [ "$RB_TRANSPORT" = direct ]; then
|
||||
port_open "$RB_HOST" "$RB_PORT" || die "cannot reach ${RB_HOST}:${RB_PORT} (transport=direct)"
|
||||
return 0
|
||||
fi
|
||||
port_open 127.0.0.1 "$RB_PORT" && return 0
|
||||
ssh -o BatchMode=yes -o ExitOnForwardFailure=yes -f -N \
|
||||
-L "${RB_PORT}:127.0.0.1:${RB_PORT}" "$RB_HOST" 2>/dev/null \
|
||||
|| die "cannot open SSH tunnel to ${RB_HOST} — is it awake and is your key authorised?"
|
||||
for _ in $(seq 1 25); do port_open 127.0.0.1 "$RB_PORT" && return 0; sleep 0.2; done
|
||||
die "tunnel up but nothing listening on 127.0.0.1:${RB_PORT}.
|
||||
On ${RB_HOST}, open ${RB_INSPECT_URL} and tick
|
||||
'Allow remote debugging for this browser instance', then retry."
|
||||
}
|
||||
|
||||
ws_handshake() { # prints HTTP status line of a WS upgrade attempt
|
||||
python3 - "${1}" <<'PY' 2>/dev/null || echo "no-response"
|
||||
import base64, os, socket, sys, urllib.parse as up
|
||||
url = up.urlparse(sys.argv[1])
|
||||
s = socket.create_connection((url.hostname, url.port or 80), timeout=5)
|
||||
key = base64.b64encode(os.urandom(16)).decode()
|
||||
s.sendall((f"GET {url.path or '/'} HTTP/1.1\r\nHost: {url.hostname}:{url.port}\r\n"
|
||||
"Upgrade: websocket\r\nConnection: Upgrade\r\n"
|
||||
f"Sec-WebSocket-Key: {key}\r\nSec-WebSocket-Version: 13\r\n\r\n").encode())
|
||||
print(s.recv(256).decode(errors="replace").split("\r\n")[0].strip() or "no-response")
|
||||
s.close()
|
||||
PY
|
||||
}
|
||||
|
||||
ensure_attached() {
|
||||
ensure_tunnel
|
||||
playwright-cli -s="$SESSION" eval '1' >/dev/null 2>&1 && return 0
|
||||
playwright-cli -s="$SESSION" attach --cdp="$WS" >/dev/null 2>&1 \
|
||||
|| die "playwright-cli could not attach to ${WS}.
|
||||
On ${RB_HOST}: open ${RB_INSPECT_URL} and tick
|
||||
'Allow remote debugging for this browser instance'."
|
||||
}
|
||||
|
||||
# --- helpers ------------------------------------------------------------------
|
||||
|
||||
# tab_list → "INDEX<TAB>TITLE<TAB>URL"
|
||||
tab_list() {
|
||||
playwright-cli -s="$SESSION" tab-list 2>/dev/null \
|
||||
| sed -n 's/^- \([0-9]\+\): \(.*\)\[\(.*\)\](\(.*\))$/\1\t\3\t\4/p'
|
||||
}
|
||||
|
||||
resolve_tab() {
|
||||
local idx="" match=""
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--index) idx=${2:-}; shift 2 ;;
|
||||
--match) match=${2:-}; shift 2 ;;
|
||||
*) shift ;;
|
||||
esac
|
||||
done
|
||||
if [ -n "$match" ]; then
|
||||
idx=$(tab_list | awk -F'\t' -v m="$(printf '%s' "$match" | tr 'A-Z' 'a-z')" \
|
||||
'tolower($0) ~ m {print $1; exit}')
|
||||
[ -n "$idx" ] || die "no tab matching '$match'"
|
||||
fi
|
||||
printf '%s' "${idx:-}"
|
||||
}
|
||||
|
||||
json_unquote() {
|
||||
python3 -c '
|
||||
import json, sys
|
||||
for line in sys.stdin.read().splitlines():
|
||||
line = line.strip()
|
||||
if line[:1] == chr(34) and line[-1:] == chr(34):
|
||||
try:
|
||||
sys.stdout.write(json.loads(line)); break
|
||||
except Exception:
|
||||
pass
|
||||
'
|
||||
}
|
||||
|
||||
# --- commands -----------------------------------------------------------------
|
||||
|
||||
cmd_setup() {
|
||||
local name="" host="" port=9222 transport=ssh path=/devtools/browser inspect=""
|
||||
local url_default
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--name) name=${2:-}; shift 2 ;;
|
||||
--host) host=${2:-}; shift 2 ;;
|
||||
--port) port=${2:-}; shift 2 ;;
|
||||
--transport) transport=${2:-}; shift 2 ;;
|
||||
--ws-path) path=${2:-}; shift 2 ;;
|
||||
--inspect-url) inspect=${2:-}; shift 2 ;;
|
||||
*) die "setup: unexpected argument '$1'" ;;
|
||||
esac
|
||||
done
|
||||
[ -n "$name" ] || die "setup: --name is required (a short label, e.g. deck, laptop)"
|
||||
[ -n "$host" ] || die "setup: --host is required (ssh alias or address)"
|
||||
case "$transport" in ssh|direct) ;; *) die "setup: --transport must be ssh or direct" ;; esac
|
||||
mkdir -p "$PROFILE_DIR"
|
||||
local f; f=$(profile_file "$name")
|
||||
if [ -f "$f" ]; then
|
||||
info "updating existing profile $name ($f)"
|
||||
fi
|
||||
cat > "$f" <<EOF
|
||||
# remote-browser profile created $(date -Iseconds) by \`$PN setup\`
|
||||
# transport=ssh forwards the remote loopback port to 127.0.0.1 locally.
|
||||
# transport=direct talks to RB_HOST:RB_PORT as-is (no tunnel).
|
||||
RB_TRANSPORT=$transport
|
||||
RB_HOST=$host
|
||||
RB_PORT=$port
|
||||
RB_WS_PATH=$path
|
||||
RB_INSPECT_URL=${inspect:-chrome://inspect/#remote-debugging}
|
||||
EOF
|
||||
chmod 600 "$f"
|
||||
echo "wrote $f"
|
||||
echo
|
||||
echo "Next: on $host, open ${inspect:-chrome://inspect/#remote-debugging} and tick"
|
||||
echo " 'Allow remote debugging for this browser instance', then run:"
|
||||
echo " $PN check --profile $name"
|
||||
}
|
||||
|
||||
cmd_check() {
|
||||
load_profile
|
||||
local failures=0
|
||||
say() { printf '%s %s\n' "$1" "$2"; }
|
||||
[ -n "$PROFILE" ] && printf 'profile: %s (transport=%s host=%s port=%s)\n\n' "$PROFILE" "$RB_TRANSPORT" "$RB_HOST" "$RB_PORT"
|
||||
|
||||
if [ "$RB_TRANSPORT" = ssh ]; then
|
||||
if ssh -o BatchMode=yes -o ConnectTimeout=6 "$RB_HOST" true >/dev/null 2>&1; then
|
||||
say "✓" "ssh to $RB_HOST works"
|
||||
else
|
||||
say "✗" "ssh to $RB_HOST failed — add an ssh config entry and key, or use --transport direct"
|
||||
failures=$((failures+1))
|
||||
fi
|
||||
fi
|
||||
|
||||
if ensure_tunnel 2>/dev/null; then
|
||||
say "✓" "cdp port reachable at $( [ "$RB_TRANSPORT" = ssh ] && echo "127.0.0.1:$RB_PORT via tunnel" || echo "$RB_HOST:$RB_PORT" )"
|
||||
else
|
||||
say "✗" "cdp port not reachable — is the browser running with remote debugging enabled?"
|
||||
say " " " on $RB_HOST: open $RB_INSPECT_URL and tick the box"
|
||||
failures=$((failures+1))
|
||||
fi
|
||||
|
||||
if [ $failures -eq 0 ]; then
|
||||
local status; status=$(ws_handshake "$WS")
|
||||
case "$status" in
|
||||
*" 101"*) say "✓" "websocket handshake on ${RB_WS_PATH} accepted" ;;
|
||||
*) say "✗" "websocket handshake returned '${status}'"
|
||||
say " " " expected 101; a 403/404 means the endpoint is not the CDP socket"
|
||||
failures=$((failures+1)) ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ $failures -eq 0 ] && ensure_attached 2>/dev/null; then
|
||||
say "✓" "playwright attached (session $SESSION)"
|
||||
local ua; ua=$(playwright-cli -s="$SESSION" eval 'navigator.userAgent' 2>/dev/null | json_unquote)
|
||||
say "✓" "browser: ${ua:-unknown}"
|
||||
local n; n=$(tab_list | wc -l)
|
||||
if [ "$n" -gt 0 ]; then
|
||||
say "✓" "$n tab(s) visible — try: $PN tabs --profile $PROFILE"
|
||||
else
|
||||
say "!" "attached but no tabs found (open a page in that browser)"
|
||||
fi
|
||||
elif [ $failures -eq 0 ]; then
|
||||
say "✗" "playwright could not attach to $WS"
|
||||
failures=$((failures+1))
|
||||
fi
|
||||
|
||||
echo
|
||||
if [ $failures -eq 0 ]; then
|
||||
echo "ready. Read-only commands: tabs, text, html, shot, status, cli."
|
||||
return 0
|
||||
fi
|
||||
echo "$failures check(s) failed."
|
||||
return 1
|
||||
}
|
||||
|
||||
case "$CMD" in
|
||||
""|-h|--help) usage; exit 0 ;;
|
||||
profiles) list_profiles ;;
|
||||
setup) cmd_setup "${ARGS[@]+"${ARGS[@]}"}" ;;
|
||||
check) cmd_check ;;
|
||||
tabs)
|
||||
load_profile; ensure_attached
|
||||
tab_list | awk -F'\t' '{printf "%2s %-52s %s\n", $1, substr($2,1,52), $3}'
|
||||
;;
|
||||
status)
|
||||
load_profile; ensure_attached
|
||||
playwright-cli -s="$SESSION" eval 'navigator.userAgent' | json_unquote
|
||||
;;
|
||||
text|html)
|
||||
LIMIT=8000; tabargs=()
|
||||
while [ ${#ARGS[@]} -gt 0 ]; do
|
||||
case "${ARGS[0]}" in
|
||||
--limit) LIMIT=${ARGS[1]:-8000}; ARGS=("${ARGS[@]:2}") ;;
|
||||
*) tabargs+=("${ARGS[0]}"); ARGS=("${ARGS[@]:1}") ;;
|
||||
esac
|
||||
done
|
||||
load_profile; ensure_attached
|
||||
idx=$(resolve_tab "${tabargs[@]+"${tabargs[@]}"}")
|
||||
[ -n "$idx" ] && playwright-cli -s="$SESSION" tab-select "$idx" >/dev/null
|
||||
if [ "$CMD" = text ]; then expr='document.body.innerText'; else expr='document.documentElement.outerHTML'; fi
|
||||
out=$(playwright-cli -s="$SESSION" eval "$expr" | json_unquote)
|
||||
printf '%s' "$out" | head -c "$LIMIT"
|
||||
[ "${#out}" -gt "$LIMIT" ] && printf '\n[truncated %s more characters]\n' "$(( ${#out} - LIMIT ))"
|
||||
echo
|
||||
;;
|
||||
shot)
|
||||
OUT=/tmp/remote-browser-$(date +%s).png; tabargs=()
|
||||
while [ ${#ARGS[@]} -gt 0 ]; do
|
||||
case "${ARGS[0]}" in
|
||||
--out) OUT=${ARGS[1]:-$OUT}; ARGS=("${ARGS[@]:2}") ;;
|
||||
*) tabargs+=("${ARGS[0]}"); ARGS=("${ARGS[@]:1}") ;;
|
||||
esac
|
||||
done
|
||||
load_profile; ensure_attached
|
||||
idx=$(resolve_tab "${tabargs[@]+"${tabargs[@]}"}")
|
||||
[ -n "$idx" ] && playwright-cli -s="$SESSION" tab-select "$idx" >/dev/null
|
||||
playwright-cli -s="$SESSION" screenshot --filename="$OUT" >/dev/null
|
||||
echo "$OUT"
|
||||
;;
|
||||
cli)
|
||||
load_profile; ensure_attached
|
||||
playwright-cli -s="$SESSION" "${ARGS[@]+"${ARGS[@]}"}"
|
||||
;;
|
||||
*)
|
||||
die "unknown command '$CMD'. Try: $PN --help"
|
||||
;;
|
||||
esac
|
||||
@@ -13,9 +13,9 @@ Locate, outline, then read a window — never paste a file body you have not nar
|
||||
|
||||
## Reaching the user's browser
|
||||
|
||||
The user browses on the **Steam Deck**, not on this host. `deck-browser` reads their Chrome (tabs, page text,
|
||||
screenshots) over CDP through an SSH tunnel they enable per session. Read-only: never click or navigate an
|
||||
authenticated session. Details: `/skill:deck-browser`.
|
||||
The user browses on their own machines (a Steam Deck, a laptop), not on this host. `remote-browser` reads their
|
||||
browser (tabs, page text, screenshots) over CDP through a tunnel they enable per session — read-only, and set up per
|
||||
device with the user. Details: `/skill:remote-browser`.
|
||||
|
||||
## Document every change in the Wiki.js homelab docs
|
||||
|
||||
|
||||
+1
-1
@@ -37,4 +37,4 @@ Load the skill that matches the task instead of asking for it up front:
|
||||
| memory, secrets, host safety, forges, codemode, stack defaults | `/skill:homelab-policies` |
|
||||
| delegate a well-specified task to free models, then review it | `/skill:cli/handoff` |
|
||||
| runtimes and project tools | `/skill:mise-cli` |
|
||||
| reading the user's Chrome on the Steam Deck | `/skill:deck-browser` |
|
||||
| reading the user's browser on another machine | `/skill:remote-browser` |
|
||||
@@ -1,54 +0,0 @@
|
||||
---
|
||||
name: deck-browser
|
||||
description: Read the user's Chrome on the Steam Deck from arceus — list tabs, dump page text/HTML, take screenshots. Use when the user says "look at my browser", "what's on my screen", "read this page I have open", or when a page they can see on the Deck is unreachable from this host. Read-only; never drive authenticated sessions.
|
||||
---
|
||||
|
||||
# Reading the Steam Deck's browser
|
||||
|
||||
The user browses on the **Steam Deck** (`deck`, `192.168.129.204`) and talks to agents on **arceus (ziadpve)**.
|
||||
When they say "look at my browser" or "the page I have open", this is how you see it.
|
||||
|
||||
Under the hood it is Playwright: `playwright-cli attach --cdp=ws://127.0.0.1:9222/devtools/browser` connects to
|
||||
Chrome over CDP (Playwright's `connectOverCDP` accepts a `ws://` endpoint), and `bin/deck-browser` is a thin
|
||||
wrapper that opens the SSH tunnel and picks the tab for you.
|
||||
|
||||
## Requirement (user-side, already enabled)
|
||||
|
||||
In the Chrome they want read: `chrome://inspect/#remote-debugging` → tick **"Allow remote debugging for this
|
||||
browser instance."** That binds CDP to `127.0.0.1:9222` **on the Deck only**. If the tool reports no endpoint, ask
|
||||
them to tick it again — never try to enable it yourself, and never expose the port on `0.0.0.0`.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
deck-browser tabs # index, title, url
|
||||
deck-browser status # user agent of the browser
|
||||
deck-browser text --match linkedin --limit 4000 # innerText of that tab
|
||||
deck-browser text --index 3 # by index from `tabs`
|
||||
deck-browser html --index 0 --limit 20000 # outerHTML
|
||||
deck-browser shot --index 3 --out /tmp/x.png # PNG screenshot
|
||||
deck-browser cli tab-select 2 # any playwright-cli command, same session
|
||||
```
|
||||
|
||||
Prefer `--match` over `--index`: tabs reorder between calls. The tunnel opens itself and is reused.
|
||||
|
||||
For anything beyond reading (console, network, storage state), pass a `playwright-cli` command through
|
||||
`deck-browser cli …` rather than writing a new tool.
|
||||
|
||||
## Rules
|
||||
|
||||
- **Read-only.** No click/type/navigate helper exists on purpose. Driving an authenticated session (LinkedIn,
|
||||
Gmail, banking) risks the account being restricted; the user explicitly ruled that out. If a task needs clicking,
|
||||
say so and ask them to do it.
|
||||
- **Screenshots may contain private data.** Write to `/tmp` (never a Git repo), name the path, and never restate
|
||||
credentials, tokens, cookies or payment details seen in a capture.
|
||||
- `chrome://` tabs (newtab, apps, inspect) return little or no text — Chrome blocks script there. Use `shot`.
|
||||
- If attach fails mid-task, the user probably unticked the box or closed the tab: re-run `deck-browser tabs`.
|
||||
- Teardown when finished: `pkill -f "ssh -N -L 9222"` and ask them to untick the box.
|
||||
|
||||
## Background worth knowing
|
||||
|
||||
Chrome ≥136 ignores `--remote-debugging-port` on a normal profile, so the `chrome://inspect` toggle is the only way
|
||||
in (verified on Chrome 158 flatpak: no listener, no `DevToolsActivePort`). That endpoint serves **only** the
|
||||
WebSocket at `/devtools/browser` — HTTP `/json/version` and `/json/list` return 403/404 — which is why the endpoint
|
||||
must be given to Playwright as `ws://`, not `http://`.
|
||||
@@ -0,0 +1,51 @@
|
||||
---
|
||||
name: remote-browser
|
||||
description: Read a Chromium browser running on another machine (Steam Deck, laptop, desktop) over CDP — list tabs, dump page text/HTML, take screenshots. Use when the user says "look at my browser", "what's on my screen", "read this page I have open", or when a page they can see on another device is unreachable from this host. Includes a setup workflow for onboarding a new device. Read-only; never drive authenticated sessions.
|
||||
---
|
||||
|
||||
# Reading someone else's browser
|
||||
|
||||
The user browses on their **own machine** (a Steam Deck, a laptop); agents usually run somewhere else. When they say
|
||||
"look at my browser" or "the page I have open", `remote-browser` shows it to you: it opens a tunnel to that machine
|
||||
and drives `playwright-cli` against the browser's CDP endpoint.
|
||||
|
||||
Underneath it is Playwright — `playwright-cli attach --cdp=ws://…` (`connectOverCDP` accepts a `ws://` URL) — plus a
|
||||
tunnel. The wrapper exists to save you from re-deriving that every time.
|
||||
|
||||
**New device? Follow [`references/setup.md`](references/setup.md)** with the user. It is a checklist with the exact
|
||||
commands, the per-browser switch, and a failure→fix table. Then confirm with `remote-browser check`. Do not invent
|
||||
your own procedure: the failure modes below cost hours.
|
||||
|
||||
## Everyday use
|
||||
|
||||
```bash
|
||||
remote-browser profiles # what is configured
|
||||
remote-browser check --profile deck # readiness test (run this first when something feels off)
|
||||
remote-browser tabs --profile deck # index, title, url
|
||||
remote-browser text --profile deck --match linkedin --limit 4000
|
||||
remote-browser html --profile deck --index 3 --limit 20000
|
||||
remote-browser shot --profile deck --index 3 --out /tmp/x.png
|
||||
remote-browser cli --profile deck console # anything not wrapped
|
||||
```
|
||||
|
||||
Profile defaults to `$REMOTE_BROWSER_PROFILE`, so a single-device setup needs no flag.
|
||||
|
||||
## Rules
|
||||
|
||||
- **Read-only.** There is no click/type/navigate helper, on purpose. Driving an authenticated session (LinkedIn,
|
||||
Gmail, banking) risks the account being restricted, and the user has ruled LinkedIn automation out explicitly. If
|
||||
a task needs clicking, say so and let them do it.
|
||||
- **Screenshots may contain private data.** Write to `/tmp`, never a Git repo; name the path; never restate
|
||||
credentials, tokens, cookies or payment details you see in a capture.
|
||||
- `chrome://` / `edge://` tabs (newtab, apps, inspect) return little text — Chrome blocks script there. Use `shot`.
|
||||
- Prefer `--match` over `--index`: tabs reorder between calls.
|
||||
- If attach fails mid-task the user probably unticked the debugging box: re-run `check`, and ask rather than
|
||||
flipping chrome settings for them.
|
||||
- Teardown when finished: `pkill -f "ssh -N -L <port>:127.0.0.1:<port>"` and ask them to untick the box.
|
||||
|
||||
## The one background fact worth remembering
|
||||
|
||||
Chrome ≥136 ignores `--remote-debugging-port` on a normal profile; the `chrome://inspect/#remote-debugging` toggle is
|
||||
the only way in on a browser the user is already using. That endpoint serves **only**
|
||||
`ws://127.0.0.1:<port>/devtools/browser` — HTTP `/json/version` and `/json/list` return 403/404, which is why the URL
|
||||
handed to Playwright must be `ws://`, not `http://`.
|
||||
@@ -0,0 +1,89 @@
|
||||
# Setting up a new device
|
||||
|
||||
Run this **with the user**, top to bottom. Each step has a check you can perform; do not skip ahead to "try it" when a
|
||||
check fails — the failures look identical (`attach failed`) for three different causes.
|
||||
|
||||
Ask at the start, in one message:
|
||||
|
||||
1. **Which machine and which browser?** (Chrome, Chromium, Brave, Edge — not Firefox)
|
||||
2. **Do I have SSH to it?** `ssh -o BatchMode=yes -o ConnectTimeout=6 <host> true` — if that fails, either ask them
|
||||
to add a key/entry for their agent host, or use `--transport direct` on a trusted LAN.
|
||||
3. **Which port?** Default `9222` unless they already run something there (`ss -ltn | grep 9222`).
|
||||
|
||||
## Step 1 — create the profile
|
||||
|
||||
```bash
|
||||
remote-browser setup --name <label> --host <ssh-alias-or-address> [--port 9222] [--transport ssh|direct]
|
||||
remote-browser profiles # confirm the row
|
||||
```
|
||||
|
||||
Profiles live in `~/.config/remote-browser/profiles/<label>.env`, mode 600, and hold no secrets — only transport,
|
||||
host, port, websocket path and the inspect URL used in error messages. Use `--inspect-url` for non-Chrome browsers
|
||||
(`edge://inspect/#remote-debugging`, `brave://inspect/#remote-debugging`).
|
||||
|
||||
## Step 2 — turn on remote debugging in their browser (user does this)
|
||||
|
||||
| Browser | What to open | What to tick |
|
||||
| --- | --- | --- |
|
||||
| Chrome / Chromium | `chrome://inspect/#remote-debugging` | "Allow remote debugging for this browser instance" |
|
||||
| Brave | `brave://inspect/#remote-debugging` | same |
|
||||
| Edge | `edge://inspect/#remote-debugging` | same |
|
||||
| Chrome < 136 (or a browser with no toggle) | launch with `--remote-debugging-port=9222 --user-data-dir=<separate dir>` | n/a — separate profile, no logins |
|
||||
| Firefox | — | not supported (no CDP); offer a PDF/paste route instead |
|
||||
|
||||
They keep their logins either way. Chrome prints `Server running at: 127.0.0.1:9222` when the toggle is on.
|
||||
|
||||
**Never** set `--remote-debugging-address=0.0.0.0` or open the port on the LAN: CDP is equivalent to handing over the
|
||||
browser's cookies. Loopback plus an SSH tunnel, or nothing.
|
||||
|
||||
## Step 3 — confirm the port on their side
|
||||
|
||||
```bash
|
||||
ssh <host> 'ss -ltn | grep -E "9222|LISTEN"' # Linux
|
||||
ssh <host> 'lsof -nP -iTCP:9222 -sTCP:LISTEN' # macOS
|
||||
# Windows: netstat -an | findstr 9222
|
||||
```
|
||||
|
||||
Expect `127.0.0.1:9222`. If it is absent, the toggle is off or the browser was restarted.
|
||||
|
||||
## Step 4 — run the readiness test
|
||||
|
||||
```bash
|
||||
remote-browser check --profile <label>
|
||||
```
|
||||
|
||||
It checks, in order: SSH reachability → port reachable through the tunnel → websocket handshake returns 101 →
|
||||
Playwright attaches → tab count. Read the first ✗ only; later steps are skipped because they cannot pass.
|
||||
|
||||
| Symptom | Cause | Fix |
|
||||
| --- | --- | --- |
|
||||
| `ssh to <host> failed` | no key, no config entry, host asleep | fix SSH first; or `--transport direct` on a trusted network |
|
||||
| `cdp port not reachable` | toggle off, browser restarted, different port | re-tick in the browser, check `ss -ltn`, confirm `--port` |
|
||||
| `websocket handshake returned 403/404` | wrong path, or an HTTP endpoint | profile must use `/devtools/browser`; the URL given to Playwright must be `ws://` |
|
||||
| `playwright could not attach` | `playwright-cli` missing or too old | `playwright-cli --version`; it must support `attach --cdp=` with a `ws://` value |
|
||||
| `attached but no tabs found` | browser window has no pages | open any page |
|
||||
|
||||
## Step 5 — smoke test, then hand back
|
||||
|
||||
```bash
|
||||
remote-browser tabs --profile <label>
|
||||
remote-browser text --profile <label> --index 0 --limit 200 # any visible text
|
||||
remote-browser shot --profile <label> --index 0 --out /tmp/rb-smoke.png
|
||||
ls -l /tmp/rb-smoke.png # a few hundred KB, not 0
|
||||
```
|
||||
|
||||
Tell the user plainly: what now works, that it is read-only (no clicks, no navigation), that the tunnel can be closed
|
||||
with `pkill -f "ssh -N -L 9222:127.0.0.1"`, and that unticking the box in their browser disables it entirely.
|
||||
|
||||
## Step 6 — record it
|
||||
|
||||
- Wiki: add the device and profile to the remote-browser page (host, port, transport, how the toggle was enabled).
|
||||
- Memory: save one entry naming the profile, the transport, and anything surprising about that device.
|
||||
- If a step needed a workaround, add it to the table above — the next agent reads this file, not your conversation.
|
||||
|
||||
## Housekeeping worth knowing
|
||||
|
||||
- One tunnel per port. Two devices both on 9222 collide; give the second profile `--port 9333` and forward that.
|
||||
- Playwright sessions are named `rb-<profile>`, so parallel devices do not fight over one session.
|
||||
- `remote-browser cli --profile <label> console` (or `requests`, `cookie-list`) is available when reading page text is
|
||||
not enough — but treat cookie and storage output as secret, never echo it.
|
||||
+1
-1
@@ -9,7 +9,7 @@ let
|
||||
sharedSkills = [
|
||||
"git" "gt" "mise-cli" "secrets_man" "searxng" "playwright-cli"
|
||||
"context-discipline" "homelab-policies" "memory-layer" "roku-tv" "zsa-moonlander"
|
||||
"deck-browser"
|
||||
"remote-browser"
|
||||
];
|
||||
cliSkills = [ "infra-change" "wiki-update" "wiki-view" "lapis-memory" "handoff" ];
|
||||
allSkills = sharedSkills ++ cliSkills;
|
||||
|
||||
Reference in new issue
Block a user