Hello!
I have a bunch of 'div'_ov whose appearance is customized from the CSS classes. I used to change it with the help of such a function:

function f_changeCSSClass(typeAndClass, newRule, newValue){ let target = null; let ruleSearch = null; let thisCSS = document.styleSheets[0]; console.log(thisCSS.cssRules); if(thisCSS.cssRules){ ruleSearch = thisCSS.cssRules; console.log('cssRules'); }else{ ruleSearch = thisCSS.rules; console.log('rules'); } for(let i = 0; i < ruleSearch.length; i++){ if(ruleSearch[i].selectorText == typeAndClass){ target = ruleSearch[i]; break; } } tagret.style[newRule] = newValue; } 


After updating Chrome to x64, an error began to creep out:

 Uncaught DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules at f_changeCSSClass 


I read it - it turns out that now it’s impossible even to breathe the CSS properties from JS and any mention of .cssRules causes an error.
Good people, tell me - how to get out now? Changing everything through a .style object is not an option, there are 200 of them per page. There is only one option so far - to add to the head html
Thank!

  • Add CORS and crossorigin attribute bugs.chromium.org/p/chromium/issues/detail?id=804607 - Alexey Ten

1 answer 1

This is a popular mistake that many sites have. To solve this problem, simply add the following code to the top of your scripts: crossorigin = "anonymous"