aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/api.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-19 22:45:29 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-19 22:45:29 -0400
commit205498ef3b84c5acfe7ee2a76e4085260bc7a3ef (patch)
treee363034b4e3bc9a04eeb3ffadd0defa68c247eb3 /ext/bg/js/api.js
parentffb6ff932588fc2a00e2ec6ec586dae40c83ffad (diff)
Validate chrome.windows exists before usage
Diffstat (limited to 'ext/bg/js/api.js')
-rw-r--r--ext/bg/js/api.js24
1 files changed, 13 insertions, 11 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index e8379d10..9ae7c841 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -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}, () => {