globalSpeed icon indicating copy to clipboard operation
globalSpeed copied to clipboard

[Bug] Playback speed control fails on Douyin Web (douyin.com) due to dynamic MSE loading and strict playbackRate locks

Open PYH-is-wo opened this issue 2 months ago • 11 comments

Environment

  • Website: https://www.douyin.com/ (Douyin Web)
  • Extension: Global Speed

Steps to Reproduce

  1. Open douyin.com and watch the very first video (initial static render). Global Speed works fine here.
  2. Scroll down to load the 2nd, 3rd, or subsequent videos dynamically.
  3. Try to adjust the playback speed using the Global Speed extension or shortcut keys.

Expected Behavior

The playback speed of the currently active video should change, and the extension's popup should display the correct video duration and progress bar.

Actual Behavior

  1. Speed control fails: The video playback speed remains firmly at 1.0x. Any changes made via the extension are immediately overridden or ignored.
  2. Missing Progress Bar: The extension detects multiple "Douyin" video instances in the DOM, but they appear as empty shells without duration or progress bars.

Technical Details & Debugging Info

After some debugging, it appears Douyin recently updated their web player (xgplayer) architecture, which breaks standard HTML5 video speed controllers:

  1. DOM Recycling & MSE Lazy Loading: Douyin pre-renders multiple <video> tags as empty shells (without src). The actual media stream is dynamically injected via MSE (Blob URL) only when the video scrolls into the active viewport. Because the metadata (duration) is lazy-loaded, the extension fails to attach to the new stream properly, resulting in the missing progress bars in the popup menu.
  2. Aggressive State Locking: The custom player engine strictly locks the playbackRate state. Even if we use the DevTools Console to force the speed (setInterval(() => { video.playbackRate = 2.0 }, 500)), the speed still gets instantly reset to 1.0x. It seems the frontend script continuously overrides the native playbackRate at a very high frequency (likely using requestAnimationFrame).
  3. Current Workaround: The only way to successfully change the speed via code right now is to simulate a click on Douyin's native UI speed menu, bypassing the HTML5 video tag entirely (e.g., document.querySelectorAll('.douyin-player-playratio-item[data-id="2.0"]')[0].click()).

Could you please look into this to see if the extension can hook into the player differently or bypass this aggressive state resetting? Thank you for your great work!

PYH-is-wo avatar Sep 12 '26 04:09 PYH-is-wo

@PYH-is-wo Hello! It might be a gradual update because there's no issue for me. Does turning on Ghost mode in Global Speed's option speed fix the issue?

polywock avatar Sep 12 '26 04:09 polywock

I tried turning on Ghost mode and refreshed the page, but unfortunately, the issue still persists.

PYH-is-wo avatar Sep 12 '26 04:09 PYH-is-wo

Thanks for the detailed write-up — the rate-locking behaviour you describe matches what I found.

Fixed on a branch: fix/douyin-bplayer-playback-rate (commit 3e8a525)

What changed

  • src/contentScript/isolated/utils/aggressiveRateLock.ts (new) — AggressiveRateLocker re-asserts the target rate every 100 ms, so Douyin's own re-assignment does not win. It is only constructed on the hosts that need it; every other site keeps the existing path.
  • src/contentScript/isolated/utils/isWebsite.ts — adds IS_DOUYIN and IS_VKBROTHER, and excludes both from IS_NATIVE so they use the smart fullscreen path.
  • src/contentScript/isolated/ConfigSync.ts — extends the static ghost-mode list.
  • src/contentScript/isolated/SpeedSync.ts — drives the locker from the speed lifecycle, including hold-to-speed and the temporary keyboard speed.

On the two causes you list

The re-assignment loop is what makes a written value not stick, and that is what this change targets. I want to be clear that I have not independently verified whether the MSE re-attachment path contributes on top of it — the fix does not change how sources are detected or attached, so if there is a separate failure mode there, this branch would not cover it.

