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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2025 Danny Milosavljevic <dannym@friendly-machines.com>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (gnu packages playwright)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix packages)
#:use-module (guix gexp)
#:use-module (guix git-download)
#:use-module (guix build-system node)
#:use-module (guix utils)
#:use-module (gnu packages)
#:use-module (gnu packages chromium)
#:use-module (gnu packages node)
#:use-module (gnu packages node-xyz)
#:use-module (gnu packages python)
#:use-module (gnu packages web))
;; Playwright is a browser automation framework. Upstream provides patched
;; versions of Firefox and WebKit browsers, but those require building
;; custom browser forks. This package only supports Chromium-based browsers
;; (using the system ungoogled-chromium) since Chromium's DevTools Protocol
;; is sufficient for automation without patches.
;;
;; Firefox support would require Playwright's "Juggler" protocol patches.
;; WebKit support would require Playwright's WebKit automation patches.
;; Both are invasive changes to browser source code.
;;
;; In the future, WebDriver BiDi (a W3C standard) may allow Playwright to
;; work with unpatched browsers.
(define-public node-playwright-core
(package
(name "node-playwright-core")
(version "1.50.0")
(source
(origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/microsoft/playwright")
(commit (string-append "v" version))))
(file-name (git-file-name name version))
(sha256
(base32 "0xymivpn2c4srbaqdix3qx2zcr6cx5zgs2a20drvi4dmkspn4jz6"))
(modules '((guix build utils)))
(snippet
'(delete-file-recursively "packages/playwright-core/bundles"))))
(build-system node-build-system)
(arguments
(list
#:tests? #f ; Tests require browser binaries.
#:phases
#~(modify-phases %standard-phases
(add-after 'unpack 'break-monorepo-structure
(lambda _
;; This is a monorepo with npm workspaces. Delete root package.json
;; and lock files to prevent npm from reading workspace config.
(delete-file "package.json")
(for-each delete-file
(find-files "." "package-lock\\.json$"))))
(add-after 'break-monorepo-structure 'change-to-package-directory
(lambda _
(chdir "packages/playwright-core")))
(add-after 'unpack 'skip-browser-download
(lambda _
(setenv "PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD" "1")))
(add-after 'unpack 'unbundle-dependencies
(lambda _
(substitute* "packages/playwright-core/src/zipBundle.ts"
(("require\\('./zipBundleImpl'\\)\\.yazl")
"require('yazl')")
(("require\\('./zipBundleImpl'\\)\\.yauzl")
"require('yauzl')")
(("require\\('./zipBundleImpl'\\)\\.extract")
"require('extract-zip')"))
(substitute* "packages/playwright-core/src/utilsBundle.ts"
(("require\\('./utilsBundleImpl'\\)\\.colors")
"require('colors/safe')")
(("require\\('./utilsBundleImpl'\\)\\.debug")
"require('debug')")
(("require\\('./utilsBundleImpl'\\)\\.diff")
"require('diff')")
(("require\\('./utilsBundleImpl'\\)\\.dotenv")
"require('dotenv')")
(("require\\('./utilsBundleImpl'\\)\\.getProxyForUrl")
"require('proxy-from-env').getProxyForUrl")
(("require\\('./utilsBundleImpl'\\)\\.HttpsProxyAgent")
"require('https-proxy-agent').HttpsProxyAgent")
(("require\\('./utilsBundleImpl'\\)\\.jpegjs")
"require('jpeg-js')")
(("require\\('./utilsBundleImpl'\\)\\.lockfile")
"require('proper-lockfile')")
(("require\\('./utilsBundleImpl'\\)\\.mime")
"require('mime')")
(("require\\('./utilsBundleImpl'\\)\\.minimatch")
"require('minimatch')")
(("require\\('./utilsBundleImpl'\\)\\.open")
"require('open')")
(("require\\('./utilsBundleImpl'\\)\\.PNG")
"require('pngjs').PNG")
(("require\\('./utilsBundleImpl'\\)\\.program")
"require('commander').program")
(("require\\('./utilsBundleImpl'\\)\\.progress")
"require('progress')")
(("require\\('./utilsBundleImpl'\\)\\.SocksProxyAgent")
"require('socks-proxy-agent').SocksProxyAgent")
(("require\\('./utilsBundleImpl'\\)\\.yaml")
"require('yaml')")
(("require\\('./utilsBundleImpl'\\)\\.wsServer")
"require('ws').WebSocketServer")
(("require\\('./utilsBundleImpl'\\)\\.wsReceiver")
"require('ws').Receiver")
(("require\\('./utilsBundleImpl'\\)\\.wsSender")
"require('ws').Sender")
(("require\\('./utilsBundleImpl'\\)\\.ws\\b")
"require('ws')")
(("require\\('./utilsBundleImpl'\\)\\.StackUtils")
"require('stack-utils')"))))
(add-after 'unbundle-dependencies 'add-unbundled-dependencies
(lambda _
;; Add dependencies that were unbundled from utilsBundle/zipBundle.
;; Must run before patch-dependencies which minifies package.json.
(modify-json
#:file "packages/playwright-core/package.json"
(lambda (pkg)
(acons "dependencies"
'(("colors" . "*")
("commander" . "*")
("debug" . "*")
("diff" . "*")
("dotenv" . "*")
("extract-zip" . "*")
("https-proxy-agent" . "*")
("jpeg-js" . "*")
("mime" . "*")
("minimatch" . "*")
("open" . "*")
("pngjs" . "*")
("progress" . "*")
("proper-lockfile" . "*")
("proxy-from-env" . "*")
("socks-proxy-agent" . "*")
("stack-utils" . "*")
("ws" . "*")
("yaml" . "*")
("yazl" . "*")
("yauzl" . "*"))
pkg)))))
(add-before 'build 'generate-injected-scripts
(lambda _
;; Run generate_injected.js to create src/generated/*.ts files.
(invoke "node" "../../utils/generate_injected.js")))
(add-after 'generate-injected-scripts 'add-build-script
(lambda _
;; Upstream uses Babel, but Babel isn't packaged. Use esbuild.
;; Compile TypeScript and copy non-TS files (JS, JSON, PNG).
(modify-json
(lambda (pkg)
(acons "scripts"
'(("build" . "find src -name '*.ts' | xargs esbuild --outdir=lib --format=cjs --platform=node && cp -r src/third_party lib/ && find src \\( -name '*.json' -o -name '*.png' \\) -exec sh -c 'mkdir -p lib/$(dirname ${0#src/}) && cp $0 lib/${0#src/}' {} \\;"))
pkg)))))
(add-before 'install 'set-cc
(lambda _
(setenv "CC" #$(cc-for-target))))
(add-after 'install 'wrap-playwright-cli
(lambda* (#:key inputs outputs #:allow-other-keys)
(let* ((out (assoc-ref outputs "out"))
(cli (string-append out "/lib/node_modules/playwright-core/cli.js")))
(wrap-program cli
;; Avoid vite dependency.
`("PW_CODEGEN_NO_INSPECTOR" = ("1"))
`("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD" = ("1")))))))))
(inputs
(list node-esbuild
;; Dependencies (unbundled from utilsBundle).
node-colors
node-commander
node-debug
node-diff
node-dotenv
node-graceful-fs
node-https-proxy-agent
node-jpeg-js
node-mime
node-minimatch-3
node-ms
node-open
node-pngjs
node-progress
node-proper-lockfile
node-proxy-from-env
node-retry
node-signal-exit
node-socks-proxy-agent
node-stack-utils
node-ws
node-yaml
;; Dependencies (unbundled from zipBundle).
node-yazl
node-yauzl
node-extract-zip))
(native-inputs
(list esbuild python))
(native-search-paths
(list
(search-path-specification
(variable "PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH")
(file-type 'regular)
(separator #f) ;single entry
(files '("bin/chromium")))
(search-path-specification
(variable "PWTEST_CLI_EXECUTABLE_PATH")
(file-type 'regular)
(separator #f) ;single entry
(files '("bin/chromium")))))
(home-page "https://playwright.dev/")
(synopsis "Browser automation library (Chromium-only)")
(description
"Playwright is a framework for browser automation and end-to-end testing.
This package provides @code{playwright-core}, the library without bundled
browsers.
@strong{Important}: This package only supports Chromium-based browsers.
Firefox and WebKit are not supported because Playwright requires custom-patched
versions of those browsers that are not packaged for Guix.
To use Playwright with the system Chromium, either:
@enumerate
@item
Set the environment variable @env{PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH} to the
Chromium binary path, or
@item
Use the @code{executablePath} option in your Playwright code:
@example
const browser = await chromium.launch(@{
executablePath: '/run/current-system/profile/bin/chromium'
@});
@end example
For the command line variant $code{playwright-core}, set the environment
variable $env{PWTEST_CLI_EXECUTABLE_PATH} to the Chromium binary path.
@end enumerate")
(license license:asl2.0)))
|