fix(player): detect the runtime by __player and honour runtime-src for src embeds - #4246
Open
srikarsunchu wants to merge 1 commit into
Open
srikarsunchu wants to merge 1 commit into
srikarsunchu wants to merge 1 commit into
Conversation
…r src embeds
`<hyperframes-player src="...">` treated the existence of `window.__hf` in
the composition frame as "the core runtime is present". `__hf` is a shared
namespace, not a bridge: `@hyperframes/shader-transitions` creates it too
(`window.__hf = window.__hf || {}`) to publish `shaderTransitionsReady`. An
authored composition that used shader transitions and registered its own
`__timelines` therefore never had the runtime injected and had its
direct-timeline adapter refused, and the embed failed 8 s later with
"Composition timeline not found". The only global the player ever drives is
`__player`, which the runtime installs synchronously in the same task as
`__hf`, so that is now the bridge check on both the probe tick and the
adapter path.
The probe's injection also always loaded the runtime from jsDelivr: the
`runtime-src` attribute was resolved for srcdoc only. The resolver is now
shared, and the player passes it to the probe, so an `src` embed can serve
its own pinned copy offline or under a `script-src 'self'` CSP. A runtime
that fails to load reports its URL on the script's own error event instead
of being indistinguishable from a slow one until the timeout.
Closes heygen-com#4002
Closes heygen-com#4003
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Closes #4002
Closes #4003
Problem
Two related defects in how
<hyperframes-player src="...">discovers and injects the core runtime:window.__hfwas treated as the runtime bridge.@hyperframes/shader-transitionsalso creates that global (window.__hf = window.__hf || {}) to publishshaderTransitionsReady. Any authored composition that uses shader transitions and registers its own__timelinestherefore looked like it already had the runtime: the probe never injected it,hasRuntimeBridge()refused the direct-timeline adapter, and the element emittederror: "Composition timeline not found after 8s"with a black frame (player: window.__hf from @hyperframes/shader-transitions makes an src embed reject its own composition #4002).runtime-srconly applied to srcdoc. The probe's late injection closed over the module-level CDN constant, so ansrcembed always fetched the runtime from jsDelivr even when the element carried a validruntime-src. Offline, air-gapped, or behind ascript-src 'self'CSP that silently fails and the embed times out (player: runtime-src is honoured for srcdoc only - an src embed always fetches the runtime from jsDelivr #4003).Fix
hasRuntimeBridge(win)now checks forwindow.__playeronly. The core runtime installs__playersynchronously in the same task as__hf(initSandboxRuntimeModularhas no awaits between the two), so there is no tick on which a real runtime has__hfbut not__player. Both the probe tick'shasRuntimeand the adapter path use the same helper.runtime-srcresolver inshader-options.tsis exported asresolveRuntimeUrlFromElementand the player hands it to the probe via a newresolveRuntimeUrlcallback. It is read at injection time, so aruntime-srcset after construction is still honoured. The existing origin/loopback validation is unchanged and now covers both paths.<script>gets anonerrorhandler: a blocked or 404 runtime now stops the probe and reportsHyperFrames runtime failed to load from <url>instead of waiting out the 8 s timeout with a message about the timeline.Tests
New unit tests in
composition-probe.test.tscover: the shader-transitions__hfnamespace next to__timelinesresolving via the direct-timeline adapter;__playerstill winning over__timelines; injection into a nested composition despite a pre-existing__hf; injection usingresolveRuntimeUrl; and the script error path stopping the probe without a second timeout error.hyperframes-player.test.tsgains an element-level test that ansrcembed withruntime-srcinjects the configured URL.bun run --filter @hyperframes/player test(excluding the pre-existing slideshow presenter-mode failures, which fail identically onmainin this environment),tsc --noEmit,oxlint,oxfmt --check, the lefthook pre-commit gate, and the player build withverify-runtime-pin.mjsall pass.Repro from the issues (both
host.htmlvariants in the linked gist) is expected to reportreadyfor the shader-transitions composition and to request/local-runtime.jsinstead of jsDelivr for thesrcembed.🤖 Generated with Claude Code