diff --git a/js/open_new_tab.ts b/js/open_new_tab.ts new file mode 100644 index 0000000000000000000000000000000000000000..4909a0059f8d8ff64dc92b37d96e2931d725cc99 --- /dev/null +++ b/js/open_new_tab.ts @@ -0,0 +1,36 @@ +export async function open_new_tab( + url: string, + newWindow: boolean, + windowId?: number +): Promise { + let tabId; + if (newWindow) { + let window = await chrome.windows.create({ + type: 'normal', + state: 'maximized', + url: url, + } as any as chrome.windows.CreateData); + windowId = window.id as number; + let tabs = window.tabs || [ + await chrome.tabs.create({ + url: url, + windowId: windowId, + }), + ]; + tabId = tabs[0].id as number; + } else { + if (!windowId) { + const window = await chrome.windows.getCurrent(); + windowId = window.id; + } + let tab = await chrome.tabs.create({ + url: url, + windowId: windowId, + }); + tabId = tab.id as number; + } + let tab = await waitForTabComplete(tabId); + await sleep(200); + return tab; +} +