diff --git a/js/lib/Comms.js b/js/lib/Comms.js index 053c19c..e544b76 100644 --- a/js/lib/Comms.js +++ b/js/lib/Comms.js @@ -277,7 +277,7 @@ class CommsServer { } if (message.cmd === 'get-current-site') { - port.postMessage({cmd: 'set-current-site', site: await this.getCurrentTabHostname()}); + port.postMessage({cmd: 'set-current-site', site: this.server.getVideoTab()}); } if (message.cmd === 'get-config') { diff --git a/js/uw-bg.js b/js/uw-bg.js index 55eaa50..73672ee 100644 --- a/js/uw-bg.js +++ b/js/uw-bg.js @@ -14,6 +14,7 @@ class UWServer { this.setup(); this.videoTabs = {}; + this.currentTabId = 0; } async setup() { @@ -60,13 +61,13 @@ class UWServer { console.log("[uw-bg::onTabSwitched] TAB CHANGED, GETTING INFO FROM MAIN TAB"); try { - var tabId = activeInfo.tabId; // just for readability + this.currentTabId = activeInfo.tabId; // just for readability var tab; if (BrowserDetect.firefox) { - var tab = await browser.tabs.get(tabId); + var tab = await browser.tabs.get(this.currentTabId); } else if (BrowserDetect.chrome) { - var tab = await this._promisifyTabsGet(chrome, tabId); + var tab = await this._promisifyTabsGet(chrome, this.currentTabId); } this.currentSite = this.extractHostname(tab.url); @@ -145,6 +146,21 @@ class UWServer { console.log("[UWServer::ungisterVideo] video unregistered. current videoTabs:", this.videoTabs); } } + + getVideoTab() { + // friendly reminder: if current tab doesn't have a video, + // there won't be anything in this.videoTabs[this.currentTabId] + if (this.videoTabs[this.currentTabId]) { + return this.videoTabs[this.currentTabId]; + } + + // return something more or less empty if this tab doesn't have + // a video registered for it + return { + host: this.currentSite, + frames: [] + } + } } var server = new UWServer(); \ No newline at end of file diff --git a/res/popup/js/popup.js b/res/popup/js/popup.js index cf1b046..a6d472b 100644 --- a/res/popup/js/popup.js +++ b/res/popup/js/popup.js @@ -129,7 +129,8 @@ async function processReceivedMessage(message, port){ port.postMessage({cmd: 'get-current-zoom'}); } site = message.site; - loadConfig(message.site); + loadConfig(message.site.host); + loadFrames(message.site); } else if (message.cmd === 'set-current-zoom') { setCurrentZoom(message.zoom); }