Skip to content

Commit 0d89374

Browse files
committed
fix crash if an img tag has no src, fix undefined variables
1 parent 433d7ce commit 0d89374

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

src/Preload.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ html2canvas.Preload = function(element, opts){
2525
doc = element.ownerDocument,
2626
domImages = doc.images, // TODO probably should limit it to images present in the element only
2727
imgLen = domImages.length,
28-
link = doc.createElement("a");
28+
link = doc.createElement("a"),
29+
timeoutTimer;
2930

3031
link.href = window.location.href;
3132
pageOrigin = link.protocol + link.host;
@@ -214,7 +215,7 @@ html2canvas.Preload = function(element, opts){
214215
methods = {
215216
loadImage: function( src ) {
216217
var img;
217-
if ( images[src] === undefined ) {
218+
if ( src && images[src] === undefined ) {
218219
if ( src.match(/data:image\/.*;base64,/i) ) {
219220

220221
//Base64 src
@@ -257,7 +258,7 @@ html2canvas.Preload = function(element, opts){
257258

258259
},
259260
cleanupDOM: function(cause) {
260-
var img;
261+
var img, src;
261262
if (!images.cleanupDone) {
262263
if (cause && typeof cause === "string") {
263264
html2canvas.log("html2canvas: Cleanup because: " + cause);
@@ -320,10 +321,7 @@ html2canvas.Preload = function(element, opts){
320321
this.log('html2canvas: Preload: Finding images');
321322
// load <img> images
322323
for (i = 0; i < imgLen; i+=1){
323-
var imgSrc = domImages[i].getAttribute( "src" );
324-
if ( imgSrc ) {
325-
methods.loadImage( imgSrc );
326-
}
324+
methods.loadImage( domImages[i].getAttribute( "src" ) );
327325
}
328326

329327
images.firstRun = false;

0 commit comments

Comments
 (0)