Html2canvas: Chrome/Chromium "Not allowed to navigate top frame to data URL" error

Created on 19 Nov 2017  路  1Comment  路  Source: niklasvh/html2canvas

In Chrome and Chromium, upon calling

html2canvas(document.getElementsByClassName('console'), {
    onrendered: function(canvas) {
      var img = canvas.toDataURL()
      window.open(img);
    }
 });

html2canvas opens the window that should contain my console element only to display this error:

Not allowed to navigate top frame to data URL:

Followed by the URL that should display the image.

Most helpful comment

I was able to find a work around by using an iframe like such:

  html2canvas(document.getElementsByClassName('console'), {
      onrendered: function(canvas) {
        var img = canvas.toDataURL()
        var iframe = '<iframe src="' + img + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>'
        var x = window.open();
        x.document.open();
        x.document.write(iframe);
        x.document.close();
      }
    });

But note that the display in Chrome still has issues as mentioned here: #1272

>All comments

I was able to find a work around by using an iframe like such:

  html2canvas(document.getElementsByClassName('console'), {
      onrendered: function(canvas) {
        var img = canvas.toDataURL()
        var iframe = '<iframe src="' + img + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>'
        var x = window.open();
        x.document.open();
        x.document.write(iframe);
        x.document.close();
      }
    });

But note that the display in Chrome still has issues as mentioned here: #1272

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tjchambers32 picture tjchambers32  路  3Comments

arzyu picture arzyu  路  3Comments

yasergh picture yasergh  路  5Comments

AlphaDu picture AlphaDu  路  4Comments

dking3876 picture dking3876  路  4Comments