Repository navigation
Fix the web focus highlight on YouTube, and show it only for key navigation - #842
Merged
AndreyPavlenko merged 3 commits intoNov 10, 2026
Merged
Conversation
AndreyPavlenko
left a comment
Owner
There was a problem hiding this comment.
Review of the textContent fix and the key-navigation gate.
Correct
innerHTMLtotextContentfixes the Trusted Types error.:focus-visibleplus the key gate is reasonable. Keep the gate, since a script that focuses an element on load can still match:focus-visible.
Issues
- Filter accepts almost any key.
!event.isSystem()lets letters, digits, Enter and Space through, so typing in a search box turns the highlight on. The comment and description say "navigation key", but the code does not check for one. Restrict to navigation keys, e.g.KEYCODE_DPAD_UP/DOWN/LEFT/RIGHT,KEYCODE_DPAD_CENTER,KEYCODE_TAB. - Rotary input may not reach
dispatchKeyEvent. Some rotary controllers sendMotionEventACTION_SCROLL(AXIS_SCROLL) instead of key events. Testing usedadb input keyeventonly. Verify on real car hardware, or also handledispatchGenericMotionEvent. - Duplicate
<style>elements. The style is added on everypageLoaded, and YouTube is an SPA, sopageLoadedcan fire repeatedly on one document. Give the element an id and skip if present:if (document.getElementById('fermata-focus')) return; style.id = 'fermata-focus';
- Minor: if the first key arrives during page load,
document.headmay be null. Use(document.head || document.documentElement). - Minor:
keyNavigationnever resets for the view's lifetime. Probably intended, but make it a deliberate choice.
Verdict: request changes for 1 and 3. Item 2 needs hardware testing or an explicit note that it is untested.
Reviewed by Claude
YouTube only accepts TrustedHTML for innerHTML, so injecting the focus highlight style threw on every page load and focused elements were not highlighted. Set the style's textContent instead.
Once working, the highlight outlined whatever was last tapped, and a page that focuses an element when it loads (YouTube focuses its logo) got it before anything was pressed. Add the style only once a navigation key (D-pad, rotary controller, arrow keys) has been pressed, and use :focus-visible so taps after that aren't outlined either.
Only navigation keys (D-pad, Tab, rotary next/previous) and rotary scroll events turn it on, rather than any key, so typing doesn't. The style gets an id and isn't added again to the same document, and it falls back to the document element while the head doesn't exist yet.
giunatale
force-pushed
the
fix/youtube-focus-highlight
branch
from
November 8, 2026 15:47
bde54b3 to
9d7818b
Compare
Contributor
Author
Thanks! Addressed basically everything:
Also rebased on master. |
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.
The focus highlight (the outline showing which element is selected when navigating with a D-pad or a car's rotary controller) never worked on YouTube. Two commits:
addFocusHighlight()set the style throughinnerHTML, which YouTube blocks: every page load loggedFailed to set the 'innerHTML' property on 'Element': This document requires 'TrustedHTML' assignment, and nothing was highlighted. It now sets the style'stextContent, which Trusted Types doesn't restrict.:focus-visible, so taps after that aren't outlined either.Tested on a OnePlus 12 (Android 16) by inspecting Fermata's WebView: no console error, no outline when the page loads or after taps, and the outline appearing and moving through the page with
adb shell input keyevent KEYCODE_DPAD_DOWN.