我收到DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules。任何建议我该如何解决。
示例代码
function copyStyles(source, target) {
Array.from(source.styleSheets).forEach(styleSheet => {
let rules
try {
rules = styleSheet.cssRules
} catch (err) {
console.error(err)
}
if (rules) {
const newStyleEl = source.createElement('style')
Array.from(styleSheet.cssRules).forEach(cssRule => {
.......
})
target.head.appendChild(newStyleEl)
} else if (styleSheet.href) {
..........
}
})
}