mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-29 17:38:04 +01:00
make tab object for message sender
This commit is contained in:
parent
06c8f17d06
commit
729380c0ec
@ -44,16 +44,7 @@ class BrowserApi {
|
||||
|
||||
const returnedTabs: any[] = [];
|
||||
tabs.forEach((tab: any) => {
|
||||
const winIndex = safari.application.browserWindows.indexOf(tab.browserWindow);
|
||||
const tabIndex = tab.browserWindow.tabs.indexOf(tab);
|
||||
returnedTabs.push({
|
||||
id: winIndex + '_' + tabIndex,
|
||||
index: tabIndex,
|
||||
windowId: winIndex,
|
||||
title: tab.title,
|
||||
active: tab === tab.browserWindow.activeTab,
|
||||
url: tab.url || 'about:blank',
|
||||
});
|
||||
returnedTabs.push(BrowserApi.makeTabObject(tab));
|
||||
});
|
||||
|
||||
return Promise.resolve(returnedTabs);
|
||||
@ -169,14 +160,33 @@ class BrowserApi {
|
||||
} else if (BrowserApi.isSafariApi) {
|
||||
safari.application.addEventListener('message', async (msgEvent: any) => {
|
||||
callback(msgEvent.message, {
|
||||
tab: {
|
||||
id: null, // TODO
|
||||
},
|
||||
tab: BrowserApi.makeTabObject(msgEvent.target),
|
||||
frameId: null,
|
||||
}, () => { /* No responses in Safari */ });
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
|
||||
private static makeTabObject(tab: any) {
|
||||
if (BrowserApi.isChromeApi) {
|
||||
return tab;
|
||||
}
|
||||
|
||||
if (!tab.browserWindow) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const winIndex = safari.application.browserWindows.indexOf(tab.browserWindow);
|
||||
const tabIndex = tab.browserWindow.tabs.indexOf(tab);
|
||||
return {
|
||||
id: winIndex + '_' + tabIndex,
|
||||
index: tabIndex,
|
||||
windowId: winIndex,
|
||||
title: tab.title,
|
||||
active: tab === tab.browserWindow.activeTab,
|
||||
url: tab.url || 'about:blank',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { BrowserApi };
|
||||
|
Loading…
Reference in New Issue
Block a user