Skip to content

web: Add background tick mode to keep player running in hidden tabs#23395

Merged
kjarosh merged 18 commits into
ruffle-rs:masterfrom
robinmiau:robinmiau-patch-4
Apr 20, 2026
Merged

web: Add background tick mode to keep player running in hidden tabs#23395
kjarosh merged 18 commits into
ruffle-rs:masterfrom
robinmiau:robinmiau-patch-4

Conversation

@robinmiau
Copy link
Copy Markdown
Contributor

@robinmiau robinmiau commented Apr 5, 2026

Related to #7289
Related to #10527

Previously, when a tab was hidden, the requestAnimationFrame loop would stop, halting game logic and audio. This adds a background tick mode that replaces the RAF loop with a Web Worker-based tick loop when the tab becomes hidden, keeping the player running.

When the tab becomes visible again, the background worker is terminated, the normal RAF loop is restarted, and the AudioContext is explicitly resumed since browsers may auto-suspend it in background tabs.

New configuration option

A new backgroundExecutionMode config option controls background playback behavior:

Value Behavior
"mainThread" Uses the Web Worker tick loop when the tab is hidden
"none" Disables background execution entirely (default)

Example usage:

window.RufflePlayer.config = {
  "backgroundExecutionMode": "mainThread"
};

Notes

  • The visibilitychange listener no longer passes an explicit false as the third argument, since that is the default and every other listener in the file omits it.
  • Tested in the latest version of Chrome, where it ran reliably and smoothly in the background.

@kjarosh kjarosh added A-web Area: Web & Extensions newsworthy T-compat Type: Compatibility with Flash Player labels Apr 5, 2026
@kjarosh
Copy link
Copy Markdown
Member

kjarosh commented Apr 5, 2026

Note that we still support Firefox 94 and Safari 14.1 which do not support locks. We can either drop support for older versions or handle the missing API.

Comment thread web/packages/core/src/internal/player/inner.tsx Outdated
@kjarosh
Copy link
Copy Markdown
Member

kjarosh commented Apr 5, 2026

It would be really nice to have that covered by tests, it's a pretty important piece of code.

