h43z Profile picture
Interested in the unexpected - js, web, security, linux, mind, religion, drugs, history, psychology, culture, freedom and trailrunning

Oct 19, 2024, 9 tweets

The sound of silence

Many websites are using your browser's Web Audio API, but they are using it incorrectly.

The broken code leads to an constant stream of silent audio playing through your speakers or headphones.

This can drain your batteries twice as fast or ...

1/x

lead to bluetooth troubles and stop your device from going into power saving mode.

So far I know these websites have this issue

x.com if you click anywhere on the page
translate.google.com if you click listen
office.outlook.com on notification sound

The core of the problem is I think if websites create an new AudioContext in javascript (for whatever reason) and never suspend them.

I created a test website
So you can test your browser/os.

In windows you can check...editor.43z.one/sqare/i

running audio streams from your terminal with

powercfg /requests

in linux with

pactl list sinks short
(and powertop to see power consumption)

Ideally the audiostreams should become suspended and/or idle if there is no sound playing.

It seems like chrome anticipated bad website programmers and and has some internal logic to suspend the stream on it's own after 20 sec or so.

But to the website the audio context will...

still be in the state of "running".

Unfortunately firefox has no remedy for this long standing problem.

bugzilla.mozilla.org/show_bug.cgi?i…
bugzilla.mozilla.org/show_bug.cgi?i…
bugzilla.mozilla.org/show_bug.cgi?i…

One can monkey patch the AudioContext function by creating an extension which auto suspends it but this may lead to unwanted side effects. As suspended audiocontext cannot be reused by the website. (no sound will be playing)

But maybe I can come up with some solution... 🫡

I created a Firefox Extension that hooks calls to audiocontext and autosuspends the context after 4 seconds. This may lead to missed sounds but is much better than wasting CPU and battery 🔋(should not affect Videos and Audio played by html tags)

addons.mozilla.org/en-US/firefox/…

@threadreaderapp unroll

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling