youtube
youtube copied to clipboard
fix: add null guards to disableAutoDubbing (fixes #3559)
Fix for #3559 — "Disable auto dubbing" TypeError crash
Problem
The disableAutoDubbing function throws TypeError: can't access property "name", track.Af is undefined when YouTube player audio tracks have malformed internal properties. This crashes the entire feature, preventing auto-dubbing from working.
Solution
Added comprehensive null guards and defensive programming throughout the function chain:
| Function | Fix |
|---|---|
disableAutoDubbing() |
Wrapped in try-catch; validates player and tracks exist and are the correct types |
hasOriginalKeyword() |
Explicit type check on getLanguageInfo result before accessing .name |
hasASR() |
Added try-catch; null-check on caption track entries |
findOriginalAudioTrack() |
Null-check on each track before passing to helper functions |
| Fallback finder | Wrapped in try-catch with explicit type checks |
Additional cleanup
- Removed stray
console.log(fallback)from production code (was logging track objects to console on every invocation)
Testing
- No behavior change for the happy path (tracks with valid
getLanguageInfo()) - Graceful degradation when tracks are malformed — no crash, feature silently skips invalid tracks