Skip to content

Commit

Permalink
fix: wrap .sheet.cssRules access in try...catch. (#1693)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJThompson authored and niklasvh committed Apr 7, 2019
1 parent 5cbe5db commit 2c018d1
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/Clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,21 +234,25 @@ export class DocumentCloner {
return tempIframe;
}

if (node instanceof HTMLStyleElement && node.sheet && node.sheet.cssRules) {
const css = [].slice.call(node.sheet.cssRules, 0).reduce((css, rule) => {
try {
try {
if (node instanceof HTMLStyleElement && node.sheet && node.sheet.cssRules) {
const css = [].slice.call(node.sheet.cssRules, 0).reduce((css, rule) => {
if (rule && rule.cssText) {
return css + rule.cssText;
}
return css;
} catch (err) {
this.logger.log('Unable to access cssText property', rule.name);
return css;
}
}, '');
const style = node.cloneNode(false);
style.textContent = css;
return style;
}, '');
const style = node.cloneNode(false);
style.textContent = css;
return style;
}
} catch (e) {
// accessing node.sheet.cssRules throws a DOMException
this.logger.log('Unable to access cssRules property');
if (e.name !== 'SecurityError') {
this.logger.log(e);
throw e;
}
}

return node.cloneNode(false);
Expand Down

0 comments on commit 2c018d1

Please sign in to comment.