← OfflineAudioContext incremental rendering
v158 · web audio · dictionary member + attribute reference
Indefinite length: OfflineAudioContextOptions.length and OfflineAudioContext.length
OfflineAudioContextOptions.length is now optional and nullable. Omit it (or pass null) and the context has no fixed duration: OfflineAudioContext.length reads null, each startRendering() call renders one more chunk, and the render runs until you call close(). Use this when the output length is not known up front, such as rendering until a live signal goes quiet.
Syntax
// Web Audio API 1.1 (IDL verbatim)
dictionary OfflineAudioContextOptions {
unsigned long numberOfChannels = 1;
unsigned long? length = null; // was: required unsigned long length;
required float sampleRate;
(AudioContextRenderSizeCategory or unsigned long) renderSizeHint = "default";
};
interface OfflineAudioContext : BaseAudioContext {
// ...excerpt; full interface on the overview page
readonly attribute unsigned long? length; // null for an indefinite context
};
// Usage
const ctx = new OfflineAudioContext({ sampleRate: 48000 }); // length omitted
const ctx2 = new OfflineAudioContext({ sampleRate: 48000, length: null });
ctx.length; // null
Web Audio 1.0 declared required unsigned long length;; 1.1 makes it unsigned long? length = null, and the matching length attribute becomes nullable. Chromium’s offline_audio_context_options.idl carries the same unsigned long? length = null;, and its offline_audio_context.idl declares readonly attribute unsigned long? length;. The three-argument constructor new OfflineAudioContext(numberOfChannels, length, sampleRate) keeps a non-nullable length, so an indefinite context can only be made with the options dictionary.
OfflineAudioContextOptions.length
Accepted values
length | Result |
|---|---|
omitted or null | Indefinite-length context; ctx.length === null |
| positive integer | Finite context of that many sample-frames (unchanged behavior) |
0 | NotSupportedError from the constructor |
Infinity | Not indefinite: WebIDL converts it to 0 for an unsigned long, so the constructor throws NotSupportedError. The explainer’s length: Infinity sketch predates the shipped design. |
Constructor exceptions for length
NotSupportedError—lengthis 0 after conversion (Chromium: “number of frames” below the minimum bound of 1), plus the existing channel-count,sampleRateandrenderSizeHintrange checks.InvalidStateError— the document is not fully active.TypeError— omittinglengthwhere the feature is unavailable: Web Audio 1.0 engines treat it as a required dictionary member, and Chromium with the flag off throws “Required member is undefined.” This doubles as a construction-time feature check.
OfflineAudioContext::Create and CreateOfflineAudioContext in Chromium offline_audio_context.cc; WebIDL ConvertToInt (±∞ and NaN become +0); explainer
OfflineAudioContext.length
Value
readonly attribute unsigned long? length. Returns the length passed at construction, or null for an indefinite-length context (“For undefined-length rendering, this attribute SHOULD be set to null”). It never changes as chunks render — WPT checks that ctx.length stays null after a chunk and stays the requested number after a finite render closes — so ctx.length === null is the reliable way to branch between the two modes. The attribute is read-only and takes no input: assigning to ctx.length is silently ignored in sloppy mode and throws a TypeError in strict-mode code (standard WebIDL readonly-attribute behavior). Reading ctx.length never throws, in any context state, including after close().
Requirements and context
OfflineAudioContextis[Exposed=Window]; Chromium refuses to construct it in workers.- No permission, user activation or secure context.
- Chrome 158+: constructing without
lengthis allowed only whenOfflineAudioContextIncrementalRenderingis enabled (stablein runtime_enabled_features.json5).
Lifecycle: how an indefinite context differs
| Behavior | Finite length | length: null |
|---|---|---|
startRendering() with no chunkSize | All remaining frames | One render quantum (128 frames by default) |
| Upper bound on calls | Rejects (InvalidStateError) once every frame is committed | None |
| Ends | Automatically after the last chunk | Only via close() |
complete event | Once, after the last chunk (Chromium) | Never |
suspend(t) range | Must be before the total render duration | No upper bound (Chromium skips the duration check) |
Nothing is pre-allocated for an indefinite context; rendering is pull-based and only advances by the chunks you request. Remember to close() it when finished.
CalculateEffectiveChunkSize, suspendContext and IsRenderComplete in Chromium offline_audio_context.cc
Examples
Render until the output goes silent (length: null)
const ctx = new OfflineAudioContext({ numberOfChannels: 1, sampleRate: 48000 });
console.log(ctx.length); // null: no fixed length
const src = new AudioBufferSourceNode(ctx, { buffer: impulse });
const reverb = new ConvolverNode(ctx, { buffer: roomResponse });
src.connect(reverb).connect(ctx.destination);
src.start();
const chunks = [];
for (;;) {
const chunk = await ctx.startRendering(4800); // 4864 frames: rounded up to a multiple of 128
chunks.push(chunk);
const peak = Math.max(...chunk.getChannelData(0).map(Math.abs));
if (peak < 1e-4) break; // tail has decayed
}
await ctx.close();
Detecting indefinite-length support at construction
function makeOpenEndedContext(sampleRate) {
try {
const ctx = new OfflineAudioContext({ sampleRate }); // no length
if (ctx.length === null) return ctx;
} catch (e) {
// TypeError: this engine still requires OfflineAudioContextOptions.length
}
return null; // fall back to a fixed-length render
}
Source: gendn-derived from OfflineAudioContextOptions.length and OfflineAudioContext.length; behaviour checked against WPT incremental-rendering
Browser compatibility
| Browser | length: null / omitted | Notes |
|---|---|---|
| Chrome / Chrome Android / WebView | 158 | Interim: ChromeStatus; BCD has options_parameter but no nullable-length sub-feature (checked 2026-11-22) |
| Edge | Unknown | Chromium-based; not separately recorded |
| Firefox | No | Not implemented per webstatus.dev; a missing length is expected to throw TypeError (required in the Web Audio 1.0 IDL) — not separately tested here |
| Safari | No | Not implemented per webstatus.dev; a missing length is expected to throw TypeError (required in the Web Audio 1.0 IDL) — not separately tested here |
Security and privacy
An indefinite context adds no new data exposure or permission. Because it is pull-based, an open-ended render cannot allocate or run ahead on its own: memory use is bounded by the chunks the page has requested and not yet released. The remaining cost — a rendering thread kept alive — ends with close(). The Web Audio privacy considerations apply unchanged.
Specifications
Web Audio API 1.1 — OfflineAudioContextOptions.length · OfflineAudioContext.length, changed by WebAudio/web-audio-api#2675. Tracking: ChromeStatus 5109900936085504.