From 0d4b62c4852c80454ed3b73a5abe6fa7fa621ed0 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Tue, 11 Aug 2026 04:42:28 +0000 Subject: [PATCH] fix: guard video.play() for jsdom and fix Hls mock case mismatch - Defensive null check on video.play() return value (jsdom returns undefined) - Fix test mock: win.Hls (not win.HLS) to match viewer.js window.Hls reference - All 39/39 tests now pass --- __tests__/viewer_integration.test.mjs | 4 ++-- src/viewer/viewer.js | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/__tests__/viewer_integration.test.mjs b/__tests__/viewer_integration.test.mjs index 2d2fd43..58bb884 100644 --- a/__tests__/viewer_integration.test.mjs +++ b/__tests__/viewer_integration.test.mjs @@ -62,7 +62,7 @@ function createBrowserEnv({ storageData = {}, url = 'https://example.com/viewer/ // 'native' mode sets HLS = undefined so viewer.js takes the Safari native path. const hlsCalls = { instances: [], loaded: false }; if (hlsMode === 'mocked') { - win.HLS = class MockHLS { + win.Hls = class MockHLS { constructor(opts) { hlsCalls.instances.push({ opts, destroyed: false, events: {}, source: null, media: null }); } @@ -103,7 +103,7 @@ function createBrowserEnv({ storageData = {}, url = 'https://example.com/viewer/ } else if (hlsMode === 'native') { // Simulate Safari — window.HLS exists but isSupported() returns false. // viewer.js then falls through to video.src = manifestUrl (native HLS). - win.HLS = class MockHLS_Native { + win.Hls = class MockHLS_Native { static isSupported() { return false; // Safari has native HLS, Hls.js is not needed } diff --git a/src/viewer/viewer.js b/src/viewer/viewer.js index 74205a5..ebfaee8 100644 --- a/src/viewer/viewer.js +++ b/src/viewer/viewer.js @@ -37,7 +37,8 @@ function playHls(video, manifestUrl, panel) { if (!window.Hls || !window.Hls.isSupported()) { console.log('[goon-viewer] Native HLS support detected, using direct source'); video.src = manifestUrl; - video.play().catch(() => { /* autoplay blocked — user interaction required */ }); + const p = video.play(); + if (p) p.catch(() => { /* autoplay blocked — user interaction required */ }); return; } @@ -55,7 +56,8 @@ function playHls(video, manifestUrl, panel) { hls.on(window.Hls.Events.MANIFEST_PARSED, () => { console.log('[goon-viewer] HLS manifest parsed, playing'); - video.play().catch(() => { /* autoplay blocked */ }); + const p = video.play(); + if (p) p.catch(() => { /* autoplay blocked */ }); }); hls.on(window.Hls.Events.LEVEL_SWITCHED, () => {