mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-05 19:04:43 +03:00
8538f61a72
This patch implements a new mode of network tethering for Playwright server & its clients. With this patch: - playwright server could be launched with the `--browser-proxy-mode=tether` flag to engage in the new mode - a new type of client, "Network Tethering Client" can connect to the server to provide network traffic to the browsers - all clients that connect to the server with the `x-playwright-proxy: *` header will get traffic from the "Network Tethering Client" This patch also adds an environment variable `PW_OWNED_BY_TETHER_CLIENT`. With this env, playwright server will auto-close when the network tethering client disconnects. It will also auto-close if the network client does not connect to the server in the first 10 seconds of the server existence. This way we can ensure that `npx playwright docker start` blocks terminal & controls the lifetime of the started container.
40 lines
1.2 KiB
Bash
Executable File
40 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
SCREEN_WIDTH=1360
|
|
SCREEN_HEIGHT=1020
|
|
SCREEN_DEPTH=24
|
|
SCREEN_DPI=96
|
|
GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"
|
|
|
|
nohup /usr/bin/xvfb-run --server-num=$DISPLAY_NUM \
|
|
--listen-tcp \
|
|
--server-args="-screen 0 "$GEOMETRY" -fbdir /var/tmp -dpi "$SCREEN_DPI" -listen tcp -noreset -ac +extension RANDR" \
|
|
/usr/bin/fluxbox -display "$DISPLAY" >/dev/null 2>&1 &
|
|
|
|
for i in $(seq 1 500); do
|
|
if xdpyinfo -display $DISPLAY >/dev/null 2>&1; then
|
|
break
|
|
fi
|
|
echo "Waiting for Xvfb..."
|
|
sleep 0.2
|
|
done
|
|
|
|
nohup x11vnc -noprimary -nosetprimary -forever -shared -rfbport 5900 -rfbportv6 5900 -display "$DISPLAY" >/dev/null 2>&1 &
|
|
nohup /opt/bin/noVNC/utils/novnc_proxy --listen 7900 --vnc localhost:5900 >/dev/null 2>&1 &
|
|
|
|
cd /ms-playwright-agent
|
|
|
|
NOVNC_UUID=$(cat /proc/sys/kernel/random/uuid)
|
|
echo "novnc is listening on http://127.0.0.1:7900?path=$NOVNC_UUID&resize=scale&autoconnect=1"
|
|
|
|
PW_UUID=$(cat /proc/sys/kernel/random/uuid)
|
|
|
|
# Make sure to re-start playwright server if something goes wrong.
|
|
# The approach taken from: https://stackoverflow.com/a/697064/314883
|
|
|
|
until npx playwright run-server --port=5400 --path=/$PW_UUID --proxy-mode=tether; do
|
|
echo "Server crashed with exit code $?. Respawning.." >&2
|
|
sleep 1
|
|
done
|
|
|