chore(scripts): headless screenshots on a private Xvfb display
window-shot.ps1 typed into whatever window had focus on the Windows desktop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -90,6 +90,7 @@ It signs you in through a real Teams web page and lets that page make the API ca
90
90
| Against Chrome on a debug port | `cargo run -p app -- --endpoint http://127.0.0.1:9222` |
91
91
| Windows exe from WSL/Linux | `scripts/build-windows.sh crates/app teams`, see [docs/build-windows.md](docs/build-windows.md) |
92
92
| Tests | `cargo test` |
93
| Screenshot without a desktop (Xvfb, xdotool, xclip, mesa-vulkan-drivers) | `cargo build -p app && scripts/headless-shot.sh shot.png -- "mousemove 450 740" "click 1" "type hello"` |
93
94
94
95
## Docs
95
96
@@ -90,6 +90,7 @@ It signs you in through a real Teams web page and lets that page make the API ca90
| Against Chrome on a debug port | `cargo run -p app -- --endpoint http://127.0.0.1:9222` |90
| Against Chrome on a debug port | `cargo run -p app -- --endpoint http://127.0.0.1:9222` |91
| Windows exe from WSL/Linux | `scripts/build-windows.sh crates/app teams`, see [docs/build-windows.md](docs/build-windows.md) |91
| Windows exe from WSL/Linux | `scripts/build-windows.sh crates/app teams`, see [docs/build-windows.md](docs/build-windows.md) |92
| Tests | `cargo test` |92
| Tests | `cargo test` |93
| Screenshot without a desktop (Xvfb, xdotool, xclip, mesa-vulkan-drivers) | `cargo build -p app && scripts/headless-shot.sh shot.png -- "mousemove 450 740" "click 1" "type hello"` |93
94
94
## Docs95
## Docs95
96
@@ -0,0 +1,63 @@
1
#!/usr/bin/env bash
2
# Usage: scripts/headless-shot.sh OUT.png [--size 1280x800] [--wait 10] [--bin target/debug/teams] [--] [xdotool command]...
3
# Runs the Linux build with --demo on a private Xvfb display and saves a screenshot.
4
# Example: scripts/headless-shot.sh shot.png -- "mousemove 450 740" "click 1" "type hello" "paste ```\\ncode\\n```"
5
# `type` cannot send a backtick (X11 treats it as a dead key and input stops); use `paste`, which expands \n.
6
set -euo pipefail
7
8
out=${1:?output png}
9
shift
10
size=1280x800
11
wait_seconds=10
12
binary=target/debug/teams
13
while [[ $# -gt 0 ]]; do
14
case $1 in
15
--size) size=$2; shift 2 ;;
16
--wait) wait_seconds=$2; shift 2 ;;
17
--bin) binary=$2; shift 2 ;;
18
--) shift; break ;;
19
*) break ;;
20
esac
21
done
22
23
display_number=$((100 + RANDOM % 800))
24
Xvfb ":$display_number" -screen 0 "${size}x24" -nolisten tcp >/dev/null 2>&1 &
25
xvfb_pid=$!
26
app_pid=
27
cleanup() {
28
[[ -n $app_pid ]] && kill "$app_pid" 2>/dev/null || true
29
kill "$xvfb_pid" 2>/dev/null || true
30
}
31
trap cleanup EXIT
32
sleep 1
33
34
export DISPLAY=":$display_number"
35
unset WAYLAND_DISPLAY
36
export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.json
37
"$binary" --demo >/dev/null 2>&1 &
38
app_pid=$!
39
sleep "$wait_seconds"
40
41
for command in "$@"; do
42
subcommand=${command%% *}
43
rest=${command#"$subcommand"}
44
rest=${rest# }
45
if [[ $subcommand == click ]]; then
46
# Xvfb has no window manager: keyboard focus only follows an explicit windowfocus.
47
eval "$(xdotool getmouselocation --shell)"
48
xdotool windowfocus --sync "$WINDOW"
49
fi
50
if [[ $subcommand == type ]]; then
51
xdotool type --delay 20 -- "$rest"
52
elif [[ $subcommand == paste ]]; then
53
printf '%b' "$rest" | xclip -selection clipboard
54
xdotool key ctrl+v
55
else
56
read -r -a arguments <<<"$rest"
57
xdotool "$subcommand" "${arguments[@]}"
58
fi
59
sleep 0.4
60
done
61
sleep 1
62
import -window root "$out"
63
echo "$out"
@@ -0,0 +1,63 @@1
#!/usr/bin/env bash2
# Usage: scripts/headless-shot.sh OUT.png [--size 1280x800] [--wait 10] [--bin target/debug/teams] [--] [xdotool command]...3
# Runs the Linux build with --demo on a private Xvfb display and saves a screenshot.4
# Example: scripts/headless-shot.sh shot.png -- "mousemove 450 740" "click 1" "type hello" "paste ```\\ncode\\n```"5
# `type` cannot send a backtick (X11 treats it as a dead key and input stops); use `paste`, which expands \n.6
set -euo pipefail7
8
out=${1:?output png}9
shift10
size=1280x80011
wait_seconds=1012
binary=target/debug/teams13
while [[ $# -gt 0 ]]; do14
case $1 in15
--size) size=$2; shift 2 ;;16
--wait) wait_seconds=$2; shift 2 ;;17
--bin) binary=$2; shift 2 ;;18
--) shift; break ;;19
*) break ;;20
esac21
done22
23
display_number=$((100 + RANDOM % 800))24
Xvfb ":$display_number" -screen 0 "${size}x24" -nolisten tcp >/dev/null 2>&1 &25
xvfb_pid=$!26
app_pid=27
cleanup() {28
[[ -n $app_pid ]] && kill "$app_pid" 2>/dev/null || true29
kill "$xvfb_pid" 2>/dev/null || true30
}31
trap cleanup EXIT32
sleep 133
34
export DISPLAY=":$display_number"35
unset WAYLAND_DISPLAY36
export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/lvp_icd.json37
"$binary" --demo >/dev/null 2>&1 &38
app_pid=$!39
sleep "$wait_seconds"40
41
for command in "$@"; do42
subcommand=${command%% *}43
rest=${command#"$subcommand"}44
rest=${rest# }45
if [[ $subcommand == click ]]; then46
# Xvfb has no window manager: keyboard focus only follows an explicit windowfocus.47
eval "$(xdotool getmouselocation --shell)"48
xdotool windowfocus --sync "$WINDOW"49
fi50
if [[ $subcommand == type ]]; then51
xdotool type --delay 20 -- "$rest"52
elif [[ $subcommand == paste ]]; then53
printf '%b' "$rest" | xclip -selection clipboard54
xdotool key ctrl+v55
else56
read -r -a arguments <<<"$rest"57
xdotool "$subcommand" "${arguments[@]}"58
fi59
sleep 0.460
done61
sleep 162
import -window root "$out"63
echo "$out"