main
js 31 lines 958 Bytes
Raw
1 /* global chrome */
2
3 'use strict';
4
5 import setExtensionIconAndPopup from './setExtensionIconAndPopup';
6
7 function isRestrictedBrowserPage(url) {
8 if (!url) {
9 return true;
10 }
11
12 const urlProtocol = new URL(url).protocol;
13 return urlProtocol === 'chrome:' || urlProtocol === 'about:';
14 }
15
16 function checkAndHandleRestrictedPageIfSo(tab) {
17 if (tab && isRestrictedBrowserPage(tab.url)) {
18 setExtensionIconAndPopup('restricted', tab.id);
19 }
20 }
21
22 // Update popup page of any existing open tabs, if they are restricted browser pages
23 chrome.tabs.query({}, tabs => tabs.forEach(checkAndHandleRestrictedPageIfSo));
24 chrome.tabs.onCreated.addListener(tab => checkAndHandleRestrictedPageIfSo(tab));
25
26 // Listen to URL changes on the active tab and update the DevTools icon.
27 chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
28 if (changeInfo.url && isRestrictedBrowserPage(changeInfo.url)) {
29 setExtensionIconAndPopup('restricted', tabId);
30 }
31 });