@@ -298,58 +298,66 @@ class Tinter {
298298
299299 for ( let i = 0 ; i < document . styleSheets . length ; i ++ ) {
300300 const ss = document . styleSheets [ i ] ;
301- if ( ! ss ) continue ; // well done safari >:(
302- // Chromium apparently sometimes returns null here; unsure why.
303- // see $14534907369972FRXBx:matrix.org in HQ
304- // ...ah, it's because there's a third party extension like
305- // privacybadger inserting its own stylesheet in there with a
306- // resource:// URI or something which results in a XSS error.
307- // See also #vector:matrix.org/$145357669685386ebCfr:matrix.org
308- // ...except some browsers apparently return stylesheets without
309- // hrefs, which we have no choice but ignore right now
310-
311- // XXX seriously? we are hardcoding the name of vector's CSS file in
312- // here?
313- //
314- // Why do we need to limit it to vector's CSS file anyway - if there
315- // are other CSS files affecting the doc don't we want to apply the
316- // same transformations to them?
317- //
318- // Iterating through the CSS looking for matches to hack on feels
319- // pretty horrible anyway. And what if the application skin doesn't use
320- // Vector Green as its primary color?
321- // --richvdh
322-
323- // Yes, tinting assumes that you are using the Riot skin for now.
324- // The right solution will be to move the CSS over to react-sdk.
325- // And yes, the default assets for the base skin might as well use
326- // Vector Green as any other colour.
327- // --matthew
328-
329- // stylesheets we don't have permission to access (eg. ones from extensions) have a null
330- // href and will throw exceptions if we try to access their rules.
331- if ( ! ss . href || ! ss . href . match ( new RegExp ( '/theme-' + this . theme + '.css$' ) ) ) continue ;
332- if ( ss . disabled ) continue ;
333- if ( ! ss . cssRules ) continue ;
334-
335- if ( DEBUG ) console . debug ( "calcCssFixups checking " + ss . cssRules . length + " rules for " + ss . href ) ;
336-
337- for ( let j = 0 ; j < ss . cssRules . length ; j ++ ) {
338- const rule = ss . cssRules [ j ] ;
339- if ( ! rule . style ) continue ;
340- if ( rule . selectorText && rule . selectorText . match ( / # m x _ t h e m e / ) ) continue ;
341- for ( let k = 0 ; k < this . cssAttrs . length ; k ++ ) {
342- const attr = this . cssAttrs [ k ] ;
343- for ( let l = 0 ; l < this . keyRgb . length ; l ++ ) {
344- if ( rule . style [ attr ] === this . keyRgb [ l ] ) {
345- this . cssFixups [ this . theme ] . push ( {
346- style : rule . style ,
347- attr : attr ,
348- index : l ,
349- } ) ;
301+ try {
302+ if ( ! ss ) continue ; // well done safari >:(
303+ // Chromium apparently sometimes returns null here; unsure why.
304+ // see $14534907369972FRXBx:matrix.org in HQ
305+ // ...ah, it's because there's a third party extension like
306+ // privacybadger inserting its own stylesheet in there with a
307+ // resource:// URI or something which results in a XSS error.
308+ // See also #vector:matrix.org/$145357669685386ebCfr:matrix.org
309+ // ...except some browsers apparently return stylesheets without
310+ // hrefs, which we have no choice but ignore right now
311+
312+ // XXX seriously? we are hardcoding the name of vector's CSS file in
313+ // here?
314+ //
315+ // Why do we need to limit it to vector's CSS file anyway - if there
316+ // are other CSS files affecting the doc don't we want to apply the
317+ // same transformations to them?
318+ //
319+ // Iterating through the CSS looking for matches to hack on feels
320+ // pretty horrible anyway. And what if the application skin doesn't use
321+ // Vector Green as its primary color?
322+ // --richvdh
323+
324+ // Yes, tinting assumes that you are using the Riot skin for now.
325+ // The right solution will be to move the CSS over to react-sdk.
326+ // And yes, the default assets for the base skin might as well use
327+ // Vector Green as any other colour.
328+ // --matthew
329+
330+ // stylesheets we don't have permission to access (eg. ones from extensions) have a null
331+ // href and will throw exceptions if we try to access their rules.
332+ if ( ! ss . href || ! ss . href . match ( new RegExp ( '/theme-' + this . theme + '.css$' ) ) ) continue ;
333+ if ( ss . disabled ) continue ;
334+ if ( ! ss . cssRules ) continue ;
335+
336+ if ( DEBUG ) console . debug ( "calcCssFixups checking " + ss . cssRules . length + " rules for " + ss . href ) ;
337+
338+ for ( let j = 0 ; j < ss . cssRules . length ; j ++ ) {
339+ const rule = ss . cssRules [ j ] ;
340+ if ( ! rule . style ) continue ;
341+ if ( rule . selectorText && rule . selectorText . match ( / # m x _ t h e m e / ) ) continue ;
342+ for ( let k = 0 ; k < this . cssAttrs . length ; k ++ ) {
343+ const attr = this . cssAttrs [ k ] ;
344+ for ( let l = 0 ; l < this . keyRgb . length ; l ++ ) {
345+ if ( rule . style [ attr ] === this . keyRgb [ l ] ) {
346+ this . cssFixups [ this . theme ] . push ( {
347+ style : rule . style ,
348+ attr : attr ,
349+ index : l ,
350+ } ) ;
351+ }
350352 }
351353 }
352354 }
355+ } catch ( e ) {
356+ // Catch any random exceptions that happen here: all sorts of things can go
357+ // wrong with this (nulls, SecurityErrors) and mostly it's for other
358+ // stylesheets that we don't want to proces anyway. We should not propagate an
359+ // exception out since this will cause the app to fail to start.
360+ console . log ( "Failed to calculate CSS fixups for a stylesheet: " + ss . href , e ) ;
353361 }
354362 }
355363 if ( DEBUG ) {
0 commit comments