title: html2canvas(document.body).then(function(canvas) {} not call
body: <p>I want to call <strong>html2canvas(document.body).then(function(canvas){});</strong> in <code>javaScript</code> function on <code>button</code> <code>click</code>.</p>
  
  <h3>Working Code:</h3>
  
  <pre><code>function action () {
      if (elementScope == "body") {
           alert("generating pdf.........2");
           //alert("canvas........."+canvas)
  
          alert("document.body......."+document.body)
          //mypdf();
          html2canvas(document.body).then(function(canvas){
              alert("html2canvas called...!!!");
              var imageFullQuality = canvas.toDataURL();
              var docDefinition = {
                  content: [{
                      image : imageFullQuality,
                      width : widthCanvas,
                  }]
          };
          alert("generating pdf.........4");
          new  pdfMake.createPdf(docDefinition).download(fileName + ".pdf");
          });
      }
  }
  </code></pre>
  
  <h3>Error Code</h3>
  
  <p><strong>html2canvas(document.body).then(function(canvas){});</strong> not getting call and remaining code will execute properly.</p>
  
  <pre><code>this.action = function action() {
      if (elementScope == "body") {
           alert("generating pdf.........2");
           //alert("canvas........."+canvas)
  
          alert("document.body......."+document.body)
          //mypdf();
          html2canvas(document.body).then(function(canvas){
              alert("html2canvas called...!!!");
              var imageFullQuality = canvas.toDataURL();
              var docDefinition = {
                  content: [{
                      image : imageFullQuality,
                      width : widthCanvas,
                  }]
              };
              alert("generating pdf.........4");
              new  pdfMake.createPdf(docDefinition).download(fileName + ".pdf");
          });
      }
  }
  </code></pre>
  
  <p>What is problem here didn't get. Please help me.</p>