mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
process messages in background runtime
This commit is contained in:
@@ -42,6 +42,15 @@ export default class RuntimeBackground {
|
||||
}
|
||||
}, true);
|
||||
|
||||
this.runtime.addEventListener('message', async (msgEvent: any) => {
|
||||
await this.processMessage(msgEvent.message, {
|
||||
tab: {
|
||||
id: null, // TODO
|
||||
},
|
||||
frameId: null,
|
||||
}, () => { /* No responses in Safari */ });
|
||||
}, false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,6 +68,11 @@ export default class RuntimeBackground {
|
||||
}
|
||||
|
||||
this.runtime.onMessage.addListener(async (msg: any, sender: any, sendResponse: any) => {
|
||||
await this.processMessage(msg, sender, sendResponse);
|
||||
});
|
||||
}
|
||||
|
||||
private async processMessage(msg: any, sender: any, sendResponse: any) {
|
||||
switch (msg.command) {
|
||||
case 'loggedIn':
|
||||
case 'unlocked':
|
||||
@@ -134,7 +148,6 @@ export default class RuntimeBackground {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private async autofillPage() {
|
||||
|
||||
@@ -101,11 +101,11 @@ class BrowserApi {
|
||||
return Promise.reject('Window not found.');
|
||||
}
|
||||
|
||||
if (safari.application.activeBrowserWindow.tabs.length < tab.index + 1) {
|
||||
if (win.tabs.length < tab.index + 1) {
|
||||
return Promise.reject('Tab not found.');
|
||||
}
|
||||
|
||||
const t = safari.application.activeBrowserWindow.tabs[tab.index];
|
||||
const t = win.tabs[tab.index];
|
||||
t.page.dispatchMessage('bitwarden', obj);
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
@@ -995,7 +995,7 @@
|
||||
*/
|
||||
|
||||
if ((typeof safari !== 'undefined')) {
|
||||
safari.self.addEventListener('bitwarden', function (msgEvent) {
|
||||
safari.self.addEventListener('message', function (msgEvent) {
|
||||
var msg = msgEvent.message;
|
||||
if (msg.command === 'collectPageDetails') {
|
||||
var pageDetails = collect(document);
|
||||
|
||||
Reference in New Issue
Block a user