Skip to content

ensureBrowserProcess

Ensures the bundle runs against a process global that browser-targeting packages recognize.

Serialized into the emitted banner, so it never runs in the builder process — but it is an ordinary function here, so it is unit-tested directly rather than by evaluating the banner text.

Fills in the keys MISSING from a host-provided process rather than replacing or skipping it. Obsidian Mobile exposes a partial process, and the whole-object guards this replaced (if (globalThis.process) { return; } / globalThisRecord['process'] ??= …) took that as “already shimmed”, so browser never landed. The bundled debug package then selected its Node entry point, which calls require('util').deprecate() at module top level, and on mobile the patched require returns {} — so the plugin threw before its onload ran.

A real Node or Electron process is left completely untouched. process.versions.node is the signal for it, and — unlike globalThis.app.isMobile — it is self-contained, so it also holds in the Node CLI bundles this banner is emitted into, where no Obsidian app exists.

Import:

import { ensureBrowserProcess } from 'obsidian-dev-utils/script-utils/bundlers/esbuild-impl/preprocess-plugin';

Signature:

function ensureBrowserProcess(): void

Returns: void