@@ -70,18 +70,29 @@ async function injectStyleSheets(
7070 fontDeclarations ,
7171 fontFileDeclarations
7272) {
73- let { extensionActive } = await chrome . storage . local . get ( "extensionActive" ) ;
74- let fontDeclarationsCss = fontDeclarations . join ( "\n" ) ;
75- let fontFileDeclarationsCss = fontFileDeclarations . join ( "\n" ) ;
76- if ( extensionActive ) {
77- // Inject CSS to activate font
78- await insertOrReplaceCss ( tabId , "fonts" , fontDeclarationsCss ) ;
79- await insertOrReplaceCss ( tabId , "fontfiles" , fontFileDeclarationsCss ) ;
73+ try {
74+ let { extensionActive } = await chrome . storage . local . get (
75+ "extensionActive"
76+ ) ;
77+ let fontDeclarationsCss = fontDeclarations . join ( "\n" ) ;
78+ let fontFileDeclarationsCss = fontFileDeclarations . join ( "\n" ) ;
79+ if ( extensionActive ) {
80+ // Inject CSS to activate font
81+ await insertOrReplaceCss ( tabId , "fonts" , fontDeclarationsCss ) ;
82+ await insertOrReplaceCss (
83+ tabId ,
84+ "fontfiles" ,
85+ fontFileDeclarationsCss
86+ ) ;
87+ }
88+ await chrome . scripting . executeScript ( {
89+ target : { tabId } ,
90+ func : extensionActive ? customFontsOn : customFontsOff
91+ } ) ;
92+ } catch ( error ) {
93+ // Silently ignore errors for protected pages (chrome://, extension pages, etc.)
94+ console . debug ( `Can't inject into ${ tabId } :` , error . message ) ;
8095 }
81- chrome . scripting . executeScript ( {
82- target : { tabId } ,
83- func : extensionActive ? customFontsOn : customFontsOff
84- } ) ;
8596}
8697
8798async function generateFontStyleSheets ( ) {
0 commit comments