From 931314b0f0ac831b4ad27db243ed7f0a4b02d08d Mon Sep 17 00:00:00 2001 From: KrX3D Date: Fri, 28 Aug 2026 20:50:21 +0200 Subject: [PATCH] fix: retry who's-watching suppression if localStorage isn't ready yet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported on-device (standalone, Tizen 6.5): after a full TV power cycle, the app sometimes lands on the profile-selector screen instead of resuming video playback. Not confirmed via a log yet (no direct evidence of the exact mechanism), but this is a plausible, testable cause: disableWhosWatching() only ever ran once, synchronously, at script load, bailing out immediately with just a console warning if YouTube's own recurring_actions localStorage key wasn't there yet. A power cycle is a much slower cold boot than a simple app restart — a genuine race against YouTube's own code creating that key exists on a cold boot that doesn't exist on a warm restart (where the key already exists from before). Now retries up to 10 times, 500ms apart, before giving up. --- mods/ui/disableWhosWatching.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/mods/ui/disableWhosWatching.js b/mods/ui/disableWhosWatching.js index ff7eea63..d05fd2d9 100644 --- a/mods/ui/disableWhosWatching.js +++ b/mods/ui/disableWhosWatching.js @@ -9,14 +9,33 @@ configChangeEmitter.addEventListener('configChange', (event) => { let interval; -function disableWhosWatching(value) { +// Reported on-device (standalone, Tizen 6.5): after a full TV power cycle +// (not just closing/reopening the app), the profile-selector screen +// sometimes shows up even though this is supposed to keep suppressing it. +// A power cycle is a much slower cold boot than a simple app restart — this +// function only ever ran once, synchronously, at script load, so if +// YouTube's own code hadn't created the recurring_actions localStorage key +// yet by the time this ran (a genuine race on a slow cold boot, not present +// on a warm restart where the key already exists from before), this bailed +// out immediately with just a console warning, leaving suppression never +// applied for that launch. Bounded retry so a slow cold boot gets more than +// one chance before giving up. +const MAX_RETRY_ATTEMPTS = 10; +const RETRY_DELAY_MS = 500; + +function disableWhosWatching(value, attempt) { + if (attempt === undefined) attempt = 0; // FIX: Wrap the entire function body — localStorage may be missing or corrupt // (e.g. first boot, reset, or storage quota hit) and JSON.parse can throw. let LeanbackRecurringActions; try { const raw = localStorage['yt.leanback.default::recurring_actions']; if (!raw) { - console.warn('[disableWhosWatching] recurring_actions not found in localStorage — skipping'); + if (attempt < MAX_RETRY_ATTEMPTS) { + setTimeout(() => disableWhosWatching(value, attempt + 1), RETRY_DELAY_MS); + return; + } + console.warn('[disableWhosWatching] recurring_actions not found in localStorage after retrying — giving up'); return; } LeanbackRecurringActions = JSON.parse(raw);