Files
app__bitwarden-clients/libs
Andreas Coroiu 2ff80e5095 [PM-45453] feat(ipc): Resolve SDK IPC broadcast groups and wake extension pages (#23987)
* [PM-18041] feat: Add IPC transport between popup and background

* [PM-18041] refactor: Align popup IPC with existing transports

Read chrome.runtime.lastError on port disconnect as the desktop transport does, and await
IpcService.init() in the popup as web and desktop do.

* [PM-18041] refactor: Align popup IPC transports with the existing ones

Name the transports after the SDK endpoint they handle, start listening in
init() with receive passed to the constructor, and report disconnects to the
owning service, which removes the session. Move InMemoryIpcSessionRepository
to apps/browser since only the extension uses it.

* [PM-18041] test: Tighten popup IPC transport tests

Check that a send reaches only the addressed port, and drop the tests for
the session repository's Map wrapper and the unreachable destination guard.

* [PM-18041] refactor: Use the SDK's in-memory IPC sessions

The SDK already recovers when a peer restarts and loses its session, at the
cost of one dropped message, the same as the other IPC connections. Drop the
client-managed repository and the disconnect callbacks that only avoided it.

* Ensure ports get removed on disconnect

* feat(ipc): resolve SDK IPC broadcast groups in browser and desktop

Implement the SDK communication backend resolve hook so IpcClient.broadcast
works on the two hubs:

- Browser background resolves AllBrowserForeground to the extension pages
  with an open IPC port.
- Desktop main resolves AllBrowserBackground to the connected native
  messaging clients, excluding the CLI. This includes the browser's
  biometrics connection, which ignores IPC and costs a handshake timeout
  per broadcast; that channel is expected to go away once shared unlock
  ships.

Every other group resolves to Unsupported. IpcService gains a broadcast
pass-through next to send.

Requires the unreleased sdk-internal broadcast API (branch
coroiu/ipc-broadcast).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Wake extension pages so the background can reach them before they send

The extension page transport opened its port on the first send, so a page
that had not sent anything was not an IPC endpoint and broadcasts to
AllBrowserForeground skipped it. A restarted service worker also lost every
page until it sent again.

Pages now connect when their IPC service starts. The background opens a
bitwarden-ipc-wake port once at startup, which every open extension page
receives; a page that has no port then connects its own. Verified in headless
Chromium: idle popups receive broadcasts, closed popups drop out, and after a
service worker restart an already open popup reconnects and completes a fresh
handshake.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Document broadcast's fatal-error behavior and the desktop biometrics stall

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Update sdk-internal to 0.2.0-main.1157

Picks up the IPC broadcast API (bitwarden/sdk-internal#1652).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Wake extension pages with a runtime message, not a port

A page that listens to runtime.onConnect also receives the other pages'
IPC ports. With two pages open, that keeps a page's port alive after the
service worker stops, so its onDisconnect never fires: the page keeps
posting into a dead port and is missing from AllBrowserForeground after
the restart.

The background now sends the wake signal with runtime.sendMessage and
pages listen on runtime.onMessage, so no extension page registers an
onConnect listener.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Daniel García <dani-garcia@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 13:26:39 +01:00
..
…
…
…
…