firefox bug scroll instead of volume#3663
Draft
MoriMomo wants to merge 4 commits intocode-charity:masterfrom
Draft
firefox bug scroll instead of volume#3663MoriMomo wants to merge 4 commits intocode-charity:masterfrom
MoriMomo wants to merge 4 commits intocode-charity:masterfrom
Conversation
Member
|
hi! @MoriMomo ( #1565 #862 (comment) ) |
Member
|
#3659 was closed |
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.
Fix: Keyboard shortcuts not working when player isn't focused (Firefox)
The Problem
yo so, so keyboard shortcuts weren't working on Firefox-based browsers (Firefox, Floorp, Librewolf, etc.) when the video player wasn't in focus. For example, if you set Up/Down arrow keys to control volume, they would just scroll the page instead of changing the volume - unless you clicked on the player first.
it kinda worked fine in Chrome, but was broken in Firefox. Pretty annoying when you're reading comments and want to quickly adjust volume!
What Was Wrong
The shortcut handler was checking
document.activeElementto see if the user was typing in an input field. This check was too strict in Firefox - it would incorrectly think the player needed focus for shortcuts to work, when really we just need to make sure the user isn't typing in a text field.The Fix
Two changes to make it work properly:
Better event target checking - Now we check
event.targetfirst (the actual element that received the keypress) instead of relying ondocument.activeElement. This is more reliable across all browsers, especially Firefox.Added document-level listeners - Added keyboard event listeners to
documentin addition towindowfor better Firefox compatibility. This ensures we catch all keyboard events, even when YouTube's complex DOM structure is involved.Testing
Tested on:
To test:
The fix still correctly prevents shortcuts from working when you're actually typing in input fields or the search box.
Files Changed
js&css/web-accessible/www.youtube.com/shortcuts.js- Updated event handler and listener initializationFixes ##3639