diff --git a/src/content/app.js b/src/content/app.js index 3834702..5fd60c5 100644 --- a/src/content/app.js +++ b/src/content/app.js @@ -127,7 +127,7 @@ export class App { } } - static allowedTabUrl(url) { + static allowedTabProxy(url) { return /^https?:\/\/.+|^about:(blank|newtab)$/.test(url); } } \ No newline at end of file diff --git a/src/content/on-request.js b/src/content/on-request.js index 384e32c..eef8744 100644 --- a/src/content/on-request.js +++ b/src/content/on-request.js @@ -226,7 +226,7 @@ export class OnRequest { static setTabProxy(tab, pxy) { // const [tab] = await browser.tabs.query({currentWindow: true, active: true}); switch (true) { - case !App.allowedTabUrl(tab.url): // unacceptable URLs + case !App.allowedTabProxy(tab.url): // unacceptable URLs case this.bypass(tab.url): // check local & global passthrough return; } diff --git a/src/content/popup.js b/src/content/popup.js index cb36416..e7b03d7 100644 --- a/src/content/popup.js +++ b/src/content/popup.js @@ -21,7 +21,6 @@ class Popup { // --- Quick Add (not for storage.managed) this.quickAdd = document.querySelector('select#quickAdd'); !pref.managed && this.quickAdd.addEventListener('change', () => { - if (!this.tab) { return; } if (!this.quickAdd.value) { return; } browser.runtime.sendMessage({id: 'quickAdd', pref, host: this.quickAdd.value, tab: this.tab}); @@ -54,10 +53,6 @@ class Popup { } static async process() { - const [tab] = await browser.tabs.query({currentWindow: true, active: true}); - // set this.tab only if tab.url is acceptable - App.allowedTabUrl(tab.url) && (this.tab = tab); - const labelTemplate = document.querySelector('template').content.firstElementChild; const docFrag = document.createDocumentFragment(); @@ -113,11 +108,15 @@ class Popup { this.quickAdd.appendChild(docFrag.cloneNode(true)); this.tabProxy.appendChild(docFrag); + // get active tab + this.tab = (await browser.tabs.query({currentWindow: true, active: true}))[0]; + + // Check Tab proxy (Firefox only) App.firefox && this.checkTabProxy(); } static async checkTabProxy() { - if (!this.tab) { return; } + if (!App.allowedTabProxy(this.tab.url)) { return; } // unacceptable URLs const item = await browser.runtime.sendMessage({id: 'getTabProxy', tab: this.tab}); item && (this.tabProxy.value = `${item.hostname}:${item.port}`);