Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On firefox toPng returns empty image #146

Open
Thoronir42 opened this issue Jul 3, 2023 · 1 comment
Open

On firefox toPng returns empty image #146

Thoronir42 opened this issue Jul 3, 2023 · 1 comment

Comments

@Thoronir42
Copy link

Thoronir42 commented Jul 3, 2023

I've created a simple background markup and insert tool for images with transparency: HTML repro. This HTML file contains barebones for the background creation and dom-to-image-calling in a native code.

I might try to investigate the library inner workings later but as of now I can only provide this hopefully precise report.

Repro steps

  1. (have a HTML markup with some SVGs and CSS styling in an element matching .frame selector)
  2. execute domtoimage.toPng(el) and save it by clicking an anchor tag with download attribute:
function saveFile(dataUrl, filename) {
    const a = document.createElement("a")
    a.download = filename
    a.href = dataUrl
    a.click()
}
async function saveImg(el) {
    const img = await domtoimage.toPng(el)
    saveFile(img, "fancy-portrait.png")
}
saveImg(document.querySelector('.frame'))
  1. open saved image

Expected behavior

The resulting image should:

  • have 500px*500px
  • contain the DOM markup

Actual behavior (stack traces, console logs etc)

  • ✅ have 500px*500px
  • ❌ is all transparent

The console is empty and it seems like the library "finishes" successfully and just... skips some steps?

Library version

dom-to-image-more@3.1.6 using https://cdn.jsdelivr.net/npm/dom-to-image-more@3.1.6/dist/dom-to-image-more.min.js

Browsers

  • Chrome/114.0.0.0 : works fine
  • Firefox 114.0.2 (64-bit) : produces empty image
@Durss
Copy link

Durss commented Sep 1, 2023

This is apparently due to a super old issue on Firefox.
https://stackoverflow.com/questions/28690643/firefox-error-rendering-an-svg-image-to-html5-canvas-with-drawimage

TLDR: you need to specify a fixed width and height to make it work.

domtoimage.toPng(node, {width:600, height:200} );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants