Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(docker): do not sync primary selection into clipboard (#17424)

Pavel Feldmane9f926e536bb
diff --git a/packages/playwright-test/src/docker/build_docker_image.sh b/packages/playwright-test/src/docker/build_docker_image.sh
index e3f7520551..89eef09023 100644
--- a/packages/playwright-test/src/docker/build_docker_image.sh
+++ b/packages/playwright-test/src/docker/build_docker_image.sh
@@ -17,6 +17,54 @@ mkdir -p /opt/bin && chmod +x /dev/shm \
&& rm -rf websockify-${WEBSOCKIFY_REF}/{docs,tests} \
&& mv websockify-${WEBSOCKIFY_REF} /opt/bin/noVNC/utils/websockify
+# Patch noVNC
+
+cat <<'EOF' > /opt/bin/noVNC/clip.patch
+diff --git a/app/ui.js b/app/ui.js
+index cb6a9fd..dbe42e0 100644
+--- a/app/ui.js
++++ b/app/ui.js
+@@ -951,6 +951,7 @@ const UI = {
+ clipboardReceive(e) {
+ Log.Debug(">> UI.clipboardReceive: " + e.detail.text.substr(0, 40) + "...");
+ document.getElementById('noVNC_clipboard_text').value = e.detail.text;
++ navigator.clipboard.writeText(e.detail.text).catch(() => {});
+ Log.Debug("<< UI.clipboardReceive");
+ },
+
+diff --git a/core/rfb.js b/core/rfb.js
+index ea3bf58..fad57bc 100644
+--- a/core/rfb.js
++++ b/core/rfb.js
+@@ -176,6 +176,7 @@ export default class RFB extends EventTargetMixin {
+ handleMouse: this._handleMouse.bind(this),
+ handleWheel: this._handleWheel.bind(this),
+ handleGesture: this._handleGesture.bind(this),
++ handleFocus: () => navigator.clipboard.readText().then(this.clipboardPasteFrom.bind(this)).catch(() => {})
+ };
+
+ // main setup
+@@ -515,6 +516,7 @@ export default class RFB extends EventTargetMixin {
+ this._canvas.addEventListener("gesturestart", this._eventHandlers.handleGesture);
+ this._canvas.addEventListener("gesturemove", this._eventHandlers.handleGesture);
+ this._canvas.addEventListener("gestureend", this._eventHandlers.handleGesture);
++ window.addEventListener('focus', this._eventHandlers.handleFocus);
+
+ Log.Debug("<< RFB.connect");
+ }
+@@ -522,6 +524,7 @@ export default class RFB extends EventTargetMixin {
+ _disconnect() {
+ Log.Debug(">> RFB.disconnect");
+ this._cursor.detach();
++ window.removeEventListener('focus', this._eventHandlers.handleFocus);
+ this._canvas.removeEventListener("gesturestart", this._eventHandlers.handleGesture);
+ this._canvas.removeEventListener("gesturemove", this._eventHandlers.handleGesture);
+ this._canvas.removeEventListener("gestureend", this._eventHandlers.handleGesture);
+EOF
+
+cd /opt/bin/noVNC
+git apply clip.patch
+
# Configure FluxBox menus
mkdir /root/.fluxbox
cd /ms-playwright-agent
@@ -63,7 +111,7 @@ for i in $(seq 1 500); do
sleep 0.2
done
-nohup x11vnc -forever -shared -rfbport 5900 -rfbportv6 5900 -display "$DISPLAY" >/dev/null 2>&1 &
+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