-
Notifications
You must be signed in to change notification settings - Fork 570
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
Image is not showing in some cases iOS, Safari #361
Comments
Potential duplicates:
|
Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. 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. |
steps to reproduce:
sometimes it has enough time to load the image, sometimes it doesn't |
@asaleh267 a quick workaround is to execute the function several times (2 or 3 times) like this:
|
@asaleh267 this problem seems to be a bug of A temporary fix Example code: const loadedImageCounts = IS_SAFARI ? (context.images.size || 1) : 1
for (let i = 0; i < loadedImageCounts; i++) {
await new Promise<void>(resolve => {
setTimeout(() => {
try {
context?.drawImage(loaded, 0, 0, canvas.width, canvas.height)
} catch (error) {
console.warn('Failed to image to canvas', error)
}
resolve()
}, 100 + i)
})
} |
Some libs use promises, html-to-image for example. It runs in the background. Safari, perhaps in the name of performance, ignores these promises and the HTML is converted to PNG without the images included in the html block. Also avoid using .then and .catch in functions, opt for async functions with await. The solution below solved my problem:
|
This still doesn't solve the problem, I increase the number of calls to 5 times, but the picture still can't be loaded |
@Lucas-lululu is the image very big? I assume it may be related |
The workaround also is not working for me, and I don't think image size affects it. |
Instead of trying to guess the right number of times to call
This worked for me when working with large assets that took multiple attempts until the call worked. |
I don't think it's a good way to solve this problem. |
It's not. It's a workaround. |
I found that when I generated pictures, I would introduce a lot of fonts, so I disabled them all, and the pictures came out soon |
i have similar problem on the ios devices. but with |
This is the only thing that worked for me in Safari. Thank you! However, I would like to have a more clear understanding of why it's happening. |
This works with small images - but still having trouble with larger ones. Has anyone figured out a workaround? html2canvas works perfectly, but it's a little slower so I was really hoping to get html-to-image to work! |
Firstly: lol at this workaround. Can't believe it works. |
|
None of those variants work, if you have multiple different images on your element. they get replaces all with the same 1 image instead |
Any solid solutions? |
To optimize the only current solution, I did this.
|
This worked brilliantly for us. We had this issue when taking canvas images with any of the screenshot libraries including Modern Screenshot. Our issues were not specific to Safari, it was more towards any browser that was on iOS, Safari or Chromium.
|
#420 |
However odd this might seem but It worked for me. I only did one dummy call then the main call |
The html is converted to png without the images included in the html block.
It shows white background replaced instead of the images
It happens sometimes not everytime, specially on iOS, Safari devices
The text was updated successfully, but these errors were encountered: