From f16d581f04301720a77f758702c820018f2be13d Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Thu, 28 Sep 2017 19:46:00 +0800 Subject: [PATCH] Add foreignObjectRendering option --- src/Clone.js | 1 + src/Window.js | 6 ++++-- src/index.js | 2 ++ tests/testrunner.js | 16 ++++++++++------ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Clone.js b/src/Clone.js index 3abd658..6d7d3b0 100644 --- a/src/Clone.js +++ b/src/Clone.js @@ -124,6 +124,7 @@ export class DocumentCloner { proxy: this.options.proxy, removeContainer: this.options.removeContainer, scale: this.options.scale, + foreignObjectRendering: this.options.foreignObjectRendering, target: new CanvasRenderer(), width, height, diff --git a/src/Window.js b/src/Window.js index 46d52f7..e83e559 100644 --- a/src/Window.js +++ b/src/Window.js @@ -46,8 +46,10 @@ export const renderElement = ( : documentBackgroundColor : options.backgroundColor ? new Color(options.backgroundColor) : null; - // $FlowFixMe - return Feature.SUPPORT_FOREIGNOBJECT_DRAWING.then( + return (options.foreignObjectRendering + ? // $FlowFixMe + Feature.SUPPORT_FOREIGNOBJECT_DRAWING + : Promise.resolve(false)).then( supportForeignObject => supportForeignObject ? (cloner => { diff --git a/src/index.js b/src/index.js index 52a785c..582b3f7 100644 --- a/src/index.js +++ b/src/index.js @@ -13,6 +13,7 @@ export type Options = { allowTaint: ?boolean, backgroundColor: string, canvas: ?HTMLCanvasElement, + foreignObjectRendering: boolean, imageTimeout: number, proxy: ?string, removeContainer: ?boolean, @@ -56,6 +57,7 @@ const html2canvas = (element: HTMLElement, conf: ?Options): Promise<*> => { imageTimeout: 15000, proxy: null, removeContainer: true, + foreignObjectRendering: true, scale: defaultView.devicePixelRatio || 1, target: new CanvasRenderer(config.canvas), x: left, diff --git a/tests/testrunner.js b/tests/testrunner.js index 30117c3..48bcb44 100644 --- a/tests/testrunner.js +++ b/tests/testrunner.js @@ -115,12 +115,16 @@ const assertPath = (result, expected, desc) => { }); it('Should render untainted canvas', () => { return testContainer.contentWindow - .html2canvas(testContainer.contentWindow.forceElement || testContainer.contentWindow.document.documentElement, { - removeContainer: true, - backgroundColor: '#ffffff', - proxy: 'http://localhost:8081/proxy', - ...(testContainer.contentWindow.h2cOptions || {}) - }) + .html2canvas( + testContainer.contentWindow.forceElement || + testContainer.contentWindow.document.documentElement, + { + removeContainer: true, + backgroundColor: '#ffffff', + proxy: 'http://localhost:8081/proxy', + ...(testContainer.contentWindow.h2cOptions || {}) + } + ) .then(canvas => { try { canvas