From 76d8de3c7da5710543ab435f2739189d08671cbb Mon Sep 17 00:00:00 2001 From: ElManouche Date: Fri, 24 Apr 2015 10:45:03 +0200 Subject: [PATCH] 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. --- src/ElementQueries.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ElementQueries.js b/src/ElementQueries.js index f822139..3287b8d 100755 --- a/src/ElementQueries.js +++ b/src/ElementQueries.js @@ -232,7 +232,13 @@ this.init = function(withTracking) { this.withTracking = withTracking; for (var i = 0, j = document.styleSheets.length; i < j; i++) { - readRules(document.styleSheets[i].cssText || document.styleSheets[i].cssRules || document.styleSheets[i].rules); + try { + readRules(document.styleSheets[i].cssText || document.styleSheets[i].cssRules || document.styleSheets[i].rules); + } catch(e) { + if (e.name !== 'SecurityError') { + throw e; + } + } } };