diff --git a/apps/browser/src/platform/ipc/ipc-background.service.ts b/apps/browser/src/platform/ipc/ipc-background.service.ts index 155966898f9..f26d8d680a3 100644 --- a/apps/browser/src/platform/ipc/ipc-background.service.ts +++ b/apps/browser/src/platform/ipc/ipc-background.service.ts @@ -23,14 +23,14 @@ export class IpcBackgroundService extends IpcService { await SdkLoadService.Ready; this.communicationBackend = new IpcCommunicationBackend({ async send(message: OutgoingMessage): Promise { - if (typeof message.destination === "object") { + if (typeof message.destination === "object" && message.destination.Web != undefined) { await BrowserApi.tabSendMessage( { id: message.destination.Web.id } as chrome.tabs.Tab, { type: "bitwarden-ipc-message", message: { destination: message.destination, - payload: message.payload, + payload: [...message.payload], topic: message.topic, }, } satisfies IpcMessage, @@ -44,7 +44,7 @@ export class IpcBackgroundService extends IpcService { }); BrowserApi.messageListener("platform.ipc", (message, sender) => { - if (!isIpcMessage(message)) { + if (!isIpcMessage(message) || message.message.destination !== "BrowserBackground") { return; } @@ -53,10 +53,14 @@ export class IpcBackgroundService extends IpcService { return; } - this.communicationBackend?.deliver_message( - new IncomingMessage(message.message.payload, message.message.destination, { - Web: { id: sender.tab.id }, - }), + this.communicationBackend?.receive( + new IncomingMessage( + new Uint8Array(message.message.payload), + message.message.destination, + { + Web: { id: sender.tab.id }, + }, + ), ); }); diff --git a/apps/web/src/app/platform/ipc/web-ipc.service.ts b/apps/web/src/app/platform/ipc/web-ipc.service.ts index e088de2473b..06f3c660218 100644 --- a/apps/web/src/app/platform/ipc/web-ipc.service.ts +++ b/apps/web/src/app/platform/ipc/web-ipc.service.ts @@ -27,7 +27,7 @@ export class WebIpcService extends IpcService { type: "bitwarden-ipc-message", message: { destination: message.destination, - payload: message.payload, + payload: [...message.payload], topic: message.topic, }, } satisfies IpcMessage, @@ -50,9 +50,16 @@ export class WebIpcService extends IpcService { return; } - this.communicationBackend?.deliver_message( + if ( + typeof message.message.destination !== "object" || + message.message.destination.Web == undefined + ) { + return; + } + + this.communicationBackend?.receive( new IncomingMessage( - message.message.payload, + new Uint8Array(message.message.payload), message.message.destination, "BrowserBackground", message.message.topic, diff --git a/libs/common/src/platform/ipc/ipc-message.ts b/libs/common/src/platform/ipc/ipc-message.ts index c0702f07567..abd352da1c0 100644 --- a/libs/common/src/platform/ipc/ipc-message.ts +++ b/libs/common/src/platform/ipc/ipc-message.ts @@ -2,7 +2,11 @@ import type { OutgoingMessage } from "@bitwarden/sdk-internal"; export interface IpcMessage { type: "bitwarden-ipc-message"; - message: Omit; + message: SerializedOutgoingMessage; +} + +export interface SerializedOutgoingMessage extends Omit { + payload: number[]; } export function isIpcMessage(message: any): message is IpcMessage { diff --git a/libs/common/src/platform/ipc/ipc.service.ts b/libs/common/src/platform/ipc/ipc.service.ts index c3cd77d9850..134e615fc8b 100644 --- a/libs/common/src/platform/ipc/ipc.service.ts +++ b/libs/common/src/platform/ipc/ipc.service.ts @@ -23,6 +23,8 @@ export abstract class IpcService { protected async initWithClient(client: IpcClient): Promise { this._client = client; + await this._client.start(); + this._messages$ = new Observable((subscriber) => { let isSubscribed = true; const receiveLoop = async () => { diff --git a/package-lock.json b/package-lock.json index 70b4823a613..2b6cf7eea47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "@angular/platform-browser": "19.2.14", "@angular/platform-browser-dynamic": "19.2.14", "@angular/router": "19.2.14", - "@bitwarden/sdk-internal": "0.2.0-main.177", + "@bitwarden/sdk-internal": "0.2.0-main.198", "@electron/fuses": "1.8.0", "@emotion/css": "11.13.5", "@koa/multer": "3.1.0", @@ -4378,10 +4378,25 @@ "link": true }, "node_modules/@bitwarden/sdk-internal": { - "version": "0.2.0-main.177", - "resolved": "https://registry.npmjs.org/@bitwarden/sdk-internal/-/sdk-internal-0.2.0-main.177.tgz", - "integrity": "sha512-2fp/g0WJDPPrIqrU88QrwoJsZTzoi7S7eCf+Qq0/8x3ImqQyoYJEdHdz06YHjUdS0CzucPrwTo5zJ/ZvcLNOmQ==", - "license": "GPL-3.0" + "version": "0.2.0-main.198", + "resolved": "https://registry.npmjs.org/@bitwarden/sdk-internal/-/sdk-internal-0.2.0-main.198.tgz", + "integrity": "sha512-/MRdlcBqGxFEK/p6bU4hu5ZRoa+PqU88S+xnQaFrCXsWCTXrC8Nvm46iiz6gAqdbfFQWFNLCtmoNx6LFUdRuNg==", + "license": "GPL-3.0", + "dependencies": { + "type-fest": "^4.41.0" + } + }, + "node_modules/@bitwarden/sdk-internal/node_modules/type-fest": { + "version": "4.41.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.41.0.tgz", + "integrity": "sha512-TeTSQ6H5YHvpqVwBRcnLDCBnDOHWYu7IvGbHT6N8AOymcr9PJGjc1GTtiWZTYg0NCgYwvnYWEkVChQAr9bjfwA==", + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } }, "node_modules/@bitwarden/send-ui": { "resolved": "libs/tools/send/send-ui", diff --git a/package.json b/package.json index f867b251720..d887138ea94 100644 --- a/package.json +++ b/package.json @@ -160,7 +160,7 @@ "@angular/platform-browser": "19.2.14", "@angular/platform-browser-dynamic": "19.2.14", "@angular/router": "19.2.14", - "@bitwarden/sdk-internal": "0.2.0-main.177", + "@bitwarden/sdk-internal": "0.2.0-main.198", "@electron/fuses": "1.8.0", "@emotion/css": "11.13.5", "@koa/multer": "3.1.0",