feat(sync): implement end-to-end media title synchronization

This commit is contained in:
MacBook
2026-04-22 18:29:53 +02:00
parent e40e2e5101
commit 67f872ffd2
3 changed files with 21 additions and 7 deletions
+6 -1
View File
@@ -236,6 +236,8 @@
const current = video.currentTime;
if (!Number.isFinite(current)) return;
const mediaTitle = (navigator.mediaSession && navigator.mediaSession.metadata) ? navigator.mediaSession.metadata.title : null;
const eventState = action === EVENTS.PLAY ? 'playing' : (action === EVENTS.PAUSE ? 'paused' : (action === EVENTS.SEEK ? 'seek' : null));
if (eventState && lastTargetState === eventState) {
@@ -249,6 +251,7 @@
payload: {
currentTime: current,
targetTime: current,
mediaTitle: mediaTitle,
timestamp: Date.now()
}
});
@@ -307,11 +310,13 @@
const heartbeatInterval = setInterval(() => {
const video = findVideo();
if (video) {
const mediaTitle = (navigator.mediaSession && navigator.mediaSession.metadata) ? navigator.mediaSession.metadata.title : null;
chrome.runtime.sendMessage({
type: 'HEARTBEAT',
payload: {
playbackState: video.paused ? 'paused' : 'playing',
currentTime: video.currentTime
currentTime: video.currentTime,
mediaTitle: mediaTitle
}
}).catch(err => {
if (err.message.includes('Extension context invalidated')) {