mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
`page.evaluate` callbacks with nested `function` declarations crashed with `ReferenceError: __name is not defined` whenever the host was bundled by tsx/bun. esbuild's `keepNames` mode wraps every function declaration — including ones inside the body of an evaluate callback — with a `__name(fn, "name")` call to preserve `Function.prototype.name`. The helper is injected into the host bundle but never serialized into the function string Puppeteer ships to the browser, so the browser context sees a free reference and throws. Install a no-op identity `globalThis.__name` shim via `page.evaluateOnNewDocument` during session init. We pass a string literal (not a function) because esbuild does not transform string contents — defining the shim inline would itself get wrapped with `__name(...)` and produce a use-before-define cycle. Running it via `evaluateOnNewDocument` guarantees the shim is in place before any page script (including subsequent `page.evaluate` callbacks) executes. Document the constraint at the call site in `videoFrameInjector.ts` so future edits don't try to redefine the shim inside an evaluate callback. Made-with: Cursor