Skip to content

Commit 1d2d45e

Browse files
authored
Enable patchright based execution (#93)
## Overview Following up on #84. Install and allow running against patchright instead of only playwright ## Testing Build + ran both headful + headless images. Confirmed execution working as expected with `curl`: ```sh curl -sS http://localhost:444/playwright/execute \ -H 'Content-Type: application/json' \ -d '{"code":"await page.goto(\"https://example.com\"); return await page.title();"}' {"result":"Example Domain","success":true} ``` <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds Patchright support across images and runtime, selectable via PLAYWRIGHT_ENGINE, and tweaks headless Chromium flags. > > - **Runtime** > - Update `server/runtime/playwright-executor.ts` to dynamically select `chromium` from `patchright` or `playwright-core` based on `PLAYWRIGHT_ENGINE`. > - **Images** > - Install `patchright` globally alongside `playwright-core`, `typescript`, and `tsx` in `images/chromium-headful/Dockerfile` and `images/chromium-headless/image/Dockerfile`. > - **Scripts** > - Pass through `PLAYWRIGHT_ENGINE` env in `images/chromium-headful/run-docker.sh` and `images/chromium-headless/run-docker.sh`. > - **Chromium Flags (Headless)** > - Adjust defaults in `images/chromium-headless/image/wrapper.sh` by removing several flags (e.g., `--disable-component-update`, `--disable-default-apps`, `--disable-extensions`, `--enable-automation`). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 50d5bb3. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 18771b2 commit 1d2d45e

File tree

6 files changed

+16
-9
lines changed

6 files changed

+16
-9
lines changed

images/chromium-headful/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ RUN set -eux; \
276276
ln -sf /usr/local/lib/node_modules/corepack/dist/corepack.js /usr/local/bin/corepack; \
277277
fi
278278

279-
# Install TypeScript and Playwright globally
280-
RUN --mount=type=cache,target=/root/.npm,id=$CACHEIDPREFIX-npm npm install -g typescript playwright-core tsx
279+
# Install TypeScript, Playwright, Patchright globally
280+
RUN --mount=type=cache,target=/root/.npm,id=$CACHEIDPREFIX-npm npm install -g typescript playwright-core patchright tsx
281281

282282
# setup desktop env & app
283283
ENV DISPLAY_NUM=1

images/chromium-headful/run-docker.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ RUN_ARGS=(
6666
--mount type=bind,src="$FLAGS_FILE",dst=/chromium/flags,ro
6767
)
6868

69+
if [[ -n "${PLAYWRIGHT_ENGINE:-}" ]]; then
70+
RUN_ARGS+=( -e PLAYWRIGHT_ENGINE="$PLAYWRIGHT_ENGINE" )
71+
fi
72+
6973
# WebRTC port mapping
7074
if [[ "${ENABLE_WEBRTC:-}" == "true" ]]; then
7175
echo "Running container with WebRTC"

images/chromium-headless/image/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ RUN set -eux; \
179179
ln -sf /usr/local/lib/node_modules/corepack/dist/corepack.js /usr/local/bin/corepack; \
180180
fi
181181

182-
# Install TypeScript and Playwright globally
183-
RUN --mount=type=cache,target=/root/.npm,id=$CACHEIDPREFIX-npm npm install -g typescript playwright-core tsx
182+
# Install TypeScript, Playwright, Patchright globally
183+
RUN --mount=type=cache,target=/root/.npm,id=$CACHEIDPREFIX-npm npm install -g typescript playwright-core patchright tsx
184184

185185
ENV WITHDOCKER=true
186186

images/chromium-headless/image/wrapper.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,9 @@ if [ -z "${CHROMIUM_FLAGS:-}" ]; then
4444
--disable-breakpad \
4545
--disable-client-side-phishing-detection \
4646
--disable-component-extensions-with-background-pages \
47-
--disable-component-update \
4847
--disable-crash-reporter \
4948
--disable-crashpad \
50-
--disable-default-apps \
5149
--disable-dev-shm-usage \
52-
--disable-extensions \
5350
--disable-features=AcceptCHFrame,AutoExpandDetailsElement,AvoidUnnecessaryBeforeUnloadCheckSync,CertificateTransparencyComponentUpdater,DeferRendererTasksAfterInput,DestroyProfileOnBrowserClose,DialMediaRouteProvider,ExtensionManifestV2Disabled,GlobalMediaControls,HttpsUpgrades,ImprovedCookieControls,LazyFrameLoading,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate \
5451
--disable-field-trial-config \
5552
--disable-gcm-registration \
@@ -63,7 +60,6 @@ if [ -z "${CHROMIUM_FLAGS:-}" ]; then
6360
--disable-renderer-backgrounding \
6461
--disable-search-engine-choice-screen \
6562
--disable-software-rasterizer \
66-
--enable-automation \
6763
--enable-use-zoom-for-dsf=false \
6864
--export-tagged-pdf \
6965
--force-color-profile=srgb \

images/chromium-headless/run-docker.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ RUN_ARGS=(
1919
-v "$HOST_RECORDINGS_DIR:/recordings"
2020
)
2121

22+
if [[ -n "${PLAYWRIGHT_ENGINE:-}" ]]; then
23+
RUN_ARGS+=( -e PLAYWRIGHT_ENGINE="$PLAYWRIGHT_ENGINE" )
24+
fi
25+
2226
# If a positional argument is given, use it as the entrypoint
2327
ENTRYPOINT_ARG=()
2428
if [[ $# -ge 1 && -n "$1" ]]; then

server/runtime/playwright-executor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { readFileSync } from 'fs';
2-
import { chromium } from 'playwright-core';
2+
import { chromium as chromiumPW } from 'playwright-core';
3+
import { chromium as chromiumPR } from 'patchright';
34

45
async function main() {
56
const codeFilePath = process.argv[2];
@@ -24,6 +25,8 @@ async function main() {
2425
let result;
2526

2627
try {
28+
const chromium = process.env.PLAYWRIGHT_ENGINE === 'patchright' ? chromiumPR : chromiumPW;
29+
2730
browser = await chromium.connectOverCDP('ws://127.0.0.1:9222');
2831
const contexts = browser.contexts();
2932
const context = contexts.length > 0 ? contexts[0] : await browser.newContext();

0 commit comments

Comments
 (0)