Validate chrome.windows exists before usage

This commit is contained in:
toasted-nutbread 2019-10-19 22:45:29 -04:00
parent ffb6ff9325
commit 205498ef3b

View File

@ -367,21 +367,23 @@ async function apiFindTab(timeout, checkUrl) {
}
async function apiFocusTab(tab) {
const tabWindow = await new Promise((resolve) => {
chrome.windows.get(tab.windowId, {}, (tabWindow) => {
const e = chrome.runtime.lastError;
if (e) { reject(e); }
else { resolve(tabWindow); }
});
});
if (!tabWindow.focused) {
await new Promise((resolve, reject) => {
chrome.windows.update(tab.windowId, {focused: true}, () => {
if (typeof chrome.windows === 'object' && chrome.windows !== null) {
const tabWindow = await new Promise((resolve) => {
chrome.windows.get(tab.windowId, {}, (tabWindow) => {
const e = chrome.runtime.lastError;
if (e) { reject(e); }
else { resolve(); }
else { resolve(tabWindow); }
});
});
if (!tabWindow.focused) {
await new Promise((resolve, reject) => {
chrome.windows.update(tab.windowId, {focused: true}, () => {
const e = chrome.runtime.lastError;
if (e) { reject(e); }
else { resolve(); }
});
});
}
}
await new Promise((resolve, reject) => {
chrome.tabs.update(tab.id, {active: true}, () => {