fix : opening link 1
All checks were successful
release / build (push) Successful in 23s
release / verify-windows (push) Successful in 1m13s

This commit is contained in:
jeanotx32
2026-08-12 01:03:23 +02:00
parent 6ad8429cf1
commit a38baf9a88
6 changed files with 109 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
import { execFile, spawn } from 'node:child_process';
import { promisify } from 'node:util';
import type { AgentEvent, BrowserSettings } from '@stream-control/shared';
import { x11Env } from './x11.ts';
import { sessionEnv } from './x11.ts';
const run = promisify(execFile);
@@ -9,6 +9,22 @@ export interface BrowserLog {
(level: 'info' | 'warn' | 'error', message: string, event?: AgentEvent): void;
}
export interface LaunchOptions {
/**
* Forcer XWayland. Une fenêtre Wayland native est invisible à xdotool, donc
* impossible à basculer en plein écran par une touche. On ne l'impose que
* lorsque ce rappel est réellement demandé : sous Wayland, XWayland ajoute une
* copie d'image dont une capture par rognage OBS n'a que faire.
*/
forceXWayland?: boolean;
}
function launchEnv(options: LaunchOptions): NodeJS.ProcessEnv {
const env = sessionEnv();
if (options.forceXWayland) env.MOZ_ENABLE_WAYLAND = '0';
return env;
}
/**
* Seules les URL http(s) sont acceptées. Elles finissent en argument de
* processus — jamais dans un shell, donc pas d'injection possible — mais un
@@ -39,6 +55,7 @@ export async function openUrl(
settings: BrowserSettings,
url: string,
log: BrowserLog,
options: LaunchOptions = {},
): Promise<{ command: string; url: string }> {
const target = assertWebUrl(url);
const args = [...settings.args, target];
@@ -48,12 +65,7 @@ export async function openUrl(
const child = spawn(settings.command, args, {
detached: true,
stdio: 'ignore',
// Sous une session Wayland, une fenêtre Firefox native est invisible à
// xdotool : ni activation, ni touche, donc pas de plein écran. XWayland la
// rend pilotable, sans rien changer à la lecture vidéo. Sans effet sur une
// session X11, et sans effet non plus si une instance Firefox tourne déjà —
// elle récupérerait l'URL avec ses propres variables d'environnement.
env: { ...x11Env(), MOZ_ENABLE_WAYLAND: '0' },
env: launchEnv(options),
});
return new Promise((resolve, reject) => {
@@ -85,6 +97,7 @@ export async function openUrl(
export async function blankPage(
settings: BrowserSettings,
log: BrowserLog,
options: LaunchOptions = {},
): Promise<{ command: string; url: string }> {
const args = [...settings.args, 'about:blank'];
log('info', 'Lecteur déchargé (page vide) — fenêtre conservée pour OBS', 'browser.closed');
@@ -92,7 +105,7 @@ export async function blankPage(
const child = spawn(settings.command, args, {
detached: true,
stdio: 'ignore',
env: { ...x11Env(), MOZ_ENABLE_WAYLAND: '0' },
env: launchEnv(options),
});
return new Promise((resolve, reject) => {
@@ -118,7 +131,7 @@ export async function closeWindow(
throw new Error(`Fermeture de fenêtre non gérée sur ${process.platform}`);
}
const env = x11Env();
const env = sessionEnv();
let ids: string[] = [];
try {