From d434500ec8b9d5da0c341f3e6d6748a4bb7c6e2e Mon Sep 17 00:00:00 2001 From: Mohammed Shekha Date: Thu, 23 Jul 2015 14:35:02 +0530 Subject: [PATCH] [FIX]web_editor: Fixed the issue of firefox not able to enumerate on cssRules, it is due to Cross domain security policy of firefox, used try catch, so that if there is cross domain css then skip it, it should not break the system, atleast it should work for same domain css, cross domain css should skipped --- addons/web_editor/static/src/js/transcoder.js | 14 +++++++++++++- addons/web_editor/static/src/js/widgets.js | 13 ++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/transcoder.js b/addons/web_editor/static/src/js/transcoder.js index 6e0097ee8fb..8dbc0ff0104 100644 --- a/addons/web_editor/static/src/js/transcoder.js +++ b/addons/web_editor/static/src/js/transcoder.js @@ -12,7 +12,19 @@ var getMatchedCSSRules = function (a) { if (!rulesCache.length) { var sheets = document.styleSheets; for(var i = sheets.length-1; i >= 0 ; i--) { - var rules = sheets[i].rules || sheets[i].cssRules; + var rules; + if (sheets[i].rules) { + rules = sheets[i].rules; + } else { + //try...catch because Firefox not able to enumerate document.styleSheets[].cssRules[] for cross-domain stylesheets. + try { + rules = sheets[i].cssRules; + } catch(e) { + console.warn("Can't read the css rules of: " + sheets[i].href, e); + continue; + } + rules = sheets[i].cssRules; + } if (rules) { for(var r = rules.length-1; r >= 0; r--) { var selectorText = rules[r].selectorText; diff --git a/addons/web_editor/static/src/js/widgets.js b/addons/web_editor/static/src/js/widgets.js index 5926429fe73..87d985f19f4 100644 --- a/addons/web_editor/static/src/js/widgets.js +++ b/addons/web_editor/static/src/js/widgets.js @@ -496,7 +496,18 @@ var getCssSelectors = function(filter) { } var sheets = document.styleSheets; for(var i = 0; i < sheets.length; i++) { - var rules = sheets[i].rules || sheets[i].cssRules; + var rules; + if (sheets[i].rules) { + rules = sheets[i].rules; + } else { + //try...catch because Firefox not able to enumerate document.styleSheets[].cssRules[] for cross-domain stylesheets. + try { + rules = sheets[i].cssRules; + } catch(e) { + console.warn("Can't read the css rules of: " + sheets[i].href, e); + continue; + } + } if (rules) { for(var r = 0; r < rules.length; r++) { var selectorText = rules[r].selectorText;