diff --git a/packages/core/src/audioGain.ts b/packages/core/src/audioGain.ts index cb19e7d30a..542890ca54 100644 --- a/packages/core/src/audioGain.ts +++ b/packages/core/src/audioGain.ts @@ -52,7 +52,13 @@ export function formatAudioGain(gain: number): string { * probe observes an out-of-range volume, and the shadow is removed afterwards. */ export function withUnclampedVolume(el: HTMLMediaElement, probe: () => T): T { - const descriptor = Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, "volume"); + // Guarded for non-DOM runtimes: the probe that calls this is also reachable + // from tests and tools that run outside a browser, where the clamped path is + // the right (and only) answer. + const descriptor = + typeof HTMLMediaElement === "undefined" + ? undefined + : Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, "volume"); const nativeGet = descriptor?.get; const nativeSet = descriptor?.set; if (!nativeGet || !nativeSet) return probe(); diff --git a/packages/producer/src/services/htmlCompiler.ts b/packages/producer/src/services/htmlCompiler.ts index 164c546b71..a08b55b91d 100644 --- a/packages/producer/src/services/htmlCompiler.ts +++ b/packages/producer/src/services/htmlCompiler.ts @@ -2215,10 +2215,13 @@ export async function discoverAudioVolumeAutomationFromTimeline( // the clamped value. Mirrors `withUnclampedVolume` in // packages/core/src/audioGain.ts, which the preview probe uses; this copy // exists only because the probe body is serialized into the page. - const volumeDescriptor = Object.getOwnPropertyDescriptor( - HTMLMediaElement.prototype, - "volume", - ); + // Guarded because this body is also executed directly by tests that + // stand in for a Page, where there is no DOM and no HTMLMediaElement. + // Without the descriptor the probe simply keeps the clamped path. + const volumeDescriptor = + typeof HTMLMediaElement === "undefined" + ? undefined + : Object.getOwnPropertyDescriptor(HTMLMediaElement.prototype, "volume"); const nativeVolumeGet = volumeDescriptor?.get; const nativeVolumeSet = volumeDescriptor?.set; const withUnclampedVolume = (el: HTMLMediaElement, probe: () => T): T => {