From 66842b4b7213ab71204293943264e49201f4e62a Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 12 Jan 2018 23:20:26 -0500 Subject: [PATCH] use original safari tab if we can --- src/browser/browserApi.ts | 21 +++++++++++++-------- src/content/autofiller.js | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/browser/browserApi.ts b/src/browser/browserApi.ts index ff64ea2409..fb1ef933f1 100644 --- a/src/browser/browserApi.ts +++ b/src/browser/browserApi.ts @@ -87,16 +87,20 @@ class BrowserApi { }); }); } else if (BrowserApi.isSafariApi) { - const win = safari.application.activeBrowserWindow; - if (safari.application.browserWindows.indexOf(win) !== tab.windowId) { - return Promise.reject('Window not found.'); + let t = tab.safariTab; + if (!t || !t.page) { + const win = safari.application.activeBrowserWindow; + if (safari.application.browserWindows.indexOf(win) !== tab.windowId) { + return Promise.reject('Window not found.'); + } + + if (win.tabs.length < tab.index + 1) { + return Promise.reject('Tab not found.'); + } + + t = win.tabs[tab.index]; } - if (win.tabs.length < tab.index + 1) { - return Promise.reject('Tab not found.'); - } - - const t = win.tabs[tab.index]; if (t.page) { t.page.dispatchMessage('bitwarden', obj); } @@ -206,6 +210,7 @@ class BrowserApi { title: tab.title, active: tab === tab.browserWindow.activeTab, url: tab.url || 'about:blank', + safariTab: tab, }; } } diff --git a/src/content/autofiller.js b/src/content/autofiller.js index 72532493cf..c666563043 100644 --- a/src/content/autofiller.js +++ b/src/content/autofiller.js @@ -9,7 +9,7 @@ document.addEventListener('DOMContentLoaded', (event) => { responseCommand: responseCommand }); safari.self.addEventListener('message', function (msgEvent) { - var msg = msgEvent.message; + const msg = msgEvent.message; if (msg.command === responseCommand && msg.data === true) { setInterval(doFillIfNeeded, 500); }