Skip to content

Commit 76d8de3

Browse files
committed
Fix the External stylesheets error in Firefox
To circumvent the SecurityError in Firefox when attempting to access the cssRules attribute on external stylesheets, you must use a try/catch statement.
1 parent bd02a96 commit 76d8de3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/ElementQueries.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,13 @@
232232
this.init = function(withTracking) {
233233
this.withTracking = withTracking;
234234
for (var i = 0, j = document.styleSheets.length; i < j; i++) {
235-
readRules(document.styleSheets[i].cssText || document.styleSheets[i].cssRules || document.styleSheets[i].rules);
235+
try {
236+
readRules(document.styleSheets[i].cssText || document.styleSheets[i].cssRules || document.styleSheets[i].rules);
237+
} catch(e) {
238+
if (e.name !== 'SecurityError') {
239+
throw e;
240+
}
241+
}
236242
}
237243
};
238244

0 commit comments

Comments
 (0)