-
Notifications
You must be signed in to change notification settings - Fork 553
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
Blank Image in Safari #461
Comments
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. |
I also encountered this problem |
It seems to be a Safari bug that doesn't load the canvas immediately when the web page is rendered.
|
this works in mac safari but doesnt work in ios safari tho after 2-3 times the img does show |
Another way you can try is to loop the toCanvas function, but it's not the best practice because you don't know how many times to show the image.
|
In the same situation, the problems encountered in Safari are a headache, |
¿Has anyone found a better solution than the loop solution? |
Here's how I fixed mine in Safari. I added delay using modern-screenshot: https://github.com/qq15725/modern-screenshot/tree/main Which also came from html-to-image. `` |
@DMTaswebdevelopment There is no delay option. |
I used patch-package to patch Here is the diff that solved my problem: diff --git a/node_modules/html-to-image/es/index.js b/node_modules/html-to-image/es/index.js
index 0eda938..768f239 100644
--- a/node_modules/html-to-image/es/index.js
+++ b/node_modules/html-to-image/es/index.js
@@ -16,6 +16,10 @@ export async function toCanvas(node, options = {}) {
const { width, height } = getImageSize(node, options);
const svg = await toSvg(node, options);
const img = await createImage(svg);
+ const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
+ if (isSafari) {
+ await new Promise(resolve => setTimeout(resolve, 1000));
+ }
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
const ratio = options.pixelRatio || getPixelRatio(); |
We are basically trying to take screenshots of a div which has images as it's child the output we are getting has blank spaces instead of images this works fine on chrome but safari has this issue
The text was updated successfully, but these errors were encountered: