Html2canvas: window.html2canvas is undefined if a module loader is used

Created on 24 Mar 2016  路  4Comments  路  Source: niklasvh/html2canvas

Because html2canvas and html2canvas.svg are bundled as UMD, window.html2canvas will be undefined in applications that use a module loader.

Most helpful comment

As a result you get a

"Unable to get property 'svg' of undefined or null reference"

error in IE, whenever it tries to use fabric.

An AMD workaround:

require(["html2canvas", "html2canvas.svg"], function(html2canvas, svg) {
  window.html2canvas = {
    svg: svg
  };

All 4 comments

As a result you get a

"Unable to get property 'svg' of undefined or null reference"

error in IE, whenever it tries to use fabric.

An AMD workaround:

require(["html2canvas", "html2canvas.svg"], function(html2canvas, svg) {
  window.html2canvas = {
    svg: svg
  };

And if you're using babel/es6:

  import html2canvas from 'html2canvas';
  window.html2canvas = {
    svg: html2canvas.svg
  };

Tried to do this and I am getting an blank image..any idea of what could be causing this?
I am using version 0.5.0-beta4. and doing:
html2canvas(captureTarget, { allowTaint: true }).then(canvas => { let imagex64 = canvas.toDataURL(); });

when I display that image is blank.

I had the same issue in MSIE 11.1, but it does not happen in Chrome.

A variant on nearwood's workaround stops the error, but SVGs do not render properly:

import * as html2canvas from 'html2canvas';
(window as any).html2canvas = {
    svg: html2canvas.svg
};

@niklasvh, why did you close this? Is it thought fixed? I don't see any commits which reference this issue: do you have a link to what fixed this in Chrome, so I can take a look at why it is still broken in MSIE?

Was this page helpful?
0 / 5 - 0 ratings