Files
hyperframes/packages/engine/src
Vance Ingalls d8d69022e4 fix(engine): install __name shim before page scripts run
`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
2026-04-19 18:34:32 -07:00
..
2026-03-21 22:43:56 -07:00