fix: wrap .sheet.cssRules access in try...catch. (#1693)

This commit is contained in:
Paul Thompson 2019-04-07 15:17:43 -04:00 committed by Niklas von Hertzen
parent 5cbe5db351
commit 2c018d1987

View File

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