1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-30 13:03:53 +01:00

generate random ids for window and tabs

This commit is contained in:
Kyle Spearrin 2018-01-12 14:02:48 -05:00
parent de910ee195
commit eb4f288948

View File

@ -44,12 +44,10 @@ class BrowserApi {
const returnedTabs: any[] = []; const returnedTabs: any[] = [];
tabs.forEach((tab: any) => { tabs.forEach((tab: any) => {
const winIndex = safari.application.browserWindows.indexOf(tab.browserWindow);
const tabIndex = tab.browserWindow.tabs.indexOf(tab);
returnedTabs.push({ returnedTabs.push({
id: winIndex + '_' + tabIndex, id: BrowserApi.getTabOrWindowId(tab),
index: tabIndex, index: tab.browserWindow.tabs.indexOf(tab),
windowId: winIndex, windowId: BrowserApi.getTabOrWindowId(tab.browserWindow),
title: tab.title, title: tab.title,
active: tab === tab.browserWindow.activeTab, active: tab === tab.browserWindow.activeTab,
url: tab.url || 'about:blank', url: tab.url || 'about:blank',
@ -156,6 +154,22 @@ class BrowserApi {
// TODO // TODO
} }
} }
private static getTabOrWindowId(tabOrWindow: any) {
if (tabOrWindow.id) {
return tabOrWindow.id;
}
if (!tabOrWindow.BitwardenCachedId) {
tabOrWindow.BitwardenCachedId = BrowserApi.randomInt(1, Number.MAX_SAFE_INTEGER);
}
return tabOrWindow.BitwardenCachedId;
}
private static randomInt(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
} }
export { BrowserApi }; export { BrowserApi };