{"record":{"id":"4a6e773eb5f6cd84","repo":"heygen-com/hyperframes","slug":"beat-analyzer-not-loaded","errorCode":null,"errorMessage":"beat analyzer not loaded","messagePattern":"beat analyzer not loaded","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/beats/headlessAnalyzer.ts","lineNumber":90,"sourceCode":"  bpm: number | null;\n  bpmConfidence: string;\n}\n\n// Guard against pathological inputs that would blow CDP message limits when\n// transferred to the page as base64 (≈ +33% over the raw bytes).\nconst MAX_AUDIO_BYTES = 80 * 1024 * 1024;\n\n// Runs inside the headless page: decode the base64 audio and analyze it.\nfunction inPageAnalyze(data: string) {\n  const bin = atob(data);\n  const bytes = new Uint8Array(bin.length);\n  for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);\n  const win = window as unknown as {\n    AudioContext: typeof AudioContext;\n    webkitAudioContext?: typeof AudioContext;\n    __hfAnalyze?: (buffer: AudioBuffer) => Promise<HeadlessBeatResult>;\n  };\n  if (typeof win.__hfAnalyze !== \"function\") throw new Error(\"beat analyzer not loaded\");\n  const ctx = new (win.AudioContext || win.webkitAudioContext!)();\n  return (\n    ctx\n      .decodeAudioData(bytes.buffer)\n      .then((buf) => win.__hfAnalyze!(buf))\n      // analyzeMusicFromBuffer also returns the decoded PCM (channelData) + sampleRate;\n      // project to only the fields we need so page.evaluate doesn't serialize an\n      // ~8-million-element Float32Array back across the CDP boundary.\n      .then((r) => ({\n        beatTimes: r.beatTimes,\n        beatStrengths: r.beatStrengths,\n        bpm: r.bpm,\n        bpmConfidence: r.bpmConfidence,\n      }))\n      .finally(() => ctx.close())\n  );\n}\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/heygen-com/hyperframes/blob/c2996c8626135db5253519359d8a063d3bafad8d/packages/cli/src/beats/headlessAnalyzer.ts#L72-L108","documentation":"Thrown inside the headless Chrome page (inPageAnalyze) when window.__hfAnalyze is not a function after addScriptTag injected the analyzer bundle. The bundle is supposed to set globalThis.__hfAnalyze = analyzeMusicFromBuffer; if the script failed to execute or the global was not assigned, the page-evaluate call rejects with this message, which detectOnPage then rewraps with any page-error detail.","triggerScenarios":"analyzeBeatsHeadless() runs detectOnPage(); page.addScriptTag({ content: bundle }) injects the bundle but a JS parse/exec error prevented __hfAnalyze being set; or the bundle string was empty/malformed (e.g. buildFromCoreSource produced empty output but did not throw).","commonSituations":"The analyzer bundle is stale or corrupted (older build missing the globalThis assignment); a CSP or page error blocked script execution; an esbuild output regression produced a partial bundle; headless Chrome failed to parse the IIFE.","solutions":["Rebuild the CLI bundle artifacts: `bun run build` to regenerate beat-analyzer.global.js.","Clear any stale cache and retry: remove dist artifacts that findPrebuiltBundle() locates.","Check the wrapped error detail (detectOnPage appends pageErrors) for the underlying JS error and address it in the core beatDetection source."],"exampleFix":"# before — stale analyzer bundle lacks the global assignment\n$ bunx hyperframes beats song.mp3  # 'beat analyzer not loaded'\n# rebuild and retry\n$ bun run build\n$ bunx hyperframes beats song.mp3","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await analyzeBeatsHeadless(buf);\n} catch (err) {\n  const msg = (err as Error).message;\n  if (/beat analyzer not loaded/i.test(msg)) {\n    console.error('Analyzer bundle did not install __hfAnalyze. Rebuild artifacts: `bun run build`.');\n  }\n  throw err;\n}","preventionTips":["Rebuild CLI artifacts after pulling source changes.","Treat 'beat analyzer not loaded' as a build/packaging defect, not a user input problem.","Add a smoke test that asserts globalThis.__hfAnalyze is a function after loading the bundle."],"tags":["beats","headless-chrome","bundle","page-evaluate","internal"],"backgroundTag":null,"analyzedSha":"c2996c8626135db5253519359d8a063d3bafad8d","analyzedAt":"2026-08-12T22:18:56.877Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}