Ignore exceptions from document.querySelector()
authorRoan Kattouw <roan.kattouw@gmail.com>
Tue, 15 Sep 2015 13:25:36 +0000 (15:25 +0200)
committerOri.livneh <ori@wikimedia.org>
Tue, 15 Sep 2015 16:01:57 +0000 (16:01 +0000)
In Firefox and Safari, passing selectors with pseudo-elements
into querySelector() can cause it to throw an exception.
Ignore these exceptions rather than aborting the selector audit.

Bug: T112650
Change-Id: I9a1bd5eb6ff5ea11eb70ff5bda994b4e51d2431e

resources/src/mediawiki/mediawiki.inspect.js

index 6bebf4d..4859953 100644 (file)
                        rules = sheet.cssRules || sheet.rules;
                        $.each( rules, function ( index, rule ) {
                                selectors.total++;
-                               if ( document.querySelector( rule.selectorText ) !== null ) {
-                                       selectors.matched++;
-                               }
+                               // document.querySelector() on prefixed pseudo-elements can throw exceptions
+                               // in Firefox and Safari. Ignore these exceptions.
+                               // https://bugs.webkit.org/show_bug.cgi?id=149160
+                               // https://bugzilla.mozilla.org/show_bug.cgi?id=1204880
+                               try {
+                                       if ( document.querySelector( rule.selectorText ) !== null ) {
+                                               selectors.matched++;
+                                       }
+                               } catch ( e ) {}
                        } );
                        document.body.removeChild( style );
                        return selectors;