Repository navigation
Conversation
shortcutChapters() opened the panel whenever any hidden chapters panel existed. YouTube keeps a hidden copy next to the open panel, so a second press re-opened instead of closing, in normal view and in full screen. Decide by whether a chapters panel is expanded, and close it with that panel's own visibility button. Also stop the two errors the function threw: line 494 read two block-scoped consts outside their blocks (ReferenceError on every press), and pages with no chapters panel read .clientHeight of null. Refs code-charity#4283 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Loads the real shortcuts.js with a stub page that keeps a hidden copy of the chapters panel after opening, as YouTube does, and checks that a second press closes the panel and that no press throws. Refs code-charity#4283 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MeeTrannn
force-pushed
the
fix/4283-chapters-shortcut-toggle
branch
from
November 9, 2026 19:51
3393afc to
7478d36
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4283
What this changes and why
The "Chapters (Sidebar) On/Off" shortcut could open the chapters panel but never close it, in normal view and in full screen. After the first press, YouTube keeps a hidden copy of the chapters panel next to the open one in
ytd-watch-flexy #panels.ImprovedTube.shortcutChapterschose "open" whenever any hidden chapters panel existed, so every press after the first re-opened instead of closing.This PR changes only
ImprovedTube.shortcutChaptersinjs&css/web-accessible/www.youtube.com/shortcuts.js:#visibility-buttonbutton to close it; otherwise it opens the panel as before, through[modern-chapters] #navigation-button, keeping the old fallback and console message..clientHeightofnullthere and threw aTypeError.ReferenceError: modernChapters is not definedthat every press logged. Line 494 read twoconsts outside the blocks they were declared in.It adds
tests/unit/shortcut-chapters-toggle.test.js, which loads the realshortcuts.jsthe wayshortcuts-stuck-key-recovery.test.jsdoes, with a stub page that keeps a hidden copy of the panel after opening.Not changed: the key binding, the menu entry and translations, the keyboard handler, the chapters code in
appearance.js, andshortcutTranscript, which has the same shape and might need the same fix in a separate PR.One note on the issue as reported: on today's YouTube in Chromium, the first press already opens chapters in full screen, so I couldn't reproduce "does nothing in full screen". I tested Chromium only; if it still happens in another browser, that may need a follow-up.
Before and after
Chromium 141.0.7390.37, extension loaded unpacked, shortcut bound to H, https://www.youtube.com/watch?v=rfscVS0vtbw. H twice in normal view, then full screen, then H twice. Each line shows every
[target-id*=chapters]panel'svisibility.Before (master,
737bbfe6):After (this branch):
New test, against master's
shortcuts.jsand then on this branch:Checks
ESLint (
npx eslint --config=tests/eslint_rules.config.mjs) fails on master before linting anything, because it can't parse the config file, and CI runs it withcontinue-on-error. I didn't touch it here.AI use
I used Claude (Claude Code) to read the shortcut code with me, write the Playwright script that drove the browser reproduction, draft the fix and the test, and draft this description. I ran every step myself, checked the test fails on master and passes here, and can explain each changed line.