Skip to content

Allow Tone.js to use its own prepared audio context (fix firefox cancelAndHold bug)#91

Draft
nbogie wants to merge 1 commit into
processing:mainfrom
nbogie:nb-fix-firefox-cancelAndHold-bug
Draft

Allow Tone.js to use its own prepared audio context (fix firefox cancelAndHold bug)#91
nbogie wants to merge 1 commit into
processing:mainfrom
nbogie:nb-fix-firefox-cancelAndHold-bug

Conversation

@nbogie

@nbogie nbogie commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

This is a suggested, illustrative fix for the cancelAndHoldAtTime is not a function bug that we saw causing various of the examples to fail on firefox.

Minimal repeatable example of the bug is here - (fails in firefox, doesn't complain in chrome), and another slightly longer, more typical example, here.

A full root-cause-analysis is here.

It is only a draft pull request because I haven't done exhaustive testing of it on all browsers or of anything more than the 22 examples in examples/. The p5-to-tone example may show a regression (see section on testing).

What it changes:

Rather than pass tone.js a new raw native audio context, let Tone.js use its own prepared audio context, and own the audio context throughout.

Why:

Tone.js creates an AudioContext when it loads and shims it for maximum browser compatibility using standardized-audio-context. This adds various missing functions missing from firefox and safari which Tone.js expects to be able to call unconditionally, one of which is cancelAndHoldAtTime.

p5.sound currently forces it to use a raw new native audio context instead of this prepared one, and in turn this causes various of our examples to fail in firefox (and likely safari, too) under certain conditions.

Testing:

Tested with the browser based tests #85 plus #90 (which fixes a couple of errors in the examples).

All local examples then pass on firefox, and continue to pass on chrome, with one exception examples/p5-to-tone/. This looks like a newly introduced regression.

AI disclosure:

Claude Code was used in the investigation and preparation of this solution.

Code review, testing, and this write-up by me, a human.

Tone.js sets up its audio context with standardized-audio-context wrapper which polyfills for various missing functions missing from firefox and safari which Tone.js expects to be able to call unconditionally.  Let Tone.js own the audio context throughout.
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.

1 participant