Skip to content

Fix auto video recovery and auto-dubbed audio track handling - #4179

Merged
ImprovedTube2 merged 15 commits into
code-charity:masterfrom
communism420:master
Aug 5, 2026
Merged

Fix auto video recovery and auto-dubbed audio track handling#4179
ImprovedTube2 merged 15 commits into
code-charity:masterfrom
communism420:master

Conversation

@communism420

@communism420 communism420 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes two player-related issues:

  • Makes Auto video recovery initialize correctly and recover only confirmed playback stalls.
  • Makes Disable auto dubbing reliably exclude automatically generated audio tracks while preserving human-made dubbed tracks.

Auto video recovery

  • Initializes the feature during extension startup.
  • Attaches cleanly to the active YouTube <video> element and cleans up listeners/timers when disabled or when the player changes.
  • Does not treat normal startup buffering as a playback failure.
  • Retries playback before calling video.load(), avoiding unnecessary stream resets and slow video startup.
  • Restores the previous playback position after a confirmed reload.
  • Avoids logging expected play() rejections as extension errors.

Auto dubbing and audio tracks

  • Distinguishes auto-dubbed tracks from human-made dubbed tracks.
  • When auto dubbing is disabled:
    • selects the configured preferred language only if a non-auto-dubbed track exists;
    • otherwise falls back to the original audio track;
    • never switches repeatedly when the player cannot report the current track.
  • Hides only the auto-dubbing section in the audio-track menu, keeping manually dubbed tracks visible.
  • Recalculates both YouTube menu containers after filtering auto-dubbed entries, preventing a stale oversized audio-track menu.
  • Preserves a human-made dub when its visible language label is identical to an automatic track.

First-open audio menu layout

  • Recalculates the filtered audio-track menu's natural width and height on its first opening, without leaving a stale scrollable or clipped state.
  • Targets only the panel currently visible inside YouTube's animated settings popup, so returning to the main settings menu restores its native dimensions.
  • Clears stale scroll offsets and inner-panel height/overflow left by the removed auto-dubbing section, while preserving scrolling for genuinely long manual track lists.
  • Reapplies the filtered layout after YouTube's delayed class/style updates and restores only extension-owned styles.

Tests

  • Added regression coverage for:
    • normal startup buffering vs. an actual stalled video;
    • playback retry and reload behavior;
    • human vs. auto-dubbed preferred-language selection;
    • original-track fallback;
    • menu filtering and width restoration;
    • first-open audio-menu sizing, stale-scroll cleanup, active-panel detection, and safe native-layout restoration;
    • identical visible labels for human-made and auto-dubbed tracks.

@communism420 communism420 self-assigned this Jul 11, 2026
@ImprovedTube2 ImprovedTube2 added the untested please test. (also applies to proactively merged pull requests.) label Jul 13, 2026
@ImprovedTube2

Copy link
Copy Markdown
Collaborator

hi and thank you!😮@communism420


Functions only beloning to one specific feature can be nested in the feature to be defined conditionally only. Unless you predict them being useful for other features too.


ImprovedTube.disableAutoDubbing = function () {
if (this.storage.disable_auto_dubbing !== true) {
this.stopAutoDubbingGuard();
return;
}

this is rare, stopAutoDubbingGuard() can run called by our storage listener, when the toggle is switched off while on youtube, if ever


if (ImprovedTube.storage.disable_auto_dubbing === true) { ImprovedTube.disableAutoDubbing(); }

we can keep this.

@communism420

Copy link
Copy Markdown
Contributor Author

@ImprovedTube2 Hi, thank you for the review! I’ve addressed the points you mentioned:

  • restored conditional initialization of disableAutoDubbing;
  • moved stopAutoDubbingGuard and enforceAutoDubbingPolicy inside the feature, so they are defined only after the feature is enabled;
  • the storage listener now stops and cleans up the guard directly when the toggle is switched off;
  • kept the shared audio-track helpers at the top level because they are also used by the preferred-language, default-language, and audio-menu features.

I also added regression tests for conditional initialization and complete guard cleanup. All 99 tests and the GitHub Actions check pass.

Please let me know if this matches the intended structure. Thank you!

@communism420

Copy link
Copy Markdown
Contributor Author

@ImprovedTube2
Hi again! Can you merge this PR if everything in it matches the intended structure?

@communism420

Copy link
Copy Markdown
Contributor Author

Added both service_worker and scripts to the background section in manifest.json.

This makes temporary loading in Firefox much more convenient for testing (otherwise it fails with the classic "background.service_worker is currently disabled" error). Chrome ignores the scripts field, so nothing breaks on Chromium-based browsers.

Also, it might slightly increase the chances that this PR will be noticed and approved

@communism420

Copy link
Copy Markdown
Contributor Author

@ImprovedTube2

I’ve fixed another edge case in the filtered auto-dubbing audio menu.

When navigating back from the Audio track submenu, YouTube could detach the outgoing panel and measure the main settings menu while the compact audio-menu constraints were still active. As a result, the main menu remained incorrectly reduced in both Brave and Firefox.

The update:

  • restores the shared popup layout before YouTube measures the main menu;
  • preserves references to the affected elements so their native styles can still be restored after the audio panel is detached;
  • ignores outgoing animated panels;
  • prevents stale delayed layout callbacks from shrinking the main menu again;
  • adds regression tests for back navigation, detached panels, outgoing animations, and queued layout corrections.

The compact filtered audio menu continues to work as before, while the main settings menu now immediately returns to its native size.

Validation: all 22 test suites and 100 tests pass, along with ESLint and syntax checks.

@communism420

Copy link
Copy Markdown
Contributor Author

I’ve fixed a remaining timing race when returning from the filtered Audio track submenu to the main settings menu.

The previous restoration could still preserve an intermediate compact height written during YouTube’s transition. This caused the main settings menu to remain slightly shorter than its native size.

The follow-up update:

  • force-restores the shared popup constraints before YouTube measures the main menu;
  • immediately marks the outgoing audio panel so mutation callbacks cannot reapply its compact layout;
  • adds a focus-based fallback for keyboard and programmatic navigation;
  • selects the most visible settings panel instead of allowing a stale audio panel to retain layout ownership;
  • safely handles panel detachment, reuse, and same-batch DOM reparenting;
  • preserves dimensions already recalculated by YouTube during delayed cleanup;
  • adds regression coverage for these transition scenarios.

Validation: all 22 test suites and 101 tests pass, along with ESLint, JavaScript syntax, and diff checks.

@ImprovedTube2

Copy link
Copy Markdown
Collaborator

hi, thank you! @communism420, so sorry for the delay!
if is not enabled, a feature needs to clean up nothing either and can run 0 lines

@communism420

Copy link
Copy Markdown
Contributor Author

@ImprovedTube2 Hi, thank you for the clarification, and no worries about the delay. I’m sorry for the delay on my side as well.

I’ve updated both affected startup paths according to your guidance:

  • autoVideoRecovery() is now called only when auto_video_recovery === true;
  • observeAutoDubbedMenu() is now called only when hide_auto_dubbed_options === true.

Therefore, when either feature is disabled during initialization, its entry point is not called and performs no work. Cleanup remains only for an actual enabled → disabled transition, where existing timers, observers, event listeners, and modified menu state must be removed.

I also audited the PR for the same pattern and found no other new unconditional startup calls for these features. Regression tests were added to prevent this behavior from returning.

Validation: all 23 test suites and 109 tests pass, along with ESLint, JavaScript syntax, and diff checks.

Thank you for pointing this out!

@ImprovedTube2

ImprovedTube2 commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Thank you! @communism420

Did you test in the browser?

delay on my side

little yet!

looking forward

@communism420

communism420 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Thank you! @communism420

Did you test in the browser?

delay on my side

little yet!

looking forward

Hi!
Yes, I've tested everything and I'm currently using my version

@ImprovedTube2

Copy link
Copy Markdown
Collaborator

nice!

@ImprovedTube2

Copy link
Copy Markdown
Collaborator

Validation: all 22 test suites and 101 tests pass, along with ESLint, JavaScript syntax, and diff checks.

(Sorry we're not yet filtering LLM stuff so it multiplies the flood of characters (scroll height) and am getting used to the majority being untested. Thus (by now) looking forward short messages (human indicator) and color coded PR code to distinguish various (non-)(human) authors.)

@ImprovedTube2
ImprovedTube2 merged commit 55e3f68 into code-charity:master Aug 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

untested please test. (also applies to proactively merged pull requests.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants