{"record":{"id":"96cd9d205bfd43c4","repo":"moeru-ai/airi","slug":"worklet-loading-failed-err","errorCode":null,"errorMessage":"Worklet loading failed: ${err}","messagePattern":"Worklet loading failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/audio/src/audio-context/index.ts","lineNumber":73,"sourceCode":"    catch (err) {\n      console.error('AudioContext state listener error:', err)\n    }\n  })\n}\n\nasync function loadWorklets() {\n  if (!context || workletLoaded)\n    return\n\n  try {\n    await context.audioWorklet.addModule(ProcessorWorkletURL)\n    await context.audioWorklet.addModule(LibsamplerateWorkletURL)\n\n    workletLoaded = true\n  }\n  catch (err) {\n    console.error('Failed to load AudioWorklets:', err)\n    throw new Error(`Worklet loading failed: ${err}`)\n  }\n}\n\nexport async function initializeAudioContext(requestedSampleRate: number = 48000): Promise<AudioContext> {\n  // Use high quality base sample rate\n  const baseSampleRate = Math.max(requestedSampleRate, 48000)\n\n  if (context && isReady && sampleRate === baseSampleRate && workletLoaded) {\n    return context\n  }\n\n  if (isInitializing) {\n    return new Promise((resolve, reject) => {\n      const checkReady = () => {\n        if (!isInitializing) {\n          if (context && isReady && workletLoaded) {\n            resolve(context)\n          }","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/moeru-ai/airi/blob/27111382b4a79a7e983289d6e983a06af185ed0f/packages/audio/src/audio-context/index.ts#L55-L91","documentation":"loadWorklets calls AudioContext.audioWorklet.addModule for two processor worklets (ProcessorWorkletURL and LibsamplerateWorkletURL). If either addModule rejects, the error is rethrown as 'Worklet loading failed'. Common Web Audio failure modes apply: insecure context (http instead of https/localhost), 404 on the worklet URL, CORS restriction, or the browser not supporting audioWorklet.","triggerScenarios":"The worklet module URL 404s because the bundler did not emit it; the page is served over plain http on a non-localhost host so AudioWorklet is disabled; CORS blocks the cross-origin worklet script; an older browser/engine lacks audioWorklet support; a syntax error inside the worklet module causes addModule to reject.","commonSituations":"Dev server misconfigured to serve the worklet at the wrong path; production deploy over http; Safari/older WebView without audioWorklet; worklet file excluded from the build output.","solutions":["Verify ProcessorWorkletURL and LibsamplerateWorkletURL resolve with HTTP 200 in the served environment.","Ensure the page runs in a secure context (https or localhost/127.0.0.1).","Feature-detect context.audioWorklet before calling initializeAudioContext and degrade gracefully.","Check the worklet module for syntax errors and confirm the build emits the files."],"exampleFix":"// before\nawait context.audioWorklet.addModule(ProcessorWorkletURL)\nawait context.audioWorklet.addModule(LibsamplerateWorkletURL)\n\n// after\nif (typeof context.audioWorklet?.addModule !== 'function') {\n  throw new Error('AudioWorklet is not supported in this context (use a secure context / modern browser)')\n}\nawait context.audioWorklet.addModule(new URL(ProcessorWorkletURL, location.href).toString())\nawait context.audioWorklet.addModule(new URL(LibsamplerateWorkletURL, location.href).toString())","handlingStrategy":"validation","validationCode":"function canUseAudioWorklet(): boolean {\n  return typeof window !== 'undefined'\n    && 'AudioContext' in window\n    && typeof window.AudioContext?.prototype?.audioWorklet?.addModule === 'function'\n    && (window.isSecureContext ?? location.protocol.startsWith('https') || location.hostname === 'localhost')\n}","typeGuard":"function supportsAudioWorklet(ctx: AudioContext | null | undefined): ctx is AudioContext {\n  return !!ctx && typeof (ctx as any).audioWorklet?.addModule === 'function'\n}","tryCatchPattern":"try {\n  await loadWorklets()\n}\ncatch (err) {\n  // degrade to a non-worklet audio path instead of crashing\n  console.warn('AudioWorklet unavailable; falling back', err)\n}","preventionTips":["Serve the app over https or localhost so AudioWorklet is enabled.","Confirm the build emits the worklet files at the resolved URLs.","Feature-detect audioWorklet.addModule before calling initializeAudioContext."],"tags":["web-audio","audioworklet","cors","secure-context","browser"],"backgroundTag":null,"analyzedSha":"27111382b4a79a7e983289d6e983a06af185ed0f","analyzedAt":"2026-08-12T18:33:34.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}