Skip to content

Commit

Permalink
[PM-12971] - close safari default extension on pop out (#11391)
Browse files Browse the repository at this point in the history
* fix safari extension opening

* Update apps/browser/src/platform/browser/browser-api.ts

Co-authored-by: Justin Baur <[email protected]>

* remove whitespace

* remove check for id

---------

Co-authored-by: Justin Baur <[email protected]>
  • Loading branch information
jaasen-livefront and justindbaur authored Nov 6, 2024
1 parent 5a288b9 commit 4cc562c
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions apps/browser/src/platform/browser/browser-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,33 @@ export class BrowserApi {
}

static async createWindow(options: chrome.windows.CreateData): Promise<chrome.windows.Window> {
return new Promise((resolve) =>
chrome.windows.create(options, (window) => {
resolve(window);
}),
);
return new Promise((resolve) => {
chrome.windows.create(options, async (newWindow) => {
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);
});
});
});
});
}

/**
Expand Down

0 comments on commit 4cc562c

Please sign in to comment.