Implement temporary Media Session interceptor diagnostics for Disney+ and restore Netflix sessionId lookup guard

This commit is contained in:
Timo
2026-07-02 13:19:47 +02:00
parent ce522e2ab7
commit 066d2c9407
3 changed files with 66 additions and 2 deletions
+52 -1
View File
@@ -1654,6 +1654,42 @@ 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);
@@ -1697,9 +1733,12 @@ function setPageApiSeekEnabled(enabled) {
async function injectContentScript(tabId) {
let needsPageApiSeek = false;
let pageApiSeekReady = false;
let isMediaSessionCapable = false;
try {
const tab = await chrome.tabs.get(tabId);
needsPageApiSeek = shouldUsePageApiSeek(tab?.url || '');
const url = tab?.url || '';
needsPageApiSeek = shouldUsePageApiSeek(url);
isMediaSessionCapable = shouldInstallMediaSessionInterceptor(url);
} catch (_e) {
// Fall through to the generic content script injection.
}
@@ -1722,6 +1761,18 @@ 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']
+10 -1
View File
@@ -1396,6 +1396,7 @@
function applyAudioSettings(videoEl, settings) {
const mergedSettings = mergeAudioSettings(settings);
if (!mergedSettings.enabled || !mergedSettings.compressor?.enabled) {
@@ -1406,7 +1407,8 @@
}
const chain = setupAudioChain(videoEl);
if (!chain) return;
@@ -1804,6 +1806,13 @@
video.pause();
} else if (action === EVENTS.SEEK) {
seekVideo(video, data.targetTime, data.delta);
}
} catch (e) {
reportLog(`Media Action Error: ${e.message}`, 'error');
}
}
+4
View File
@@ -2283,6 +2283,10 @@ 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';