Skip to content

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

fix: pass asset base URL to preload via additionalArguments

Siddharth8458cbb40e95
diff --git a/electron/preload.ts b/electron/preload.ts
index ec5181c24..12167e521 100644
--- a/electron/preload.ts
+++ b/electron/preload.ts
@@ -1,18 +1,12 @@
-import path from "node:path";
-import { pathToFileURL } from "node:url";
import { contextBridge, ipcRenderer } from "electron";
import type { RecordingSession, StoreRecordedSessionInput } from "../src/lib/recordingSession";
-// Asset base URL is a build-time constant per process; resolve once here so
-// the renderer can consume it synchronously. Packaged: electron-builder
-// extraResources copies public/wallpapers -> resources/wallpapers (see
-// electron-builder.json5). Unpackaged: wallpapers live at <appRoot>/public/,
-// and __dirname in dist-electron resolves to <appRoot>/dist-electron/.
-const isPackagedProcess = !process.defaultApp;
-const assetBaseDir = isPackagedProcess
- ? process.resourcesPath
- : path.join(__dirname, "..", "public");
-const assetBaseUrl = pathToFileURL(`${assetBaseDir}${path.sep}`).toString();
+// Asset base URL is passed from the main process via webPreferences.additionalArguments
+// (see windows.ts). Sandboxed preloads cannot import node:path / node:url, so we
+// can't compute it here.
+const ASSET_BASE_URL_ARG_PREFIX = "--asset-base-url=";
+const assetBaseUrlArg = process.argv.find((arg) => arg.startsWith(ASSET_BASE_URL_ARG_PREFIX));
+const assetBaseUrl = assetBaseUrlArg ? assetBaseUrlArg.slice(ASSET_BASE_URL_ARG_PREFIX.length) : "";
contextBridge.exposeInMainWorld("electronAPI", {
assetBaseUrl,
diff --git a/electron/windows.ts b/electron/windows.ts
index daa6e5e50..f94009ab0 100644
--- a/electron/windows.ts
+++ b/electron/windows.ts
@@ -1,5 +1,5 @@
import path from "node:path";
-import { fileURLToPath } from "node:url";
+import { fileURLToPath, pathToFileURL } from "node:url";
import { BrowserWindow, ipcMain, screen } from "electron";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -9,6 +9,13 @@ const VITE_DEV_SERVER_URL = process.env["VITE_DEV_SERVER_URL"];
const RENDERER_DIST = path.join(APP_ROOT, "dist");
const HEADLESS = process.env["HEADLESS"] === "true";
+// Asset base URL for renderer (wallpapers, etc.). Packaged: extraResources copies
+// public/wallpapers -> resources/wallpapers. Unpackaged: <appRoot>/public/.
+const ASSET_BASE_DIR = process.defaultApp
+ ? path.join(__dirname, "..", "public")
+ : process.resourcesPath;
+const ASSET_BASE_URL_ARG = `--asset-base-url=${pathToFileURL(`${ASSET_BASE_DIR}${path.sep}`).toString()}`;
+
let hudOverlayWindow: BrowserWindow | null = null;
ipcMain.on("hud-overlay-hide", () => {
@@ -50,6 +57,7 @@ export function createHudOverlayWindow(): BrowserWindow {
show: !HEADLESS,
webPreferences: {
preload: path.join(__dirname, "preload.mjs"),
+ additionalArguments: [ASSET_BASE_URL_ARG],
nodeIntegration: false,
contextIsolation: true,
backgroundThrottling: false,
@@ -110,6 +118,7 @@ export function createEditorWindow(): BrowserWindow {
show: !HEADLESS,
webPreferences: {
preload: path.join(__dirname, "preload.mjs"),
+ additionalArguments: [ASSET_BASE_URL_ARG],
nodeIntegration: false,
contextIsolation: true,
webSecurity: false,
@@ -156,6 +165,7 @@ export function createSourceSelectorWindow(): BrowserWindow {
backgroundColor: "#00000000",
webPreferences: {
preload: path.join(__dirname, "preload.mjs"),
+ additionalArguments: [ASSET_BASE_URL_ARG],
nodeIntegration: false,
contextIsolation: true,
},
@@ -207,6 +217,7 @@ export function createCountdownOverlayWindow(): BrowserWindow {
show: false,
webPreferences: {
preload: path.join(__dirname, "preload.mjs"),
+ additionalArguments: [ASSET_BASE_URL_ARG],
nodeIntegration: false,
contextIsolation: true,
backgroundThrottling: false,