From 152cd27c3f41682fb6794838e9eea4afe3711214 Mon Sep 17 00:00:00 2001 From: baku Date: Sat, 28 Jan 2017 09:16:00 +0100 Subject: [PATCH] Disable popup if in PrivateBrowsing #124 --- webextension/background.js | 18 ++++++++++++++++++ webextension/manifest.json | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 webextension/background.js diff --git a/webextension/background.js b/webextension/background.js new file mode 100644 index 0000000..9b707c8 --- /dev/null +++ b/webextension/background.js @@ -0,0 +1,18 @@ +browser.tabs.onCreated.addListener(tab => { + if (tab.incognito) { + disableAddon(tab.id); + } +}); + +browser.tabs.query({}).then(tabs => { + for (let tab of tabs) { // eslint-disable-line prefer-const + if (tab.incognito) { + disableAddon(tab.id); + } + } +}).catch(() => {}); + +function disableAddon(tabId) { + browser.browserAction.disable(tabId); + browser.browserAction.setTitle({ tabId, title: "Containers disabled in Private Browsing Mode" }); +} diff --git a/webextension/manifest.json b/webextension/manifest.json index 54e137d..267bd9e 100644 --- a/webextension/manifest.json +++ b/webextension/manifest.json @@ -32,6 +32,9 @@ }, "default_title": "Containers", "default_popup": "popup.html" - } + }, + "background": { + "scripts": ["background.js"] + } }