Skip to content

feat(embed): readonly mode, postMessage handshake, origin validation#63

Open
adamamyl wants to merge 1 commit into
emfcamp:mainfrom
adamamyl:embed-readonly-postmessage-v2
Open

feat(embed): readonly mode, postMessage handshake, origin validation#63
adamamyl wants to merge 1 commit into
emfcamp:mainfrom
adamamyl:embed-readonly-postmessage-v2

Conversation

@adamamyl

@adamamyl adamamyl commented Jun 27, 2026

Copy link
Copy Markdown

Closes #61

Adds a trusted-iframe embed mode, as discussed in #61.

What this does

  • ?embed=true — hides header, enables postMessage API, calls resize() 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 load

Handshake

Parent sends emf-embed-init from its own origin when the iframe loads. Map validates the origin against an allowlist, then sets parentOrigin and begins sending emf-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-marker posts to parentOrigin if known, '*' otherwise.

Origin validation allows an explicit production allowlist plus a *.*.internal wildcard for local dev. Boolean embedActivated flag (not { once: true }) so spurious messages from extensions/Workbox/URLHash don't consume the listener before emf-embed-init arrives.

Impact on upstream

All embed changes are gated behind if (options.embed), which requires ?embed=true in the URL. Normal map usage is completely unaffected. The only additive change visible outside embed mode is ?marker=lat,lon URL param support, which pre-sets a pin on load.

Files changed

  • web/src/index.ts — parse ?embed and ?readonly URL params and pass to init() (previously called with no args, making embed mode unreachable)
  • web/src/map.ts — embed block, isAllowedEmbedOrigin, click handler attached eagerly, handshake sets parentOrigin for targeted emf-view replies, ?marker param handling
  • web/src/marker.tsparentOrigin property; setLocation() posts emf-marker to parentOrigin ?? '*'

🤖 Generated with Claude Code

https://claude.ai/code/session_012BY6JnQ2NvMvwW9Fgcp2jG

@adamamyl adamamyl force-pushed the embed-readonly-postmessage-v2 branch from 9583f46 to cb0462a Compare June 27, 2026 21:21
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
@adamamyl adamamyl force-pushed the embed-readonly-postmessage-v2 branch from cb0462a to 5ae6491 Compare June 28, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow the map to be embedded in other sites

1 participant