@@ -143,6 +143,24 @@ function reformatForNAT64(addr, doLookup=true) {
143143 return formatIPv6 ( packed128 , /*with_dots=*/ isNAT64 ) ;
144144}
145145
146+ // Magic object that calls action and/or pageAction. We want an icon in the
147+ // address bar when possible (e.g. desktop Firefox) but have a fallback option
148+ // when browsers forget to implement pageAction (e.g. Firefox 142 for Android).
149+ const actions = new Proxy ( { } , {
150+ get ( target , prop ) {
151+ const apis = [ chrome . action , chrome . pageAction ] . filter ( Boolean ) ;
152+ return ( ...args ) => {
153+ for ( const api of apis ) {
154+ if ( typeof api [ prop ] === 'function' ) {
155+ api [ prop ] ( ...args ) ;
156+ } else if ( prop != 'show' ) { // action.show() shouldn't exist.
157+ throw new Error ( `actions.${ prop } is not a function` ) ;
158+ }
159+ }
160+ } ;
161+ }
162+ } ) ;
163+
146164class SaveableEntry {
147165 #prefix;
148166 #id;
@@ -420,13 +438,9 @@ class TabInfo extends SaveableEntry {
420438 if ( has4 ) pattern += "4" ;
421439 if ( has6 ) pattern += "6" ;
422440
423- // Firefox might drop support for pageAction someday, but until then
424- // let's keep the icon in the address bar.
425- const action = chrome . pageAction || chrome . action ;
426-
427441 // Don't waste time rewriting the same tooltip.
428442 if ( this . lastTooltip != tooltip ) {
429- action . setTitle ( {
443+ actions . setTitle ( {
430444 "tabId" : this . id ( ) ,
431445 "title" : tooltip ,
432446 } ) ;
@@ -440,7 +454,7 @@ class TabInfo extends SaveableEntry {
440454 if ( color == "auto" ) {
441455 color = darkMode . value ? "lightfg" : "darkfg" ;
442456 }
443- action . setIcon ( {
457+ actions . setIcon ( {
444458 "tabId" : this . id ( ) ,
445459 "imageData" : {
446460 "16" : buildIcon ( pattern , 16 , color ) ,
@@ -449,13 +463,11 @@ class TabInfo extends SaveableEntry {
449463 } ) ;
450464 // Send icon to the popup window (mobile only)
451465 popups . pushPattern ( this . id ( ) , pattern ) ;
452- action . setPopup ( {
466+ actions . setPopup ( {
453467 "tabId" : this . id ( ) ,
454468 "popup" : `popup.html#${ this . id ( ) } ` ,
455469 } ) ;
456- if ( action . show ) {
457- action . show ( this . id ( ) ) ; // Firefox only
458- }
470+ actions . show ( this . id ( ) ) ;
459471 this . lastPattern = pattern ;
460472 this . save ( ) ;
461473 }
0 commit comments