feat(embed): readonly mode, postMessage handshake, origin validation#63
Open
adamamyl wants to merge 1 commit into
Open
feat(embed): readonly mode, postMessage handshake, origin validation#63adamamyl wants to merge 1 commit into
adamamyl wants to merge 1 commit into
Conversation
9583f46 to
cb0462a
Compare
Adds trusted-iframe embed mode: - ?embed=true hides header, enables postMessage API, resize() on load fixes WebGL green-box in iframe context - ?readonly=true suppresses click-to-pin (view-only embed) - ?marker=lat,lon pre-sets a pin on load - isAllowedEmbedOrigin() validates parent against explicit allowlist (report/panel.emf.camp) + *.*.internal wildcard for local dev - Boolean embedActivated flag; click → emf-marker, pan/zoom → emf-view Closes emfcamp#61 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014M1TEnDwcEFgmTbzkySSXn
cb0462a to
5ae6491
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.
Closes #61
Adds a trusted-iframe embed mode, as discussed in #61.
What this does
?embed=true— hides header, enables postMessage API, callsresize()on load to fix WebGL green-box in iframe context?readonly=true— suppresses click-to-pin (view-only embed)?marker=lat,lon— pre-sets a pin on loadHandshake
Parent sends
emf-embed-initfrom its own origin when the iframe loads. Map validates the origin against an allowlist, then setsparentOriginand begins sendingemf-view(pan/zoom) messages back.Click-to-pin is attached immediately on embed activation — it does not wait for the handshake, so pins work even if the handshake message is delayed.
emf-markerposts toparentOriginif known,'*'otherwise.Origin validation allows an explicit production allowlist plus a
*.*.internalwildcard for local dev. BooleanembedActivatedflag (not{ once: true }) so spurious messages from extensions/Workbox/URLHash don't consume the listener beforeemf-embed-initarrives.Impact on upstream
All embed changes are gated behind
if (options.embed), which requires?embed=truein the URL. Normal map usage is completely unaffected. The only additive change visible outside embed mode is?marker=lat,lonURL param support, which pre-sets a pin on load.Files changed
web/src/index.ts— parse?embedand?readonlyURL params and pass toinit()(previously called with no args, making embed mode unreachable)web/src/map.ts— embed block,isAllowedEmbedOrigin, click handler attached eagerly, handshake setsparentOriginfor targetedemf-viewreplies,?markerparam handlingweb/src/marker.ts—parentOriginproperty;setLocation()postsemf-markertoparentOrigin ?? '*'🤖 Generated with Claude Code
https://claude.ai/code/session_012BY6JnQ2NvMvwW9Fgcp2jG