Use Hardware Codecs

Play videos using only the hardware decoders supported by your device. (Intercepts: canPlayType, isTypeSupported, addSourceBuffer, decodingInfo, VideoDecoder/AudioDecoder.isConfigSupported. Runs in every frame.)

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

Author
ktt21
Daily installs
1
Total installs
13
Ratings
0 0 0
Version
2.1.4.3
Created
2026-04-02
Updated
2026-04-04
Size
35.3 KB
Compatibility
Compatible with Firefox Compatible with Chrome Compatible with Opera Compatible with Safari Compatible with Edge
License
MIT
Applies to
All sites

Use Hardware Codecs

Play videos using only the hardware codecs supported by your device. To do this, it runs in all frames and uses 5 capture methods:

  • canPlayType;

  • isTypeSupported;

  • addSourceBuffer;

  • decodingInfo;

  • VideoDecoder/AudioDecoder.isConfigSupported.

Purpose of the script:

Force the use of hardware (HW) codecs only for video playback on all websites. The script prevents the use of software (SW) codecs, which put a strain on the CPU and drain the battery, especially on mobile devices.     When the AllowSW=true flag is set, if a video cannot be played using a hardware (HW) codec, allow playback using a software (SW) codec after several requests for SW codecs from the player.

Key Features:

  1. Intercept all codec selection paths
    • HTMLVideoElement.canPlayType
    • MediaSource.isTypeSupported
    • MediaSource.prototype.addSourceBuffer
    • navigator.mediaCapabilities.decodingInfo
    • VideoDecoder.isConfigSupported (WebCodecs API – low-level)
  2. Permanent hardware capabilities cache
    • The results of the codec tests are stored in LocalStorage.
    • A shared cache for all tabs via BroadcastChannel.
    • It does not test the same codecs every time it runs.
  3. A safe fallback to H.264 until the cache is full
    • H.264 is guaranteed to be supported by hardware on almost all devices.
  4. Blocking of SW codecs with an adaptive threshold
    • If the player persistently requests SW (for example, because it is unaware of the HW), the script temporarily enables SW via SW_BLOCK_THRESHOLD (default 6) to prevent a black screen.
  5. Works in all frames
    • Setting @all-frames true along with @inject-into page allows embedding into a cross-origin iframe (where technically possible).
    • Exception: Web Workers—scripts cannot access them, but such sites (like Rutube) typically choose to use Web Workers themselves.
  6. Minimal impact on performance
    • All tests run asynchronously and do not block rendering.
    • Once the cache is full, no retests are performed—only a check against the map.
  7. Mobile device support
    • Detects the platform and uses a simplified safe fallback to conserve data and battery life.

Advanced settings:

const DEBUG = false;       // true = detailed logs to the console

const ClearCache = false;    // true = clear the cache on the next load

const AllowSW = false;        // true = Enable software if hardware is unavailable

const SW_BLOCK_THRESHOLD = 6; // Threshold for SW requests before fallback

Code to insert into the CODECS_TO_TEST array(If a new hardware codec is found that is not in the array, a message will be displayed in the console regarding this event):

vp09.00.51.08.01.01.01.01.00', // Added the detected hardware codec to speed up startup next time

Limitations (known):

  • Web Workers – the script cannot intercept the API in a separate thread (Rutube, some modern players). However, such sites usually select HW codecs themselves.
  • Cross-origin iframes with strict security policies—sometimes the browser blocks embedding even with @all-frames.
  • localStorage is origin-isolated—the cache is not shared across different domains. For same-origin iframes, window[MAP_KEY] is used.