-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbrowser-viewer.sh
More file actions
executable file
·44 lines (40 loc) · 1.47 KB
/
Copy pathbrowser-viewer.sh
File metadata and controls
executable file
·44 lines (40 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh
# actor-runtime's browser-view sidecar: waits for the Actor's X socket in the shared /tmp/.X11-unix, then
# mirrors that display with x11vnc. The display number is taken from the socket name (`xvfb-run -a` picks
# one at run time). When the Actor container restarts (migration), x11vnc exits and the loop waits again.
# Env names must match `src/driver/docker-driver.ts`.
SOCKET_DIR=/tmp/.X11-unix
PORT="${APIFY_BROWSER_VIEWER_PORT:-5900}"
if [ "$APIFY_BROWSER_VIEWER_INTERACTIVE" = "1" ]; then
INPUT_FLAG=""
MODE=interactive
else
INPUT_FLAG="-viewonly"
MODE=view-only
fi
log() {
echo "[actor-runtime browser view] $*"
}
log "waiting for an X display socket in $SOCKET_DIR (created by the Actor's own Xvfb when the Actor starts)"
while :; do
socket=""
for candidate in "$SOCKET_DIR"/X*; do
if [ -S "$candidate" ]; then
socket="$candidate"
break
fi
done
if [ -z "$socket" ]; then
sleep 0.5
continue
fi
display=":${socket##*/X}"
log "mirroring display $display ($MODE) on port $PORT"
# -noshm: MIT-SHM cannot cross container IPC namespaces (x11vnc would die on X_ShmAttach).
# -nosel/-nobell/-noxrecord/-nowf/-noscr: only read pixels; no clipboard, bell, or X request recording.
# shellcheck disable=SC2086 # INPUT_FLAG is intentionally word-split.
x11vnc -display "$display" -rfbport "$PORT" -noshm -nosel -nobell -shared -forever -nopw -noipv6 -q \
-noxrecord -nowf -noscr $INPUT_FLAG
log "x11vnc exited - display gone; waiting for a display again"
sleep 1
done