mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
fix: correctly handle allowTaint canvas cloning (#2649)
This commit is contained in:
parent
2b4de68e92
commit
c378e22069
@ -24,6 +24,7 @@ import {Context} from '../core/context';
|
||||
export interface CloneOptions {
|
||||
ignoreElements?: (element: Element) => boolean;
|
||||
onclone?: (document: Document, element: HTMLElement) => void;
|
||||
allowTaint?: boolean;
|
||||
}
|
||||
|
||||
export interface WindowOptions {
|
||||
@ -201,14 +202,16 @@ export class DocumentCloner {
|
||||
const ctx = canvas.getContext('2d');
|
||||
const clonedCtx = clonedCanvas.getContext('2d');
|
||||
if (clonedCtx) {
|
||||
if (ctx) {
|
||||
if (!this.options.allowTaint && ctx) {
|
||||
clonedCtx.putImageData(ctx.getImageData(0, 0, canvas.width, canvas.height), 0, 0);
|
||||
} else {
|
||||
clonedCtx.drawImage(canvas, 0, 0);
|
||||
}
|
||||
}
|
||||
return clonedCanvas;
|
||||
} catch (e) {}
|
||||
} catch (e) {
|
||||
this.context.logger.info(`Unable to clone canvas as it is tainted`);
|
||||
}
|
||||
|
||||
return clonedCanvas;
|
||||
}
|
||||
|
@ -74,6 +74,7 @@ const renderElement = async (element: HTMLElement, opts: Partial<Options>): Prom
|
||||
const foreignObjectRendering = opts.foreignObjectRendering ?? false;
|
||||
|
||||
const cloneOptions: CloneConfigurations = {
|
||||
allowTaint: opts.allowTaint ?? false,
|
||||
onclone: opts.onclone,
|
||||
ignoreElements: opts.ignoreElements,
|
||||
inlineImages: foreignObjectRendering,
|
||||
|
Loading…
Reference in New Issue
Block a user