Repository navigation
Conversation
…arem505#120) On Linux, GNOME's media controls kept a whatRust media player after WhatsApp played an alert, until whatRust quit: "Paused" (greyed out), or stuck at "Playing" when nothing was playing at all. WebKitGTK registers a page's audio as an MPRIS media player and removes it only when the element's document goes away. And once anything has played, an <audio> that merely loads registers a player too, after which every player reports "Playing" for good. WhatsApp creates its alert sounds once with new Audio(url) and keeps them: WAWebNotificationTone (an .mp3) and WAWebOutgoingMessageTone (the 40 ms send_message .m4a, created when that module loads, even with the sound turned off). So the first alert left a player, and the .m4a then pinned a "Playing" one. Reproduced on the real web.whatsapp.com in a bare WebKitGTK 2.52 view. Pausing, muting, clearing src, or turning off the MediaSession feature does not remove the player. Playing from an element in an iframe that is then removed does. media.js section 7: the page's alert elements (https:/data: <audio> in the top page, including new Audio(url)) keep their URL, but the engine never gets it, so they never load. Each play() sounds from a copy in a hidden iframe, removed when the copy ends, errors or is paused. The page's element gets play, playing, ended, pause and error as before, and reads back its src. A new alert restarts the sound. Voice messages (blob:) and calls (srcObject) keep the engine's playback. If the copy is refused, the element gets its URL and plays natively, so a sound is never lost. On the real page (not logged in), after a notification, loading the outgoing tone module and a second notification: unchanged, the player is "Paused" and then two players are stuck at "Playing"; with this change no player remains. Not covered: a voice message still leaves a player after it ends, which section 5's idle release turns into "Playing". The next alert removes it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #120. This replaces #124, which did not work in the real app; the reason is below.
Problem
On Linux, GNOME's media controls keep a whatRust media player after WhatsApp plays an alert, until whatRust quits. It shows as "Paused" (greyed out), or stuck at "Playing" while nothing is playing.
Cause
Two WebKitGTK behaviours, and how WhatsApp makes its alert sounds:
<audio>that merely loads registers a player too, and every player then reports "Playing" for good.new Audio(url)and keeps them:WAWebNotificationTone: an.mp3, 2.3 s.WAWebOutgoingMessageTone: the 40 mssend_message.m4a. It is created when that module loads, even with the outgoing sound turned off.So the first alert leaves a player, and the
.m4athen pins one at "Playing".#124 failed because it only acted on
play(). It let these elements load, and the.m4aload alone was enough to bring back a stuck player.Reproduced on the real web.whatsapp.com in a bare WebKitGTK 2.52 view, calling WhatsApp's own tone modules:
pause(),muted,currentTime = 0srcremoved +load()(what v0.7.0 does)MediaSessionfeature turned offFix
New section 7 in
media.js(Linux only):https:/data:<audio>in the top page, includingnew Audio(url)) keep their URL, but the engine never gets it, so they never load. The page still reads back its ownsrc.play()sounds from a copy in a hidden iframe. The iframe is removed when the copy ends, errors or is paused.play,playing,ended,pauseanderror, so WhatsApp's own listeners run as before. A new alert restarts the sound.blob:) and calls (srcObject) keep the engine's own playback, so section 5 handles them as before.Section 7 runs after sections 5 and 6, so section 5's idle release never sees an alert element that has media.
Results
On the real page (not logged in): a notification, then loading the outgoing-tone module, then a second notification.
master).m4aloadsThe notification still sounds: WhatsApp gets
endedafter 2.3 s, the sound's real length.Tests
media-audio.test.mjs: 7 new tests. 6 fail onmaster; the 7th checks that nothing changes inside an iframe.check.yml(on Node 24),cargo fmt --check,cargo clippy -D warnings, andcargo test(287 passed).Not covered
load()) turns it from "Paused" into "Playing". The next alert removes it. Copying voice messages like alerts would break their seek bar and progress, so I left them alone. Worth deciding how section 5 should handle this.whatrust.logshowsmedia: alert sounds play from throwaway frames. If the copy is refused there, it showsalert sound copy refused.