mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-14 10:26:19 +01:00
[PM-12971] - close safari default extension on pop out (#11391)
* fix safari extension opening * Update apps/browser/src/platform/browser/browser-api.ts Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> * remove whitespace * remove check for id --------- Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com>
This commit is contained in:
parent
5a288b97db
commit
4cc562c228
@ -58,11 +58,33 @@ export class BrowserApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static async createWindow(options: chrome.windows.CreateData): Promise<chrome.windows.Window> {
|
static async createWindow(options: chrome.windows.CreateData): Promise<chrome.windows.Window> {
|
||||||
return new Promise((resolve) =>
|
return new Promise((resolve) => {
|
||||||
chrome.windows.create(options, (window) => {
|
chrome.windows.create(options, async (newWindow) => {
|
||||||
resolve(window);
|
if (!BrowserApi.isSafariApi) {
|
||||||
}),
|
return resolve(newWindow);
|
||||||
);
|
}
|
||||||
|
// Safari doesn't close the default extension popup when a new window is created so we need to
|
||||||
|
// manually trigger the close by focusing the main window after the new window is created
|
||||||
|
const allWindows = await new Promise<chrome.windows.Window[]>((resolve) => {
|
||||||
|
chrome.windows.getAll({ windowTypes: ["normal"] }, (windows) => resolve(windows));
|
||||||
|
});
|
||||||
|
|
||||||
|
const mainWindow = allWindows.find((window) => window.id !== newWindow.id);
|
||||||
|
|
||||||
|
// No main window found, resolve the new window
|
||||||
|
if (mainWindow == null || !mainWindow.id) {
|
||||||
|
return resolve(newWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Focus the main window to close the extension popup
|
||||||
|
chrome.windows.update(mainWindow.id, { focused: true }, () => {
|
||||||
|
// Refocus the newly created window
|
||||||
|
chrome.windows.update(newWindow.id, { focused: true }, () => {
|
||||||
|
resolve(newWindow);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user