diff --git a/src/background/main.background.ts b/src/background/main.background.ts index 18a4c0f43b..405a834296 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -273,6 +273,14 @@ export default class MainBackground { } } + sendInternalRuntimeMessage(message: any) { + if (!this.isSafari) { + throw new Error('Only safari can send internal runtime messages.'); + } + + this.runtimeBackground.processMessage(message, { tab: null }, () => { /* No response needed. */ }); + } + private async buildContextMenu() { if (this.isSafari || !chrome.contextMenus || this.buildingContextMenu) { return; diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index 499c17cb4d..9409e40610 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -68,7 +68,7 @@ export default class RuntimeBackground { }); } - private async processMessage(msg: any, sender: any, sendResponse: any) { + async processMessage(msg: any, sender: any, sendResponse: any) { switch (msg.command) { case 'loggedIn': case 'unlocked': diff --git a/src/services/browserMessaging.service.ts b/src/services/browserMessaging.service.ts index 9fa953aae8..82f9b651f2 100644 --- a/src/services/browserMessaging.service.ts +++ b/src/services/browserMessaging.service.ts @@ -1,3 +1,5 @@ +import { BrowserApi } from '../browser/browserApi'; + import { MessagingService, PlatformUtilsService, @@ -8,10 +10,12 @@ export default class BrowserMessagingService implements MessagingService { } send(subscriber: string, arg: any = {}) { + const message = Object.assign({}, { command: subscriber }, arg); + if (this.platformUtilsService.isSafari()) { - // send message + const bgPage = BrowserApi.getBackgroundPage(); + bgPage.bitwardenMain.sendInternalRuntimeMessage(message); } else { - const message = Object.assign({}, { command: subscriber }, arg); chrome.runtime.sendMessage(message); } }