@@ -11,7 +11,8 @@ html2canvas.Renderer = function(parseQueue, opts){
1111 var options = {
1212 "width" : null ,
1313 "height" : null ,
14- "renderer" : "canvas"
14+ "renderer" : "canvas" ,
15+ "taintTest" : true // do a taint test with all images before applying to canvas
1516 } ,
1617 queue = [ ] ,
1718 canvas ,
@@ -81,8 +82,12 @@ html2canvas.Renderer = function(parseQueue, opts){
8182 a ,
8283 newCanvas ,
8384 bounds ,
85+ testCanvas = document . createElement ( "canvas" ) ,
86+ hasCTX = ( testCanvas . getContext !== undefined ) ,
8487 storageLen ,
8588 renderItem ,
89+ testctx = ( hasCTX ) ? testCanvas . getContext ( "2d" ) : { } ,
90+ safeImages = [ ] ,
8691 fstyle ;
8792
8893 canvas . width = canvas . style . width = ( ! usingFlashcanvas ) ? options . width || zStack . ctx . width : Math . min ( flashMaxSize , ( options . width || zStack . ctx . width ) ) ;
@@ -136,6 +141,21 @@ html2canvas.Renderer = function(parseQueue, opts){
136141 } else if ( renderItem . name === "drawImage" ) {
137142
138143 if ( renderItem [ 'arguments' ] [ 8 ] > 0 && renderItem [ 'arguments' ] [ 7 ] ) {
144+ if ( hasCTX && options . taintTest ) {
145+ if ( safeImages . indexOf ( renderItem [ 'arguments' ] [ 0 ] . src ) === - 1 ) {
146+ testctx . drawImage ( renderItem [ 'arguments' ] [ 0 ] , 0 , 0 ) ;
147+ try {
148+ testctx . getImageData ( 0 , 0 , 1 , 1 ) ;
149+ } catch ( e ) {
150+ testCanvas = document . createElement ( "canvas" ) ;
151+ testctx = testCanvas . getContext ( "2d" ) ;
152+ continue ;
153+ }
154+
155+ safeImages . push ( renderItem [ 'arguments' ] [ 0 ] . src ) ;
156+
157+ }
158+ }
139159 ctx . drawImage . apply ( ctx , renderItem [ 'arguments' ] ) ;
140160 }
141161 }
0 commit comments