Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

refactor(linux): share the Wayland session check with source enumeration

EtienneLescot31166510d659
diff --git a/electron/ipc/desktopSourceTypes.ts b/electron/ipc/desktopSourceTypes.ts
index 1185623ce..1cd50dcad 100644
--- a/electron/ipc/desktopSourceTypes.ts
+++ b/electron/ipc/desktopSourceTypes.ts
@@ -1,3 +1,5 @@
+import { isWaylandSession } from "../wayland";
+
// Issue #462. On X11, one desktopCapturer.getSources call asking for both
// "screen" and "window" runs Chromium's two X11 capturers together, and the
// screen capturer's thumbnail grab then intermittently fails ("Failed to
@@ -15,9 +17,9 @@ export function shouldEnumerateSourceTypesSeparately(
platform: NodeJS.Platform,
env: Partial<NodeJS.ProcessEnv>,
): boolean {
- // The same test main.ts uses to put Chromium on its Wayland backend.
- const isWayland = env.XDG_SESSION_TYPE === "wayland" || env.WAYLAND_DISPLAY !== undefined;
- return platform === "linux" && !isWayland;
+ // The same test that turns on the PipeWire capturer at startup, whichever Ozone
+ // backend the app runs on.
+ return platform === "linux" && !isWaylandSession(env);
}
export async function getSourcesByType<T>(
diff --git a/electron/wayland.test.ts b/electron/wayland.test.ts
index 5868f165e..62ea6b484 100644
--- a/electron/wayland.test.ts
+++ b/electron/wayland.test.ts
@@ -23,6 +23,11 @@ describe("Wayland startup configuration", () => {
configureWaylandSupport(commandLine, { XDG_SESSION_TYPE: "wayland" });
expect(switches.get("ozone-platform")).toBe(platform);
expect(commandLine.appendSwitch).not.toHaveBeenCalledWith("ozone-platform", expect.anything());
+ // Capture still goes through PipeWire under Xwayland: X11 cannot see Wayland windows.
+ expect(commandLine.appendSwitch).toHaveBeenCalledWith(
+ "enable-features",
+ "WaylandWindowDrag,WebRTCPipeWireCapturer",
+ );
});
it.each([{}, { XDG_SESSION_TYPE: "x11" }])("leaves a non-Wayland session alone: %j", (env) => {
diff --git a/electron/wayland.ts b/electron/wayland.ts
index 85e6e235a..23497074c 100644
--- a/electron/wayland.ts
+++ b/electron/wayland.ts
@@ -1,17 +1,22 @@
type CommandLine = Pick<Electron.CommandLine, "appendSwitch" | "hasSwitch">;
+type Env = Readonly<Record<string, string | undefined>>;
+
+export function isWaylandSession(env: Env): boolean {
+ return env.XDG_SESSION_TYPE === "wayland" || env.WAYLAND_DISPLAY !== undefined;
+}
/** Prefer Wayland in a Wayland session, while respecting an explicit backend. */
-export function configureWaylandSupport(
- commandLine: CommandLine,
- env: Readonly<Record<string, string | undefined>>,
-): void {
- const isWayland = env.XDG_SESSION_TYPE === "wayland" || env.WAYLAND_DISPLAY !== undefined;
- if (!isWayland) return;
+export function configureWaylandSupport(commandLine: CommandLine, env: Env): void {
+ if (!isWaylandSession(env)) return;
if (!commandLine.hasSwitch("ozone-platform")) {
commandLine.appendSwitch("ozone-platform", "wayland");
}
+ // Enable WebRTCPipeWireCapturer for screen capture on Wayland
commandLine.appendSwitch("enable-features", "WaylandWindowDrag,WebRTCPipeWireCapturer");
- // Chromium's Wayland backend cannot import PipeWire DMA-BUF frames through
- // Vulkan. Keep the existing GL/EGL capture path for Wayland sessions.
+ // Chromium's Wayland Ozone backend can't use Vulkan. When it tries, the WebRTC
+ // PipeWire capturer fails to import DMA-BUF frames into EGL (EGL_BAD_MATCH), the
+ // stream renegotiates, and screen recording yields no usable frames. Force the
+ // GL/EGL path so DMA-BUF import works. (Chromium itself logs this suggestion:
+ // "'--ozone-platform=wayland' is not compatible with Vulkan ... disabling Vulkan".)
commandLine.appendSwitch("disable-features", "Vulkan");
}