html-to-image: Uncaught (in promise) error { target: img, isTrusted: true, srcElement: img, … }

Expected Behavior

download png image of provided element (body)

Current Behavior

I get this error but can’t get more details from the developer console :

Uncaught (in promise) 
error { target: img, isTrusted: true, srcElement: img, eventPhase: 0, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, composed: false, timeStamp: 5207770, … }

Steps To Reproduce

here is what is done :

  • html-to-image.js (1.11.11) is retrieved from https://cdnjs.com/libraries/html-to-image
  • its contents is copied and pasted into the Firefox browser’s developer console (console returns true without any error)
  • (according to the advanced examples) this piece of code is then played in the developer console
htmlToImage.toPng(document.body).then(function(dataUrl) {
	var link = document.createElement('a');
	link.download = 'test';
	link.href = dataUrl;
	link.click();
});

Your Environment

  • html-to-image: 1.11.11
  • OS: ArchLinux
  • Browser: Firefox 127.0

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 12
  • Comments: 20 (1 by maintainers)

Most upvoted comments

Thanks @fzn0x

What fixed the issue for me was that, when dealing with images hosted in s3, you should invalidate the cache for the requested image, like so:

toPng(ref.current, {
    fetchRequestInit: {
        method: 'GET',
        cache: 'no-cache'   // <-- Important!
    }
})

For anybody else dealing with this problem, try this before attempting something more sophisticated.

I am facing the same issue right now image

I cannot even know whats the error

This issue persists on Firefox

Any updates on this?

Found solution that works fine on my end, but it’s pain to compress any assets inside the canvas one by one, anyone could improve this solution anyway

https://gist.github.com/fzn0x/d41864e95c7412087b859139ef49aa1b

cc @Stanley-Jovel

Thanks @leCheveuCodeur

basically you need to keep your canvas size as small as possible

I think it’s due to the size of the image generated, because the image attached to the error is 32mo on my side, whereas it’s specified in the doc that there may be problems if the DOM is huge. [Rendering will failed on huge DOM due to the dataURI limit varies.](https://github.com/bubkoo/html-to-image?tab=readme-ov-file#things-to-watch-out-for) https://stackoverflow.com/questions/695151/data-protocol-url-size-limitations/41755526#41755526

Hello, is there anything new on this issue?

Any news?

Hello, is there anything new on this issue?

Same error here using firefox. When using Edge the image gets downloaded with no issues. image