Don't copy styles for regular computed rendering

This commit is contained in:
Niklas von Hertzen 2017-08-18 20:52:29 +08:00
parent 4f96abfb7b
commit f79ae2b73a
4 changed files with 12 additions and 8 deletions

View File

@ -18,11 +18,11 @@ export class DocumentCloner {
inlineImages: boolean;
copyStyles: boolean;
constructor(element: HTMLElement, options: Options, logger: Logger) {
constructor(element: HTMLElement, options: Options, logger: Logger, copyInline: boolean) {
this.referenceElement = element;
this.scrolledElements = [];
this.copyStyles = true;
this.inlineImages = true;
this.copyStyles = copyInline;
this.inlineImages = copyInline;
this.logger = logger;
this.imageLoader = new ImageLoader(options, logger, window);
// $FlowFixMe
@ -237,7 +237,7 @@ export const cloneWindow = (
options: Options,
logger: Logger
): Promise<[HTMLIFrameElement, HTMLElement]> => {
const cloner = new DocumentCloner(referenceElement, options, logger);
const cloner = new DocumentCloner(referenceElement, options, logger, false);
const cloneIframeContainer = ownerDocument.createElement('iframe');
cloneIframeContainer.className = 'html2canvas-container';

View File

@ -38,7 +38,11 @@ export default class ImageLoader<T> {
return this.addImage(src, src);
}
} else {
if (this.options.allowTaint === true || isInlineBase64Image(src) || this.isSameOrigin(src)) {
if (
this.options.allowTaint === true ||
isInlineBase64Image(src) ||
this.isSameOrigin(src)
) {
return this.addImage(src, src);
} else if (typeof this.options.proxy === 'string' && !this.isSameOrigin(src)) {
// TODO proxy

View File

@ -23,7 +23,7 @@ export type Options = {
proxy: ?string,
removeContainer: ?boolean,
scale: number,
target: RenderTarget<*> | Array<RenderTarget<*>>,
target: RenderTarget<*>,
type: ?string,
windowWidth: number,
windowHeight: number,
@ -98,7 +98,7 @@ const html2canvas = (element: HTMLElement, config: Options): Promise<*> => {
scale: options.scale
});
});
})(new DocumentCloner(element, options, logger))
})(new DocumentCloner(element, options, logger, true))
: cloneWindow(
ownerDocument,
windowBounds,

View File

@ -115,7 +115,7 @@ const assertPath = (result, expected, desc) => {
.html2canvas(testContainer.contentWindow.document.documentElement, {
removeContainer: true
})
.then((canvas) => {
.then(canvas => {
try {
canvas
.getContext('2d')