This userscript dramatically reduces CPU usage on YouTube and YouTube Music. It dynamically switches between requestAnimationFrame
and MutationObserver
based on tab visibility to optimize the behavior of timer APIs like setTimeout
. The script also intelligently handles YouTube's SPA (Single Page Application) transitions to ensure continued stability and avoid freezes.
- βοΈ Hybrid trigger strategy: Automatically switches based on visibility state
- π SPA-aware repatching: Uses
yt-navigate-finish
events and DOM observation for automatic recovery - π§ Minimum delay threshold: Prevents interference with critical player functions
- π§Ό Native timers from iframe: Ensures a clean and safe execution context
- Install Violentmonkey or Tampermonkey in your browser
- Add the script using the link below: π Install this script
https://www.youtube.com/
https://music.youtube.com/
https://www.youtube.com/embed/
https://www.youtube-nocookie.com/embed/
- π Wraps
setTimeout
/setInterval
with hybrid throttling logic - π Uses
MutationObserver
in background tabs to reduce unnecessary CPU cycles - π§ Repatches after SPA navigation using DOM monitoring and timeout fallback
- π§ͺ Preserves
.toString()
on patched functions to prevent detection - π§Ό Utilizes native timers from sandboxed iframe to avoid contamination
- Written in modern ES2020 JavaScript
- No pollution of global namespace
- Uses
@inject-into: page
for seamless integration with YouTube internals
MIT License You are free to use, modify, and redistribute this script at your own risk.
π₯ Enjoy a smoother YouTube experience with a quieter CPU.