Skip to content

Commit 4c8d50b

Browse files
committed
fix(plugin/xvfb): Support Chromium 140 (with use Wayland).
1 parent 0de424a commit 4c8d50b

2 files changed

Lines changed: 46 additions & 15 deletions

File tree

docs/plugins/utils/xvfb.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
> [`Xvfb`](https://www.x.org/archive/X11R7.7/doc/man/man1/Xvfb.1.xhtml) in your
77
> Linux:
88
>
9-
> - `sudo apt-get install xvfb` (on Debian/Ubuntu)
10-
> - `sudo yum install xorg-x11-server-Xvfb` (on Fedora/RHEL/CentOS)
11-
> - `sudo pacman -S xorg-server-xvfb` (on Arch)
9+
> - Debian/Ubuntu: `sudo apt-get install xvfb`
10+
> - Fedora/RHEL/CentOS: `sudo yum install xorg-x11-server-Xvfb`
11+
> - Arch: `sudo pacman -S xorg-server-xvfb`
1212
1313
Start an instance of `Xvfb` (_X Virtual Frame Buffer_) and launches the browser
14-
in this virtual framebuffer.
14+
in this virtual framebuffer. This plugin is only useful in headful mode.
1515

1616
## Options
1717

src/plugins/utils/xvfb.js

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import process from "node:process";
1010

1111
/**
1212
* @import { ChildProcess } from "node:child_process"
13+
* @import { BrowserType } from "playwright"
14+
* @import { ContextBefore } from "../../hook.js"
1315
*/
1416

1517
/**
@@ -101,16 +103,38 @@ const killXvfb = (args) => {
101103
* Définit le `DISPLAY` (du serveur de `Xvfb`) dans les options de création d'un
102104
* `Browser`.
103105
*
104-
* @param {Record<string, any>|undefined} options Les options de création d'un
105-
* `Browser`.
106-
* @param {string} display Le `DISPLAY` du serveur de
107-
* `Xvfb` (par exemple : `:99`).
106+
* @param {Record<string, any>|undefined} options Les options de création
107+
* d'un `Browser`.
108+
* @param {string} display Le `DISPLAY` du serveur de
109+
* `Xvfb` (par exemple :
110+
* `:99`).
111+
* @param {BrowserType} browserType Le type de navigateur.
108112
* @returns {Record<string, any>} Les nouvelles options.
109113
*/
110-
const setDisplay = (options, display) => {
114+
const setDisplay = (options, display, browserType) => {
115+
if ("chromium" === browserType.name()) {
116+
return {
117+
...options,
118+
// Forcer l'utilisation de la plateforme X11, car Chromium 140 est
119+
// passé à Wayland par défaut sous Linux.
120+
// https://github.com/microsoft/playwright/issues/37236
121+
args: ["--ozone-platform=x11", ...(options?.args ?? [])],
122+
env:
123+
// Utilise `process.env` par défaut, car c'est la valeur
124+
// utilisée par Playwright.
125+
// https://playwright.dev/docs/api/class-browsertype#browser-type-launch-option-env
126+
undefined === options?.env
127+
? { ...process.env, DISPLAY: display }
128+
: { ...options.env, DISPLAY: display },
129+
};
130+
}
131+
111132
return {
112133
...options,
113134
env:
135+
// Utilise `process.env` par défaut, car c'est la valeur utilisée
136+
// par Playwright.
137+
// https://playwright.dev/docs/api/class-browsertype#browser-type-launch-option-env
114138
undefined === options?.env
115139
? { ...process.env, DISPLAY: display }
116140
: { ...options.env, DISPLAY: display },
@@ -170,25 +194,32 @@ export default function utilsXvfbPlugin(options) {
170194
/**
171195
* Modifie les options de lancement du navigateur.
172196
*
173-
* @param {any[]} args Les paramètres de la méthode.
197+
* @param {any[]} args Les paramètres de la
198+
* méthode.
199+
* @param {ContextBefore<BrowserType>} context Le contexte du crochet.
174200
* @returns {Promise<any[]>} Une promesse contenant les nouveaux
175201
* paramètres.
176202
*/
177-
"BrowserType.launch:before": async (args) => {
203+
"BrowserType.launch:before": async (args, { obj: browserType }) => {
178204
const display = await spawnXvfb(xvfbArgs, keepalive);
179-
return [setDisplay(args[0], display)];
205+
return [setDisplay(args[0], display, browserType)];
180206
},
181207

182208
/**
183209
* Modifie les options de lancement du navigateur.
184210
*
185-
* @param {any[]} args Les paramètres de la méthode.
211+
* @param {any[]} args Les paramètres de la
212+
* méthode.
213+
* @param {ContextBefore<BrowserType>} context Le contexte du crochet.
186214
* @returns {Promise<any[]>} Une promesse contenant les nouveaux
187215
* paramètres.
188216
*/
189-
"BrowserType.launchPersistentContext:before": async (args) => {
217+
"BrowserType.launchPersistentContext:before": async (
218+
args,
219+
{ obj: browserType },
220+
) => {
190221
const display = await spawnXvfb(xvfbArgs, keepalive);
191-
return [args[0], setDisplay(args[1], display)];
222+
return [args[0], setDisplay(args[1], display, browserType)];
192223
},
193224

194225
/**

0 commit comments

Comments
 (0)