Skip to content

Cleanup legacy browser support in libopenal.js. NFC - #27435

Open
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:openal_webkitAudioContext
Open

Cleanup legacy browser support in libopenal.js. NFC#27435
sbc100 wants to merge 1 commit into
emscripten-core:mainfrom
sbc100:openal_webkitAudioContext

Conversation

@sbc100

@sbc100 sbc100 commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

This brings libopenal.js inline with libwebaudio.js in a couple of ways:

  • Only support webkitAudioContext on older safari versions.
  • Drop support for new AudioContext that does not accept options.

This change should make is easy for us to remove this support once we drop support for Safari < 14.5.

@sbc100
sbc100 requested a review from kripken July 28, 2026 18:01
@sbc100
sbc100 force-pushed the openal_webkitAudioContext branch from 1bb7d7d to 6944cd8 Compare July 28, 2026 18:06
Comment thread src/lib/libopenal.js
QUEUE_INTERVAL: 25,
QUEUE_LOOKAHEAD: 100.0 / 1000.0,

#if MIN_SAFARI_VERSION < 140500

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.

MDN suggests 14.1, not 14.5?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think its 14.1 for Safari and maybe 14.5 for mobile safari? This is why we use 140500 elsewhere (e.g. libwebaudio.js).

AI seems to agree: Safari 14.1+ (Desktop) and iOS Safari 14.5+: Switched to standard window.AudioContext

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.

I verified 14.1/14.5 is on MDN.

Comment thread src/lib/libopenal.js Outdated

var AudioContext = window.AudioContext || window.webkitAudioContext;
#if MIN_SAFARI_VERSION < 140500
var AudioContext = window.AudioContext ?? window.webkitAudioContext;

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.

Why does this read window, and above we read globalThis?

@sbc100 sbc100 Jul 28, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Using globalThis in hasAudioContext avoid crash on startup on node (or other places where window does not exist). If could use window there too and make it include a function instead of a property if you prefer?

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.

Wait, why would it be good to use window there too? I would expect to use globalThis in all places, as the most supported? (node, workers, etc.)

Also, can we merge these two places together? Instead of a hasAudioContext property it could be AudioContext, and then we can just use it from there?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The reason I think its OK to use the window. for the usage path is that we expect that code to crash if its missing.

It doesn't really matter if its undefined window object or undefined window.AudioContext contructor, its still the same crash.

The reason I don't really want to merge these is that I want the usage path in the default case to look like new AudioContext().. not new getAudioContext().. it seems cleaner. Maybe I can keep that though .. let me try it.

Comment thread src/lib/libopenal.js

var ac;
try {
// Only try to pass options if there are any, for compat with browsers that don't support this

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.

Which browser versions was this an issue for?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Its really hard to know for sure but some ancient version of webkitAudioContext didn't not support options passed to it.

However, since we already don't have this change in libwebaudio.js I figure it much be at least as old as 14.5

This brings libopenal.js inline with libwebaudio.js in a couple
of ways:

- Only support webkitAudioContext on older safari versions.
- Drop support for `new AudioContext` that does not accept options.

This change should make is easy for us to remove this support
once we drop support for Safari < 14.5.
@sbc100
sbc100 force-pushed the openal_webkitAudioContext branch from 6944cd8 to f72c9cc Compare July 28, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants