mirror of
https://github.com/Shik3i/KoalaSync.git
synced 2026-09-01 05:29:22 +00:00
Implement temporary Media Session interceptor diagnostics for Disney+ and restore Netflix sessionId lookup guard
This commit is contained in:
+52
-1
@@ -1654,6 +1654,42 @@ async function devRemoteToolsAllowed() {
|
|||||||
return data.username === 'KoalaDev';
|
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) {
|
function shouldUsePageApiSeek(url) {
|
||||||
return typeof globalThis.koalaFindPageApiSeekProvider === 'function' &&
|
return typeof globalThis.koalaFindPageApiSeekProvider === 'function' &&
|
||||||
!!globalThis.koalaFindPageApiSeekProvider(url);
|
!!globalThis.koalaFindPageApiSeekProvider(url);
|
||||||
@@ -1697,9 +1733,12 @@ function setPageApiSeekEnabled(enabled) {
|
|||||||
async function injectContentScript(tabId) {
|
async function injectContentScript(tabId) {
|
||||||
let needsPageApiSeek = false;
|
let needsPageApiSeek = false;
|
||||||
let pageApiSeekReady = false;
|
let pageApiSeekReady = false;
|
||||||
|
let isMediaSessionCapable = false;
|
||||||
try {
|
try {
|
||||||
const tab = await chrome.tabs.get(tabId);
|
const tab = await chrome.tabs.get(tabId);
|
||||||
needsPageApiSeek = shouldUsePageApiSeek(tab?.url || '');
|
const url = tab?.url || '';
|
||||||
|
needsPageApiSeek = shouldUsePageApiSeek(url);
|
||||||
|
isMediaSessionCapable = shouldInstallMediaSessionInterceptor(url);
|
||||||
} catch (_e) {
|
} catch (_e) {
|
||||||
// Fall through to the generic content script injection.
|
// 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({
|
await chrome.scripting.executeScript({
|
||||||
target: { tabId },
|
target: { tabId },
|
||||||
files: ['page-api-seek-overrides.js']
|
files: ['page-api-seek-overrides.js']
|
||||||
|
|||||||
+10
-1
@@ -1396,6 +1396,7 @@
|
|||||||
|
|
||||||
function applyAudioSettings(videoEl, settings) {
|
function applyAudioSettings(videoEl, settings) {
|
||||||
|
|
||||||
|
const mergedSettings = mergeAudioSettings(settings);
|
||||||
|
|
||||||
if (!mergedSettings.enabled || !mergedSettings.compressor?.enabled) {
|
if (!mergedSettings.enabled || !mergedSettings.compressor?.enabled) {
|
||||||
|
|
||||||
@@ -1406,7 +1407,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const chain = setupAudioChain(videoEl);
|
||||||
|
|
||||||
if (!chain) return;
|
if (!chain) return;
|
||||||
|
|
||||||
@@ -1804,6 +1806,13 @@
|
|||||||
video.pause();
|
video.pause();
|
||||||
|
|
||||||
} else if (action === EVENTS.SEEK) {
|
} else if (action === EVENTS.SEEK) {
|
||||||
|
seekVideo(video, data.targetTime, data.delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
|
||||||
|
reportLog(`Media Action Error: ${e.message}`, 'error');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2283,6 +2283,10 @@ function refreshDebugInfo() {
|
|||||||
if (state.nativeCurrentTime != null || state.nativeDuration != null) {
|
if (state.nativeCurrentTime != null || state.nativeDuration != null) {
|
||||||
addField('Native Time', `${state.nativeCurrentTime ?? '?'}s / ${state.nativeDuration ?? '?'}s`);
|
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) {
|
if (state.siteQuirk) {
|
||||||
const quirk = state.siteQuirk;
|
const quirk = state.siteQuirk;
|
||||||
const label = quirk.name || quirk.key || 'Site';
|
const label = quirk.name || quirk.key || 'Site';
|
||||||
|
|||||||
Reference in New Issue
Block a user