@kjarosh kjarosh added the squash-on-merge Marks a PR to be squashed before merging. label Apr 6, 2026
Comment thread web/packages/core/src/internal/player/inner.tsx Outdated
Comment thread web/packages/core/src/internal/player/inner.tsx
Comment thread web/packages/core/src/internal/player/inner.tsx
if (mode === BackgroundExecutionMode.MainThread) {
this.instance.enable_background_tick_mode();
if (this.lastActivePlayingState) {
this.startBackgroundTick();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably worth handling the situation where we fail to create a worker here and fall back to pausing the movie.

Comment thread web/packages/core/src/public/config/load-options.ts
Comment thread web/packages/extension/assets/options.html Outdated
Comment thread web/packages/extension/assets/options.html
Comment thread web/packages/core/src/internal/player/inner.tsx Outdated
Copy link
Copy Markdown
Member

@kjarosh kjarosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I'll do some tests and I think we'll be ready to merge this

@Pandalusion
Copy link
Copy Markdown

Pandalusion commented Apr 18, 2026

Tested this on Habbo Flash Client , which normally disconnects after around 50 seconds when minimised or in the background. It doesn't disconnect and continues pinging websockify, no disconnections even after several hours

@kjarosh kjarosh force-pushed the robinmiau-patch-4 branch from e29224e to 007d9b2 Compare April 20, 2026 08:04
@kjarosh kjarosh enabled auto-merge (squash) April 20, 2026 08:07
@kjarosh
Copy link
Copy Markdown
Member

kjarosh commented Apr 20, 2026

Thank you!

@kjarosh kjarosh merged commit 008064f into ruffle-rs:master Apr 20, 2026
26 checks passed
Hancock33 added a commit to Hancock33/batocera.piboy that referenced this pull request Apr 26, 2026
-------------------------------------------------------------------------------------
azahar.mk b3ee2d8ac5a69e3bf310a67e716606dd98c4c14c # Version: Commits on Apr 21, 2026
-------------------------------------------------------------------------------------
tools/README.md: Re-updated release checklist

Knew I'd forgotten something (:,

----------------------------------------------------
clk.mk 2026-04-21 # Version: Commits on Apr 21, 2026
----------------------------------------------------
On the Thomson machines:

* there is now some support for LEP and SAP files;

* Memo5 images with the extension ROM are now recognised and appropriately routed; and

* an attempt at emulation of the MO6 and Prodest 128 is now present, though I don't yet trust it enough for it to be a trusted target for software. You'll have to select it yourself.

On the Master System:

* save RAM is now present, though unretained; and

* a substantial issue in the display of fixed right-hand columns has been corrected.

Together these fix all issues with the recent [Road Fighter](https://www.smspower.org/Homebrew/RoadFighter-SMS) release.,

------------------------------------------------------------------------------------------
duckstation.mk e3f6b48225b27acb0888cf28df4f2a48d9e8c287 # Version: Commits on Apr 21, 2026
------------------------------------------------------------------------------------------
GameDB: Sol Divide does not support analog (#3716),

-----------------------------------------------------------------------------------
eden.mk a0bb6324c0a11bf6578fe7d6951d08968fc16e12 # Version: Commits on Apr 21, 2026
-----------------------------------------------------------------------------------
[dist, android] Update translations from Transifex for Apr 21 (#3871)

----------------------------------------------------
pcsx2.mk v2.7.280 # Version: Commits on Apr 21, 2026
----------------------------------------------------
- [GS/DX11: Clean up srv binding, srv conflict unbinding, and read only dsv clear.](PCSX2/pcsx2#14339)

------------------------------------------------------------------------------------
rpcs3.mk 1ca8ab393aacae3e5cd736427b6aea1e57d73ee2 # Version: Commits on Apr 21, 2026
------------------------------------------------------------------------------------
sys_fs: Fix O_CREATE and O_TRUNC for BDVD,

---------------------------------------------------------------------------------------
touchhle.mk 1f1b63accfa2dce85a4dc99c43cbcd5b011ffbd0 # Version: Commits on Apr 20, 2026
---------------------------------------------------------------------------------------
Remove RET_FLAG check for zero stack on dyld call workaround

Games can use stubs for linked functions that are either 4, 12 or 16

bytes. The current version only runs with 12 and 16 byte stubs.

Removing the RET_FLAG check ensures the workaround is applied

regardless of the stub size.

Change-Id: I54dbb036079b34ed2d5103593c0497d461f2e66e,

-------------------------------------------------------------------------------------
ikemen.mk dece45c0e1d67586810f2f11cb40e15460e1a22b # Version: Commits on Apr 21, 2026
-------------------------------------------------------------------------------------
Merge pull request #3532 from ikemen-engine/fix3

fix: desync not ending netplay session,

---------------------------------------------------------------
ruffle.mk nightly-2026-04-21 # Version: Commits on Apr 21, 2026
---------------------------------------------------------------
## What's Changed

* web: Add background tick mode to keep player running in hidden tabs by @robinmiau in ruffle-rs/ruffle#23395

* avm1: Add Value::from_usize_lossy and Value::from_u64_lossy by @kjarosh in ruffle-rs/ruffle#23476

**Full Changelog**: ruffle-rs/ruffle@nightly-2026-04-20...nightly-2026-04-21,

----------------------------------------------------------------------------------------------------
gamenetworkingsockets.mk 37f28a7971054fe762b8a4392942c7437db6da6d # Version: Commits on May 08, 2025
----------------------------------------------------------------------------------------------------
USE_STEAMWEBRTC=ON now actually uses WebRTC instead of the native ICE client,

------------------------------------------------------------------------------------
cdogs.mk 84aa57c71381bf77aef452599641b72543822ae5 # Version: Commits on Apr 21, 2026
------------------------------------------------------------------------------------
Poison bubble #681,

------------------------------------------------------------------------------------------
devilutionx.mk 54cb21603c84572d4a6d657aaf64b87062115071 # Version: Commits on Apr 21, 2026
------------------------------------------------------------------------------------------
Add CPACK to build instructions for MinGW,

------------------------------------------------------------------------------------------
fallout2-ce.mk 3849b4ea17164f0059610d88ad76f7922180845a # Version: Commits on Apr 21, 2026
------------------------------------------------------------------------------------------
Add AI agent related files to git ignore (#395)

* Add AI agent related files to git ignore

* Add gemini.md,

--------------------------------------------------------------------------------------
omf2097.mk 34b942f1c62c9a17689c3bf45f15268764333e17 # Version: Commits on Apr 21, 2026
--------------------------------------------------------------------------------------
Allow Airborne Stasis'd Enemy to be hit (#1383)

* Add rectest

* Add exception to rehit mode check for stasis hits,

----------------------------------------------------------------------------------------
retroarch.mk f121e827c8e30363a0344e27a5430054bcac9f0b # Version: Commits on Apr 21, 2026
----------------------------------------------------------------------------------------
(RWEBP) The loop filter is essentially disabled for this image (seg_lf=[4,0,0,0] with seg_abs=1 means only seg=0 MBs get a very mild filter, while seg=1/2/3 MBs have zero filtering). This means the loop filter is NOT the cause of the remaining pixel differences.

The ~105 mean diff comes from the cascading effect of a small prediction/IDCT rounding difference that starts at sub-block (0,2) and compounds through all 805 macroblocks. The decoder is structurally complete with all 18 bugs fixed and a simple loop filter implementation added. The output file is ready for testing.,

---------------------------------------------------------------------------------------
vpinball.mk 0cdf78f35e7fe42047e65bd57044b0e848a3d167 # Version: Commits on Apr 21, 2026
---------------------------------------------------------------------------------------
iOS: fix crash when upgrading from App Store ver 10.8.1.2612,

-------------------------
spirv-cross.mk  NULL-NULL
-------------------------
No commit found for SHA: vulkan-tmp-1.4.349,

----------------------------------------------------------------------------------------
doomretro.mk 22b90db46ee69425071a451c32e3fb5868d41204 # Version: Commits on Apr 21, 2026
----------------------------------------------------------------------------------------
Update releasenotes.md,

------------------------------------------------------------------------------------------
xash3d-fwgs.mk e2d5bea327990ec1fe291d9a481d93ad8db33af4 # Version: Commits on Apr 21, 2026
------------------------------------------------------------------------------------------
ref: cleanup unused functions,

---------------------------------------------------------------------------------------------
libretro-citra.mk b3ee2d8ac5a69e3bf310a67e716606dd98c4c14c # Version: Commits on Apr 21, 2026
---------------------------------------------------------------------------------------------
tools/README.md: Re-updated release checklist

Knew I'd forgotten something (:,

---------------------------------------------------------------------------------------------
libretro-fbneo.mk 5f5c33b1b0ccf3ff623d6836a84cd032b4a876d4 # Version: Commits on Apr 21, 2026
---------------------------------------------------------------------------------------------
Make \RETRO_ERROR_MESSAGES_12\ be used correctly (#1119),

--------------------------------------------------------------------------------------------------
libretro-gearsystem.mk 3df5ab5847795bdbd3f7df7495341609d4652f7d # Version: Commits on Apr 21, 2026
--------------------------------------------------------------------------------------------------
Fix BIOS loading and buffer padding,

--------------------------------------------------------------------------------------------
libretro-pc98.mk 1edeb9319165a429c05bb666b925c212fee4cfec # Version: Commits on Apr 21, 2026
--------------------------------------------------------------------------------------------
20260421,

---------------------------------------------------------------------------------------------
libretro-vba-m.mk 5d9cd29130c0b60239d2ca69af7826b3ff2eee66 # Version: Commits on Apr 21, 2026
---------------------------------------------------------------------------------------------
ci: fix dangling reference warning

Fix CI fail from a dangling reference warning.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>,

-------------------------------------------------------------------------------------------
glsl-shaders.mk f374397e384b80d768ee578ac09018efc6fdeced # Version: Commits on Apr 21, 2026
-------------------------------------------------------------------------------------------
Changes to zfast-crt-composite (#558)

* Update ultra-potato.glsl

* Update zfast_crt_composite.glsl

* Update zfast-composite.glslp,

--------------------------------------------------------------------------------------------
slang-shaders.mk 6edb8f0c6c40b334f9098b2bbe94e0c67b18289e # Version: Commits on Apr 21, 2026
--------------------------------------------------------------------------------------------
some last minute fixes (#902)

* Tune 2 presets, sorry

* fix early exit condition,
@kjarosh kjarosh removed the squash-on-merge Marks a PR to be squashed before merging. label May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-web Area: Web & Extensions newsworthy T-compat Type: Compatibility with Flash Player

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants