From 65e2f28f8eaf76350336d91d1fdb5d7ce8df25bd Mon Sep 17 00:00:00 2001 From: Hare Date: Thu, 9 Apr 2026 02:46:06 +0900 Subject: [PATCH] =?UTF-8?q?SPA=E9=81=B7=E7=A7=BB=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/injected/page-script.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/injected/page-script.ts b/src/injected/page-script.ts index bacc434..36eb954 100644 --- a/src/injected/page-script.ts +++ b/src/injected/page-script.ts @@ -16,6 +16,7 @@ w.__yt_playlist_ext_injected = true; let extractingUrl: string | null = null; + let isInitialLoad = true; let collabCache: Map = new Map(); let collabCachePlaylistId: string | null = null; @@ -64,12 +65,13 @@ const { cfg, apiKey, baseContext } = getConfig(); const authHeaders = buildAuthHeaders(cfg, baseContext); - // Try ytInitialData first (works on initial page load) - let initialData = w.ytInitialData; + // Try ytInitialData only on initial page load. + // On SPA navigation ytInitialData is stale (still holds the previous page's data), + // so we must always fetch fresh data via the browse API. + let initialData = isInitialLoad ? w.ytInitialData : null; let videoList = initialData ? findVideoListContents(initialData) : null; + isInitialLoad = false; - // If ytInitialData doesn't have the video list (SPA navigation), - // fetch the playlist data ourselves via the browse API if (!videoList) { const playlistId = getPlaylistId(); if (!playlistId) {