@@ -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