← 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.

Source: Web Audio API 1.1 §1.3.4 — OfflineAudioContextOptions.length; §1.3.2 — OfflineAudioContext.length; Web Audio API 1.0 — OfflineAudioContextOptions; Chromium offline_audio_context_options.idl

OfflineAudioContextOptions.length

Accepted values

OfflineAudioContextOptions length values
lengthResult
omitted or nullIndefinite-length context; ctx.length === null
positive integerFinite context of that many sample-frames (unchanged behavior)
0NotSupportedError from the constructor
InfinityNot 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

Source: OfflineAudioContextOptions.length; 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().

Source: OfflineAudioContext.length; WPT offlineaudiocontext-incremental-rendering.html

Requirements and context

Source: Web Audio API 1.1 §1.3; Chromium offline_audio_context.cc

Lifecycle: how an indefinite context differs

Finite vs indefinite length behavior
BehaviorFinite lengthlength: null
startRendering() with no chunkSizeAll remaining framesOne render quantum (128 frames by default)
Upper bound on callsRejects (InvalidStateError) once every frame is committedNone
EndsAutomatically after the last chunkOnly via close()
complete eventOnce, after the last chunk (Chromium)Never
suspend(t) rangeMust be before the total render durationNo 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.

Source: startRendering(chunkSize) algorithm; suspend(); 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

Nullable length support
Browserlength: null / omittedNotes
Chrome / Chrome Android / WebView158Interim: ChromeStatus; BCD has options_parameter but no nullable-length sub-feature (checked 2026-11-22)
EdgeUnknownChromium-based; not separately recorded
FirefoxNoNot implemented per webstatus.dev; a missing length is expected to throw TypeError (required in the Web Audio 1.0 IDL) — not separately tested here
SafariNoNot implemented per webstatus.dev; a missing length is expected to throw TypeError (required in the Web Audio 1.0 IDL) — not separately tested here
Source: BCD api/OfflineAudioContext.json; ChromeStatus API record; webstatus.dev (Firefox/Safari not implemented)

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.

Source: startRendering(chunkSize); Web Audio API 1.1 §8

Specifications

Web Audio API 1.1 — OfflineAudioContextOptions.length · OfflineAudioContext.length, changed by WebAudio/web-audio-api#2675. Tracking: ChromeStatus 5109900936085504.