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;
|
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user