Skip to content

Fix AudioBuffer constructor calls in Web Audio basic concepts - #45701

Merged
wbamberg merged 2 commits into
mdn:mainfrom
alexzinnde:fix-audiobuffer-constructor-example
Sep 15, 2026
Merged

wbamberg merged 2 commits into
mdn:mainfrom
alexzinnde:fix-audiobuffer-constructor-example

Conversation

@alexzinnde

@alexzinnde alexzinnde commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Description

The two AudioBuffer examples on "Basic concepts behind Web Audio API" called the constructor with an AudioContext as the first argument:

const buffer = new AudioBuffer(context, { numberOfChannels: 2, length: 22050, sampleRate: 44100 });

That signature comes from an early draft of the spec. The current constructor takes only an options dictionary: new AudioBuffer(options). This PR removes the context argument from both examples.

Motivation

Anyone who copies the examples hits a problem right away:

  • In TypeScript, the DOM types report Expected 1 arguments, but got 2.
  • In a browser, the AudioContext gets read as the options dictionary. It has no length member, so the constructor throws a TypeError.

Additional details

Related issues and pull requests

Follow-up to #36562, which removed deprecated AudioBuffer options elsewhere but didn't change this page.

@alexzinnde
alexzinnde requested a review from a team as a code owner September 14, 2026 11:15
@alexzinnde
alexzinnde requested review from wbamberg and removed request for a team September 14, 2026 11:15
@github-actions github-actions Bot added Content:WebAPI Web API docs size/xs [PR only] 0-5 LoC changed labels Sep 14, 2026
@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Preview URLs (1 page)

(comment last updated: 2026-09-15 23:13:40)

@wbamberg wbamberg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for your PR!

I think it would be better to remove the context creation calls, as these code samples seem from the context to be just about creating the buffer. In a code sample for creating the buffer, creating the context looks odd.

When the example says:

If you use this call above, you will get a stereo buffer with two channels that, when played back on an AudioContext

...I read "this call" as referring to the code sample, which just creates the buffer, then using it in an audio context is a separate operation.

The samples are about constructing a buffer; creating a context there is
unrelated to the call the surrounding prose describes.
@alexzinnde

Copy link
Copy Markdown
Contributor Author

Good point — done. Both samples now just create the buffer; the prose still mentions playing it back on an AudioContext, which reads fine as a separate step.

@github-actions github-actions Bot added size/s [PR only] 6-50 LoC changed and removed size/xs [PR only] 0-5 LoC changed labels Sep 15, 2026

@wbamberg wbamberg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 thank you for the fix!

@wbamberg
wbamberg merged commit 0bea820 into mdn:main Sep 15, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants