@@ -623,10 +623,23 @@ vAPI.tabs.injectScript = function(tabId, details, callback) {
623623 callback ( ) ;
624624 }
625625 } ;
626- if ( tabId ) {
627- chrome . tabs . executeScript ( toChromiumTabId ( tabId ) , details , onScriptExecuted ) ;
628- } else {
629- chrome . tabs . executeScript ( details , onScriptExecuted ) ;
626+
627+ // This may throw on some platforms due to incomplete support of API.
628+ // https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/executeScript#Browser_compatibility
629+ try {
630+ if ( tabId ) {
631+ chrome . tabs . executeScript (
632+ toChromiumTabId ( tabId ) ,
633+ details ,
634+ onScriptExecuted
635+ ) ;
636+ } else {
637+ chrome . tabs . executeScript (
638+ details ,
639+ onScriptExecuted
640+ ) ;
641+ }
642+ } catch ( ex ) {
630643 }
631644} ;
632645
@@ -653,12 +666,8 @@ vAPI.setIcon = (function() {
653666 chrome . runtime . getManifest ( ) . browser_action . default_title +
654667 ' ({badge})' ;
655668 let icons = [
656- {
657- path : { '16' : 'img/icon_16-off.png' , '32' : 'img/icon_32-off.png' }
658- } ,
659- {
660- path : { '16' : 'img/icon_16.png' , '32' : 'img/icon_32.png' }
661- }
669+ { key : 'path' , path : { } } ,
670+ { key : 'path' , path : { } }
662671 ] ;
663672
664673 ( function ( ) {
@@ -671,6 +680,19 @@ vAPI.setIcon = (function() {
671680 } ) ;
672681 }
673682
683+ // First, copy browser icon information from the manifest -- which may
684+ // be different from one platform to another.
685+ let defaultIcons = browser . runtime . getManifest ( ) . browser_action . default_icon ;
686+ for ( let key in defaultIcons ) {
687+ let path = defaultIcons [ key ] ;
688+ icons [ 1 ] . path [ key ] = path ;
689+ let pos = path . lastIndexOf ( '.' ) ;
690+ if ( pos !== - 1 ) {
691+ path = path . slice ( 0 , pos ) + '-off' + path . slice ( pos ) ;
692+ }
693+ icons [ 0 ] . path [ key ] = path ;
694+ }
695+
674696 // As of 2018-05, benchmarks show that only Chromium benefits for sure
675697 // from using ImageData.
676698 //
@@ -718,6 +740,7 @@ vAPI.setIcon = (function() {
718740 for ( let i = 0 ; i < iconData . length ; i ++ ) {
719741 if ( iconData [ i ] ) {
720742 icons [ i ] = { imageData : iconData [ i ] } ;
743+ icons [ i ] . key = 'imageData' ;
721744 }
722745 }
723746 } ;
@@ -731,11 +754,16 @@ vAPI.setIcon = (function() {
731754 var onTabReady = function ( tab , state , badge , parts ) {
732755 if ( vAPI . lastError ( ) || ! tab ) { return ; }
733756
757+ // Beware: msedge modifies the icon data object passed as argument,
758+ // hence why we need to pass a copy since we are going to reuse the
759+ // icon data object.
734760 if ( browserAction . setIcon !== undefined ) {
735761 if ( parts === undefined || ( parts & 0x01 ) !== 0 ) {
736- browserAction . setIcon (
737- Object . assign ( { tabId : tab . id } , icons [ state ] )
738- ) ;
762+ let icon = icons [ state ] ;
763+ browserAction . setIcon ( {
764+ tabId : tab . id ,
765+ [ icon . key ] : Object . assign ( { } , icon [ icon . key ] )
766+ } ) ;
739767 }
740768 browserAction . setBadgeText ( { tabId : tab . id , text : badge } ) ;
741769 }
@@ -1017,6 +1045,9 @@ vAPI.messaging.broadcast = function(message) {
10171045// - prevent web pages from interfering with uBO's element picker
10181046
10191047( function ( ) {
1048+ // https://github.com/NanoAdblocker/NanoCore/issues/40
1049+ if ( vAPI . webextFlavor . soup . has ( 'edge' ) ) { return ; }
1050+
10201051 vAPI . warSecret =
10211052 Math . floor ( Math . random ( ) * 982451653 + 982451653 ) . toString ( 36 ) +
10221053 Math . floor ( Math . random ( ) * 982451653 + 982451653 ) . toString ( 36 ) ;
0 commit comments