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:55:32 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-10-19 22:55:32 -0400
commitce92591b636c8525696b18f5dc844e12865ee6fc (patch)
tree5ec978bb64e1ce5781d9eec121b8bd4244497fef /ext/bg/js/api.js
parent7abc7fd0e797f11bec98924b19653de6eea46c5f (diff)
Fix window focus not always working
Diffstat (limited to 'ext/bg/js/api.js')
-rw-r--r--ext/bg/js/api.js40
1 files changed, 22 insertions, 18 deletions
diff --git a/ext/bg/js/api.js b/ext/bg/js/api.js
index 9ae7c841..94a53e67 100644
--- a/ext/bg/js/api.js
+++ b/ext/bg/js/api.js
@@ -367,24 +367,6 @@ async function apiFindTab(timeout, checkUrl) {
}
async function apiFocusTab(tab) {
- 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(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}, () => {
const e = chrome.runtime.lastError;
@@ -392,4 +374,26 @@ async function apiFocusTab(tab) {
else { resolve(); }
});
});
+
+ if (!(typeof chrome.windows === 'object' && chrome.windows !== null)) {
+ // Windows not supported (e.g. on Firefox mobile)
+ return;
+ }
+
+ 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}, () => {
+ const e = chrome.runtime.lastError;
+ if (e) { reject(e); }
+ else { resolve(); }
+ });
+ });
+ }
}