@@ -580,12 +580,13 @@ window.html2canvas = function(nodeList, options) {
580580 options . async = typeof ( options . async ) === "undefined" ? true : options . async ;
581581 options . allowTaint = typeof ( options . allowTaint ) === "undefined" ? false : options . allowTaint ;
582582 options . removeContainer = typeof ( options . removeContainer ) === "undefined" ? true : options . removeContainer ;
583+ options . javascriptEnabled = typeof ( options . javascriptEnabled ) === "undefined" ? false : options . javascriptEnabled ;
583584
584585 if ( typeof ( nodeList ) === "string" ) {
585586 if ( typeof ( options . proxy ) !== "string" ) {
586587 return Promise . reject ( "Proxy must be used when rendering url" ) ;
587588 }
588- return loadUrlDocument ( absoluteUrl ( nodeList ) , options . proxy , document , window . innerWidth , window . innerHeight ) . then ( function ( container ) {
589+ return loadUrlDocument ( absoluteUrl ( nodeList ) , options . proxy , document , window . innerWidth , window . innerHeight , options ) . then ( function ( container ) {
589590 return renderWindow ( container . contentWindow . document . documentElement , container , options , window . innerWidth , window . innerHeight ) ;
590591 } ) ;
591592 }
@@ -627,14 +628,18 @@ function renderWindow(node, container, options, windowWidth, windowHeight) {
627628 return parser . ready . then ( function ( ) {
628629 log ( "Finished rendering" ) ;
629630 var canvas = ( options . type !== "view" && ( node === clonedWindow . document . body || node === clonedWindow . document . documentElement ) ) ? renderer . canvas : crop ( renderer . canvas , bounds ) ;
630- if ( options . removeContainer ) {
631- container . parentNode . removeChild ( container ) ;
632- log ( "Cleaned up container" ) ;
633- }
631+ cleanupContainer ( container , options ) ;
634632 return canvas ;
635633 } ) ;
636634}
637635
636+ function cleanupContainer ( container , options ) {
637+ if ( options . removeContainer ) {
638+ container . parentNode . removeChild ( container ) ;
639+ log ( "Cleaned up container" ) ;
640+ }
641+ }
642+
638643function crop ( canvas , bounds ) {
639644 var croppedCanvas = document . createElement ( "canvas" ) ;
640645 var x1 = Math . min ( canvas . width - 1 , Math . max ( 0 , bounds . left ) ) ;
@@ -698,16 +703,16 @@ function createWindowClone(ownerDocument, containerDocument, width, height, opti
698703 documentClone . write ( "<!DOCTYPE html>" ) ;
699704 documentClone . close ( ) ;
700705
701- documentClone . replaceChild ( removeScriptNodes ( documentClone . adoptNode ( documentElement ) ) , documentClone . documentElement ) ;
706+ documentClone . replaceChild ( options . javascriptEnabled === true ? documentClone . adoptNode ( documentElement ) : removeScriptNodes ( documentClone . adoptNode ( documentElement ) ) , documentClone . documentElement ) ;
702707 if ( options . type === "view" ) {
703708 container . contentWindow . scrollTo ( window . pageXOffset , window . pageYOffset ) ;
704709 }
705710 } ) ;
706711}
707712
708- function loadUrlDocument ( src , proxy , document , width , height ) {
713+ function loadUrlDocument ( src , proxy , document , width , height , options ) {
709714 return new Proxy ( src , proxy , window . document ) . then ( documentFromHTML ( src ) ) . then ( function ( doc ) {
710- return createWindowClone ( doc , document , width , height , { } ) ;
715+ return createWindowClone ( doc , document , width , height , options ) ;
711716 } ) ;
712717}
713718
@@ -852,12 +857,12 @@ FontMetrics.prototype.getMetrics = function(family, size) {
852857 return this . data [ family + "-" + size ] ;
853858} ;
854859
855- function FrameContainer ( container , sameOrigin , proxy ) {
860+ function FrameContainer ( container , sameOrigin , options ) {
856861 this . image = null ;
857862 this . src = container ;
858863 var self = this ;
859864 var bounds = getBounds ( container ) ;
860- this . promise = ( ! sameOrigin ? this . proxyLoad ( proxy , bounds ) : new Promise ( function ( resolve ) {
865+ this . promise = ( ! sameOrigin ? this . proxyLoad ( options . proxy , bounds , options ) : new Promise ( function ( resolve ) {
861866 if ( container . contentWindow . document . URL === "about:blank" || container . contentWindow . document . documentElement == null ) {
862867 container . contentWindow . onload = container . onload = function ( ) {
863868 resolve ( container ) ;
@@ -866,15 +871,15 @@ function FrameContainer(container, sameOrigin, proxy) {
866871 resolve ( container ) ;
867872 }
868873 } ) ) . then ( function ( container ) {
869- return html2canvas ( container . contentWindow . document . documentElement , { type : 'view' , proxy : proxy } ) ;
874+ return html2canvas ( container . contentWindow . document . documentElement , { type : 'view' , proxy : options . proxy , javascriptEnabled : options . javascriptEnabled , removeContainer : options . removeContainer } ) ;
870875 } ) . then ( function ( canvas ) {
871876 return self . image = canvas ;
872877 } ) ;
873878}
874879
875- FrameContainer . prototype . proxyLoad = function ( proxy , bounds ) {
880+ FrameContainer . prototype . proxyLoad = function ( proxy , bounds , options ) {
876881 var container = this . src ;
877- return loadUrlDocument ( container . src , proxy , container . ownerDocument , bounds . width , bounds . height ) ;
882+ return loadUrlDocument ( container . src , proxy , container . ownerDocument , bounds . width , bounds . height , options ) ;
878883} ;
879884
880885function GradientContainer ( imageData ) {
@@ -982,7 +987,7 @@ ImageLoader.prototype.loadImage = function(imageData) {
982987 } else if ( imageData . method === "svg" ) {
983988 return new SVGNodeContainer ( imageData . args [ 0 ] , this . support . svg ) ;
984989 } else if ( imageData . method === "IFRAME" ) {
985- return new FrameContainer ( imageData . args [ 0 ] , this . isSameOrigin ( imageData . args [ 0 ] . src ) , this . options . proxy ) ;
990+ return new FrameContainer ( imageData . args [ 0 ] , this . isSameOrigin ( imageData . args [ 0 ] . src ) , this . options ) ;
986991 } else {
987992 return new DummyImageContainer ( imageData ) ;
988993 }
0 commit comments