bubkoo / html-to-image

✂️ Generates an image from a DOM node using HTML5 canvas and SVG.
MIT License
5.63k stars 523 forks source link

Safari Doesn't display images from URL (CORS enabled) - no error thrown #147

Closed bardzh closed 2 years ago

bardzh commented 3 years ago

Images loaded from URL is not being rendered in safari, chrome has no issues

Expected Behavior

To display images that are provided by url

Current Behavior

Renders a placeholder in size of the original photo but brings empty

Steps To Reproduce

Your Environment

vivcat[bot] commented 3 years ago

👋 @bardiaheshmati

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

valtism commented 3 years ago

I have this too, but the funny thing is that it only happens on the first try. When I run it a second time, the images are produced correctly. I wonder if it is a thing where Safari is not allowing time for the images to download.

bardzh commented 3 years ago

yes i noticed that too. i don't know if fetching photos are asynchronous or there is something blocking the first view, i noticed a flash like reloading of the photo when i scroll up and down, and exactly after that flash, the photos render again.

valtism commented 3 years ago

This might be an unhelpful comment, but after having edge case after edge case breaking across multiple libraries, I solved my problem by doing the canvas manipulation by hand. My use-case was not overly complicated and working with the canvas directly turned out to not be as scary as I though. If you have a simple enough use-case you might want to consider doing this.

bardzh commented 3 years ago

i tried, converting to canvas to SVG in a hope that it will turn the photo to a base64 and then to jpeg. it doesn't really work.

pouu69 commented 3 years ago

i have same issue. how can i use it?

Blackfaded commented 3 years ago

Having the same issue.

muuuuminn commented 3 years ago

I faced the same issue. Please give me a workaround.

muuuuminn commented 3 years ago

My workaround is doing html-to-image twice.

const convertHtml2Image = async (element, isSafari) => {
  if (isSafari) {
    await toPng(element, { cacheBust: true })
  }
  await toPng(element, { cacheBust: true, }).then((dataUrl) => {
    const link = document.createElement('a')
    link.download = 'my-image-name.png'
    link.href = dataUrl
    link.click()
  })
}
vivcat[bot] commented 3 years ago

Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not-stale" to keep this issue open! As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request.

Thanks for being a part of the Antv community! 💪💯

vivcat[bot] commented 2 years ago

Hey again! It’s been 60 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to comment on this issue or create a new one if you need anything else. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Thanks again for being part of the Antv community! 💪💯

hansanwok commented 2 years ago

For me, twice sometimes is nto enough, I loop util it been as expected let imgBase64

  imgBase64 = await toPng(captureRef.current, options)

  while (isSafari && imgBase64.length < 100000) {
    imgBase64 = await toPng(captureRef.current, options)
  }
vivcat[bot] commented 1 year ago

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.