docs(engine): document __name polyfill and add regression test#385
Open
vanceingalls wants to merge 1 commit intovance/hdr-image-transfer-cachefrom
Open
docs(engine): document __name polyfill and add regression test#385vanceingalls wants to merge 1 commit intovance/hdr-image-transfer-cachefrom
vanceingalls wants to merge 1 commit intovance/hdr-image-transfer-cachefrom
Conversation
This was referenced Apr 21, 2026
Open
Collaborator
Author
This was referenced Apr 21, 2026
9da66c8 to
3058347
Compare
21c0314 to
5fe390c
Compare
3058347 to
3ebfb55
Compare
3ebfb55 to
574ba0e
Compare
5fe390c to
42ab080
Compare
574ba0e to
dec187d
Compare
42ab080 to
6d73ff8
Compare
54c8e1f to
b71cf6f
Compare
1178aee to
fa5f89f
Compare
3c4754f to
e49a01f
Compare
fa5f89f to
39c89eb
Compare
e49a01f to
a801330
Compare
39c89eb to
42ba7b2
Compare
a801330 to
2af81de
Compare
42ba7b2 to
1391c08
Compare
2af81de to
a3d4984
Compare
f5e524b to
d42983e
Compare
a3d4984 to
b3241ce
Compare
d42983e to
cb904e6
Compare
8b636ec to
6bc1dd6
Compare
cb904e6 to
85ef7aa
Compare
6bc1dd6 to
b03a62f
Compare
85ef7aa to
3e5824c
Compare
b03a62f to
31915d0
Compare
3e5824c to
d3c40de
Compare
31915d0 to
90bd43b
Compare
d3c40de to
cd24066
Compare
90bd43b to
4555013
Compare
cd24066 to
ed9217d
Compare
4555013 to
1f61054
Compare
ed9217d to
8821cd8
Compare
Investigation under HDR follow-ups Chunk 12. The window.__name shim in frameCapture.ts is necessary because @hyperframes/engine ships raw TypeScript and consumers' transpilers may inject __name(fn,"name") wrappers around named functions. When Puppeteer serializes a page.evaluate(callback) via Function.prototype.toString(), those wrappers travel into the browser and crash with ReferenceError: __name is not defined. Empirical findings (probe in /tmp/hf-name-probe): - bun TS loader: does not inject __name. - tsx (esbuild loader, keepNames=true): injects __name; this is the observed crash mode in dev/test (parity-harness, ad-hoc scripts, Vitest under bun run --filter @hyperframes/engine test). - tsc: does not inject. - tsup for @hyperframes/cli with noExternal: [@hyperframes/engine]: bundles the polyfill definition but emits no __name(...) call sites in dist/cli.js (verified by grep). Root cause: engine package.json points main/exports at ./src/index.ts, so each consumer's transpiler decides whether __name appears. Anything routed through tsx triggers the crash; the polyfill makes it a no-op. Decision: keep the shim. It's a single evaluateOnNewDocument call. The alternative (rewriting every page.evaluate(fn) site to page.addScriptTag with raw text, like contrast-audit.browser.js) is significantly more invasive. Changes: - Expand the inline comment in frameCapture.ts so future maintainers see the full per-runtime matrix and the script-tag alternative. - Add frameCapture-namePolyfill.test.ts: a pure unit test (matches the rest of the engine package's no-browser-launch convention) that asserts the polyfill is wired up, runs before the first awaited browser.version(), and probes the active transpiler so the next maintainer can see at a glance whether the upstream behavior has shifted. Verified: - bun run --filter @hyperframes/engine test -> 408/408 pass. - bunx tsc --noEmit -p packages/engine clean. - bunx oxlint and bunx oxfmt --check clean.
8821cd8 to
90225e4
Compare
1f61054 to
0b54ff2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Document why the
window.__namepolyfill inframeCapture.tsis necessary, expand the inline comment with the full per-runtime matrix, and add a regression test that surfaces transpiler behavior on the next failure.Outcome of the Chunk 12 investigation: keep the polyfill.
Why
Chunk 12ofplans/hdr-followups.md. The polyfill had a vague comment and no test, so it was unclear whether it was still needed or could be deleted.Empirical findings
Probe in
/tmp/hf-name-probe:__name(fn, "name")wrappers inFunction.prototype.toString()?bun(TS loader)tsx(esbuild loader,keepNames=true)tsc(noEmitand emit)tsupfor@hyperframes/cli(noExternal: ["@hyperframes/engine"])__name(...)call sites are absent inpackages/cli/dist/cli.js(grepped).Root cause.
@hyperframes/engine'spackage.jsonexports raw TypeScript (main/exports→./src/index.ts), so every consumer's transpiler decides whether to inject__name. Anything that runs throughtsx(producer parity-harness, ad-hoc dev scripts,bun run --filter @hyperframes/engine testvia Vitest's loader) will serialize wrapped function bodies intopage.evaluate(...)and crash withReferenceError: __name is not defined.Decision. Keep the no-op
window.__nameshim. Cost is oneevaluateOnNewDocumentcall. The alternative (rewriting everypage.evaluate(fn)site topage.addScriptTag({ content: "..." }), likepackages/cli/src/commands/contrast-audit.browser.jsalready does) is far more invasive and easy to regress.What changed
packages/engine/src/services/frameCapture.tsto explain the per-runtime matrix above and point to the script-tag alternative.packages/engine/src/services/frameCapture-namePolyfill.test.ts— a pure unit test (matches the rest of the engine package's no-browser-launch convention) that:evaluateOnNewDocumentand runs before the first awaitedbrowser.version()call.__name(...)injection so the next maintainer can see at a glance whether the upstream behavior has shifted.Test plan
bun run --filter @hyperframes/engine test→ 408/408 pass (3 new tests in this file).bunx tsc --noEmit -p packages/engineclean.bunx oxlintandbunx oxfmt --checkclean on edited files.Stack
Chunk 12 of
plans/hdr-followups.md. Independent of all other chunks; closes out the investigation item.