@@ -38,15 +38,8 @@ chrome.runtime.onMessage.addListener((message, sender) => {
38
38
39
39
if ( message . type === 'ext/icon:set' ) {
40
40
const selected = message . payload ? 'default' : 'disabled' ;
41
- return chrome . action . setIcon ( {
42
- path : {
43
- 16 : `icons/${ selected } -16.png` ,
44
- 24 : `icons/${ selected } -24.png` ,
45
- 48 : `icons/${ selected } -48.png` ,
46
- 96 : `icons/${ selected } -96.png` ,
47
- 128 : `icons/${ selected } -128.png` ,
48
- } ,
49
- } ) ;
41
+ const icons = [ 16 , 24 , 48 , 96 , 128 ] . map ( ( s ) => [ s , `icons/${ selected } -${ s } .png` ] ) ;
42
+ return chrome . action . setIcon ( { path : Object . fromEntries ( icons ) } ) ;
50
43
}
51
44
52
45
const port = sender . tab ?. id && ports . get ( sender . tab . id ) ;
@@ -115,11 +108,9 @@ chrome.tabs.onUpdated.addListener(
115
108
) ;
116
109
117
110
/** @param {number } tabId */
118
- async function sensor ( tabId ) {
119
- const { url } = await chrome . tabs . get ( tabId ) ;
120
- if ( url ) {
121
- // only execute script for valid tabs with URLs
122
- chrome . scripting . executeScript ( {
111
+ function sensor ( tabId ) {
112
+ chrome . scripting
113
+ . executeScript ( {
123
114
target : { tabId } ,
124
115
125
116
func : ( ) => {
@@ -133,17 +124,11 @@ async function sensor(tabId) {
133
124
chrome . runtime . sendMessage ( detail ) ;
134
125
} ) ;
135
126
} ,
127
+ } )
128
+ . catch ( ( ) => {
129
+ // for internal URLs like `chrome://` or `edge://` and extension gallery
130
+ // https://chromium.googlesource.com/chromium/src/+/ee77a52baa1f8a98d15f9749996f90e9d3200f2d/chrome/common/extensions/chrome_extensions_client.cc#131
131
+ const icons = [ 16 , 24 , 48 , 96 , 128 ] . map ( ( s ) => [ s , `icons/disabled-${ s } .png` ] ) ;
132
+ chrome . action . setIcon ( { path : Object . fromEntries ( icons ) } ) ;
136
133
} ) ;
137
- } else {
138
- // for internal pages like `chrome://extensions/`
139
- chrome . action . setIcon ( {
140
- path : {
141
- 16 : 'icons/disabled-16.png' ,
142
- 24 : 'icons/disabled-24.png' ,
143
- 48 : 'icons/disabled-48.png' ,
144
- 96 : 'icons/disabled-96.png' ,
145
- 128 : 'icons/disabled-128.png' ,
146
- } ,
147
- } ) ;
148
- }
149
134
}
0 commit comments