The same branch also fixes 百加云 BPlayer-based players (e.g. pc.vkbrother.com), where the player's own setSpeed() — clamped to 0.5x–2x and persisted to localStorage — overwrites the extension value.

npm run lint passes and the dev build succeeds. I could not open a PR: Pull Requests are disabled on this repository, so posting here instead. The branch is 2 commits ahead of master with no conflicts.

Swcmb avatar Sep 21 '26 09:09 Swcmb

@Swcmb Thanks! I tried to find the root cause in the source files. I think I found a better solution. But need to test.

Can you try this and tell me if it works on Douyin?

global-speed-chromium.zip

polywock avatar Sep 21 '26 10:09 polywock

The update got approved on the Chrome and Edge web stores. You can also test it there.

polywock avatar Sep 21 '26 13:09 polywock

Thanks! I tested your build on Edge. So far it is working well on Douyin -- no bugs found yet. I will keep testing and report back if anything comes up.

Swcmb avatar Sep 21 '26 23:09 Swcmb

@Swcmb谢谢!我尝试在源文件中查找根本原因。我觉得我找到了一个更好的解决方案,但还需要测试。

请您尝试一下,并告诉我它在抖音上是否有效?

global-speed-chromium.zip

feedback ☑️ Seek function: when first opening Douyin.com, the first video works, but after swiping down to the next video, fast-forward no longer works. Playback speed now works properly. Thank you very much to the developer for maintaining this.

12434234ad avatar Sep 22 '26 08:09 12434234ad

Following up on the remaining issue reported above — speed works after the latest update, but fast-forward/rewind stops working once you scroll past the first video.

The root cause turns out to be different from the re-assignment loop. Douyin's player feeds the decoded frames into the <video> tag as a MediaStream (WebCodecs pipeline). A MediaStream has no seekable timeline, so writes to video.currentTime are silently discarded by the browser — seek goes nowhere regardless of the rate lock. The real position lives on the same main-world player core (_player.proxy._core) that the speed fix targets, reachable only from the MAIN world.

Fixed on a branch: fix/douyin-seek (commit cceb91a), details in a3339530357/globalSpeed#1. In short:

  • MediaStream players inside .douyin-player route seeks through the Stratum bridge to the MAIN world; relative offsets are resolved there too, since the isolated world only sees the MediaStream's clock.
  • DouyinSeek resolves the same core and tries player.seek() → core.currentTime setter → core.seek(), keeping the first entry point that actually moves the decoder (verified with a tolerance check), so it adapts if Douyin changes internals again.
  • The new path only triggers on douyin.com with a confirmed MediaStream player; all other sites keep the existing code path.

36/36 tests pass (11 new cases in tools/tests/douyinSeek.test.mjs), and verified manually on douyin.com — speed and seek both work across video switches.

Since PRs are disabled on this repository, posting here for reference — feel free to reuse any of it.

a3339530357 avatar Sep 22 '26 15:09 a3339530357

@a3339530357 Thanks! It might take a few days to submit since I also made additional changes that need testing.

global-speed-chromium.zip

polywock avatar Sep 23 '26 21:09 polywock

@a3339530357 This is incredibly impressive! You've basically reverse-engineered Douyin's entire custom player pipeline.

The explanation about WebCodecs/MediaStream makes perfect sense as to why native currentTime fails on subsequent videos. Building a Stratum bridge to access the Main World and hijack the player's core directly is an absolutely brilliant workaround. The fallback logic for the seek methods is the cherry on top.

Thank you so much for digging this deep and putting so much effort into fixing both the rate lock and the seeking issue! Truly amazing work. 🙇‍♂️

PYH-is-wo avatar Sep 24 '26 05:09 PYH-is-wo

Hello! Both fixes are out: speed control on Douyin in 3.4.120, and seeking after scrolling to the next video in 3.4.124. Thanks @Swcmb and @a3339530357 for digging into Douyin's player, and everyone for testing! Closing, but feel free to reopen if it still happens on the latest version.

polywock avatar Nov 25 '26 19:11 polywock