mirror of
https://github.com/Shik3i/KoalaSync.git
synced 2026-09-03 22:45:21 +00:00
fix(extension): guard currentTime against non-finite values and fix seek payload mismatch
This commit is contained in:
+18
-1
@@ -55,6 +55,15 @@
|
|||||||
const video = findVideo();
|
const video = findVideo();
|
||||||
if (!video) return;
|
if (!video) return;
|
||||||
|
|
||||||
|
if (action === EVENTS.SEEK) {
|
||||||
|
const target = data ? (data.targetTime !== undefined ? data.targetTime : data.currentTime) : undefined;
|
||||||
|
if (!Number.isFinite(target)) {
|
||||||
|
reportLog(`Media Action Error: Invalid seek payload - ${JSON.stringify(data)}`, 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
data.targetTime = target;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const host = window.location.hostname.toLowerCase();
|
const host = window.location.hostname.toLowerCase();
|
||||||
const isYouTube = host.includes('youtube.com');
|
const isYouTube = host.includes('youtube.com');
|
||||||
@@ -162,6 +171,10 @@
|
|||||||
if (!payload || payload.targetTime === undefined) return;
|
if (!payload || payload.targetTime === undefined) return;
|
||||||
const video = findVideo();
|
const video = findVideo();
|
||||||
if (video) {
|
if (video) {
|
||||||
|
if (!Number.isFinite(payload.targetTime)) {
|
||||||
|
reportLog(`Media Action Error: Invalid force sync payload - ${JSON.stringify(payload)}`, 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
setTargetState('paused');
|
setTargetState('paused');
|
||||||
video.pause();
|
video.pause();
|
||||||
video.currentTime = payload.targetTime;
|
video.currentTime = payload.targetTime;
|
||||||
@@ -199,6 +212,9 @@
|
|||||||
const video = findVideo();
|
const video = findVideo();
|
||||||
if (!video) return;
|
if (!video) return;
|
||||||
|
|
||||||
|
const current = video.currentTime;
|
||||||
|
if (!Number.isFinite(current)) return;
|
||||||
|
|
||||||
const eventState = action === EVENTS.PLAY ? 'playing' : (action === EVENTS.PAUSE ? 'paused' : (action === EVENTS.SEEK ? 'seek' : null));
|
const eventState = action === EVENTS.PLAY ? 'playing' : (action === EVENTS.PAUSE ? 'paused' : (action === EVENTS.SEEK ? 'seek' : null));
|
||||||
|
|
||||||
if (eventState && lastTargetState === eventState) {
|
if (eventState && lastTargetState === eventState) {
|
||||||
@@ -210,7 +226,8 @@
|
|||||||
type: 'CONTENT_EVENT',
|
type: 'CONTENT_EVENT',
|
||||||
action,
|
action,
|
||||||
payload: {
|
payload: {
|
||||||
currentTime: video.currentTime,
|
currentTime: current,
|
||||||
|
targetTime: current,
|
||||||
timestamp: Date.now()
|
timestamp: Date.now()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user