From 51da169d6911a68ddaf3bd0b08c82700c24e6193 Mon Sep 17 00:00:00 2001 From: Timo <6156589+Shik3i@users.noreply.github.com> Date: Thu, 2 Jul 2026 14:18:50 +0200 Subject: [PATCH] Remove temporary Media Session interceptor and Video Event Log diagnostics Clean up the exploratory Disney+ diagnostics now that the Shadow DOM timeline/seek integration is in place: - Remove Proposal 1 (Media Session interceptor): the background.js interceptor injection and the content.js message listener capturing __koalaMediaSessionCapture, plus the now-unused mediaSessionPosition reporting in content.js and popup.js. - Remove Proposal 3 (Video Event Log): videoEventsLog, logVideoEvent(), the per-video event logging listeners, and the popup.html/popup.js UI. - Keep Proposal 2 (DOM timestamp scraper) for ongoing diagnostics. Co-Authored-By: Claude Opus 4.8 --- extension/background.js | 50 ----------------------------------------- extension/content.js | 36 ----------------------------- extension/popup.html | 6 ----- extension/popup.js | 14 ++---------- 4 files changed, 2 insertions(+), 104 deletions(-) diff --git a/extension/background.js b/extension/background.js index a33ca9c..54da4ae 100644 --- a/extension/background.js +++ b/extension/background.js @@ -1654,42 +1654,6 @@ async function devRemoteToolsAllowed() { return data.username === 'KoalaDev'; } -const mediaSessionInterceptorHosts = [ - 'disneyplus.com' -]; - -function shouldInstallMediaSessionInterceptor(url) { - try { - const host = new URL(url).hostname.toLowerCase(); - return mediaSessionInterceptorHosts.some(h => host === h || host.endsWith('.' + h)); - } catch (_e) { - return false; - } -} - -function installMediaSessionInterceptor() { - if (window.__koalaMediaSessionInterceptorInstalled) return; - window.__koalaMediaSessionInterceptorInstalled = true; - if (!navigator.mediaSession || typeof navigator.mediaSession.setPositionState !== 'function') return; - - const originalSet = navigator.mediaSession.setPositionState; - navigator.mediaSession.setPositionState = function(state) { - try { - window.postMessage({ - __koalaMediaSessionCapture: 1, - state: { - duration: state?.duration, - playbackRate: state?.playbackRate, - position: state?.position - } - }, '*'); - } catch (_e) { - // Suppress errors to not interfere with player - } - return originalSet.apply(navigator.mediaSession, arguments); - }; -} - function shouldUsePageApiSeek(url) { return typeof globalThis.koalaFindPageApiSeekProvider === 'function' && !!globalThis.koalaFindPageApiSeekProvider(url); @@ -1733,12 +1697,10 @@ function setPageApiSeekEnabled(enabled) { async function injectContentScript(tabId) { let needsPageApiSeek = false; let pageApiSeekReady = false; - let isMediaSessionCapable = false; try { const tab = await chrome.tabs.get(tabId); const url = tab?.url || ''; needsPageApiSeek = shouldUsePageApiSeek(url); - isMediaSessionCapable = shouldInstallMediaSessionInterceptor(url); } catch (_e) { // Fall through to the generic content script injection. } @@ -1761,18 +1723,6 @@ async function injectContentScript(tabId) { } } - if (isMediaSessionCapable) { - try { - await chrome.scripting.executeScript({ - target: { tabId }, - world: 'MAIN', - func: installMediaSessionInterceptor - }); - } catch (err) { - addLog(`Media Session interceptor injection failed: ${err.message}`, 'warn'); - } - } - await chrome.scripting.executeScript({ target: { tabId }, files: ['page-api-seek-overrides.js'] diff --git a/extension/content.js b/extension/content.js index 93442af..c7cbb76 100644 --- a/extension/content.js +++ b/extension/content.js @@ -62,7 +62,6 @@ let lastKnownDisneyPlusDuration = 0; let lastKnownDisneyPlusScale = 1; let lastKnownDisneyPlusStart = 0; - let videoEventsLog = []; function hostMatchesUrl(host, url) { const normalized = String(url || '') @@ -1445,9 +1444,7 @@ inShadowDom, platform, siteQuirk: getSiteQuirkDebug(video), - mediaSessionPosition: window.__koalaLastCapturedMediaPosition || null, scrapedTimestamps: getScrapedTimestamps(), - videoEventsLog: videoEventsLog, allVideos }); } else { @@ -1459,9 +1456,7 @@ allVideos, url: window.location.href, pageTitle: document.title, - mediaSessionPosition: window.__koalaLastCapturedMediaPosition || null, scrapedTimestamps: getScrapedTimestamps(), - videoEventsLog: videoEventsLog, metadata: (navigator.mediaSession && navigator.mediaSession.metadata) ? { title: navigator.mediaSession.metadata.title, artist: navigator.mediaSession.metadata.artist, @@ -1752,21 +1747,6 @@ } } - function logVideoEvent(name, video) { - try { - const time = Number.isFinite(video?.currentTime) ? video.currentTime.toFixed(2) : '?'; - const dur = Number.isFinite(video?.duration) ? video.duration.toFixed(2) : '?'; - const timeStr = new Date().toTimeString().split(' ')[0]; - const msg = `[${timeStr}] ${name} (t=${time}s, d=${dur}s)`; - videoEventsLog.unshift(msg); - if (videoEventsLog.length > 15) { - videoEventsLog.pop(); - } - } catch (_e) { - // safe - } - } - function setupListeners() { const video = findVideo(); if (video) { @@ -1782,14 +1762,6 @@ if (existing.waiting) video.removeEventListener('waiting', existing.waiting); } video._koalaHandlers = { play: handlePlay, pause: handlePause, seeked: handleSeeked, loadeddata: handleLoadedData, waiting: handleWaiting }; - if (!video._koalaLoggingAttached) { - video._koalaLoggingAttached = true; - const logEvents = ['play', 'pause', 'seeking', 'seeked', 'durationchange', 'ratechange', 'volumechange', 'waiting', 'playing']; - logEvents.forEach(evt => { - video.addEventListener(evt, () => logVideoEvent(evt.toUpperCase(), video)); - }); - } - video.addEventListener('play', handlePlay); video.addEventListener('pause', handlePause); video.addEventListener('seeked', handleSeeked); @@ -1947,14 +1919,6 @@ } }); - window.addEventListener('message', (event) => { - if (event.source !== window) return; - const data = event.data; - if (data && data.__koalaMediaSessionCapture === 1) { - window.__koalaLastCapturedMediaPosition = data.state; - } - }); - // Pull localized strings for the in-page dialog/badge (English fallback above). chrome.runtime.sendMessage({ type: 'GET_HCM_STRINGS' }, (res) => { if (chrome.runtime.lastError || !res) return; diff --git a/extension/popup.html b/extension/popup.html index b84debb..8a792e9 100644 --- a/extension/popup.html +++ b/extension/popup.html @@ -706,12 +706,6 @@ No timestamps scraped. -
- -
- No events logged. -
-
Build: __BUILD_TIMESTAMP__
diff --git a/extension/popup.js b/extension/popup.js index 765a64e..0917a3e 100644 --- a/extension/popup.js +++ b/extension/popup.js @@ -2283,10 +2283,6 @@ function refreshDebugInfo() { if (state.nativeCurrentTime != null || state.nativeDuration != null) { addField('Native Time', `${state.nativeCurrentTime ?? '?'}s / ${state.nativeDuration ?? '?'}s`); } - if (state.mediaSessionPosition) { - const pos = state.mediaSessionPosition; - addField('MediaSession Captured', `${pos.position ?? '?'}s / ${pos.duration ?? '?'}s (@ ${pos.playbackRate ?? 1}x)`, '#a855f7'); - } if (state.siteQuirk) { const quirk = state.siteQuirk; const label = quirk.name || quirk.key || 'Site'; @@ -2297,17 +2293,11 @@ function refreshDebugInfo() { if (buttons) addField(`${label} Buttons`, buttons); } const domScraperEl = document.getElementById('devtoolsDomScraperList'); - const eventLogEl = document.getElementById('devtoolsVideoEventLogList'); if (domScraperEl && state.scrapedTimestamps) { - domScraperEl.textContent = state.scrapedTimestamps.length > 0 - ? state.scrapedTimestamps.join('\n') + domScraperEl.textContent = state.scrapedTimestamps.length > 0 + ? state.scrapedTimestamps.join('\n') : 'No timestamps scraped.'; } - if (eventLogEl && state.videoEventsLog) { - eventLogEl.textContent = state.videoEventsLog.length > 0 - ? state.videoEventsLog.join('\n') - : 'No events logged.'; - } addSection('Properties'); addField('Seeking', String(state.seeking));