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. -