mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
fix: wrap .sheet.cssRules access in try...catch. (#1693)
This commit is contained in:
parent
5cbe5db351
commit
2c018d1987
26
src/Clone.js
26
src/Clone.js
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user