Skip to content

Commit 491070f

Browse files
committed
fix: use pre-installed playwright in Docker images via NODE_PATH instead of npm install
1 parent bafd5b5 commit 491070f

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

internal/connector/browser.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,21 +107,21 @@ func (c *BrowserRunConnector) Execute(ctx context.Context, params map[string]any
107107
case "javascript":
108108
containerImage = playwrightNodeImage
109109
wrapperScript = buildJSWrapper(script)
110-
// The Playwright Docker image ships browsers but not the npm package.
111-
// Install it silently before running so the script can require('playwright').
112-
// `node` with no file argument reads the script from stdin.
113-
containerCmd = []string{"sh", "-c", "cd /tmp && npm init -y --silent 2>/dev/null && npm install --silent playwright 2>/dev/null && node"}
110+
// The Playwright Docker image has browsers + a global playwright install.
111+
// Set NODE_PATH so `require('playwright')` finds the global package when
112+
// running a script from stdin.
113+
containerCmd = []string{"sh", "-c", "NODE_PATH=$(npm root -g) node"}
114114
case "typescript":
115115
containerImage = playwrightNodeImage
116116
wrapperScript = buildJSWrapper(script)
117-
// Same npm-install preamble; use --experimental-strip-types for TS syntax.
118-
containerCmd = []string{"sh", "-c", "cd /tmp && npm init -y --silent 2>/dev/null && npm install --silent playwright 2>/dev/null && node --experimental-strip-types"}
117+
// Same as JS but with TypeScript type-stripping enabled.
118+
containerCmd = []string{"sh", "-c", "NODE_PATH=$(npm root -g) node --experimental-strip-types"}
119119
case "python":
120120
containerImage = playwrightPythonImage
121121
wrapperScript = buildPythonWrapper(script)
122-
// Install the playwright Python package if not already present, then run
123-
// the script via stdin (`python3 -`).
124-
containerCmd = []string{"sh", "-c", "pip install --quiet playwright 2>/dev/null && python3 -"}
122+
// The Playwright Python image has playwright pre-installed globally.
123+
// Read the script from stdin.
124+
containerCmd = []string{"python3", "-"}
125125
}
126126

127127
// --- build docker/run params ---

0 commit comments

Comments
 (0)