Files
Jarvis/webview
james.maes a0d82711da fix(03-review): H-02 attach to existing window.jarvisBus from JarvisBusWorld
Option B (minimal edit): `installJarvisBus()` now detects a pre-existing
`window.jarvisBus` with the expected send/onOutbound/receive shape and
returns verbatim rather than overwriting it.

Root cause: Swift's WebviewBridge installs `Injection.js` as a WKUserScript
`in: JarvisBusWorld` and registers `webkit.messageHandlers.jarvisBus`
in the same content world. WebKit isolates message handlers per world,
so the default-world HUD bundle (loaded via `<script type="module">`)
can NOT reach them. `window.jarvisBus` IS visible cross-world because
WebKit keeps `window` as one shared object — only variable bindings are
world-scoped. Phase 3's `main.tsx` was therefore installing a fresh bus
whose `send()` path throws on every outbound (including the first
`uiReady`). The bus-harness.html marker script in Phase 2 never called
`send()`, which is why it wasn't observed earlier.

Fix ensures the HUD dispatcher's outbound path routes through the
Injection.js bus's `send()` (which captured `webkit.messageHandlers`
at document-start inside JarvisBusWorld). The fresh-install branch is
preserved unchanged for the bus-harness.html path (no pre-existing
bus present in Phase 2 tests).

Tests:
- 5 new H-02 cases in bridge.test.ts exercise the attach-to-existing
  path (identity preserved, send/onOutbound routed through the
  pre-existing bus, fall-through when no pre-existing bus, fall-through
  for non-bus-shaped leftovers).
- Existing 28 bus tests + 80 hud tests remain green.

Also adds a doc comment to main.tsx explaining the pattern so future
readers don't re-litigate the world-isolation model.
2026-04-24 16:48:14 -05:00
..