5
5
import setExtensionIconAndPopup from './setExtensionIconAndPopup' ;
6
6
7
7
function isRestrictedBrowserPage ( url ) {
8
- return ! url || new URL ( url ) . protocol === 'chrome:' ;
8
+ if ( ! url ) {
9
+ return true ;
10
+ }
11
+
12
+ const urlProtocol = new URL ( url ) . protocol ;
13
+ return urlProtocol === 'chrome:' || urlProtocol === 'about:' ;
9
14
}
10
15
11
16
function checkAndHandleRestrictedPageIfSo ( tab ) {
@@ -14,16 +19,13 @@ function checkAndHandleRestrictedPageIfSo(tab) {
14
19
}
15
20
}
16
21
17
- // update popup page of any existing open tabs, if they are restricted browser pages.
18
- // we can't update for any other types (prod,dev,outdated etc)
19
- // as the content script needs to be injected at document_start itself for those kinds of detection
20
- // TODO: Show a different popup page(to reload current page probably) for old tabs, opened before the extension is installed
22
+ // Update popup page of any existing open tabs, if they are restricted browser pages
21
23
chrome . tabs . query ( { } , tabs => tabs . forEach ( checkAndHandleRestrictedPageIfSo ) ) ;
22
- chrome . tabs . onCreated . addListener ( ( tabId , changeInfo , tab ) =>
23
- checkAndHandleRestrictedPageIfSo ( tab ) ,
24
- ) ;
24
+ chrome . tabs . onCreated . addListener ( tab => checkAndHandleRestrictedPageIfSo ( tab ) ) ;
25
25
26
26
// Listen to URL changes on the active tab and update the DevTools icon.
27
27
chrome . tabs . onUpdated . addListener ( ( tabId , changeInfo , tab ) => {
28
- checkAndHandleRestrictedPageIfSo ( tab ) ;
28
+ if ( changeInfo . url && isRestrictedBrowserPage ( changeInfo . url ) ) {
29
+ setExtensionIconAndPopup ( 'restricted' , tabId ) ;
30
+ }
29
31
} ) ;
0 commit comments