-
Notifications
You must be signed in to change notification settings - Fork 107
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
dome to image not working in iphone #192
Comments
I think i finally got to the bottom of this. Its the way theyre using inside svg, loading it to an image, and then writing the image to a canvas, and grabbing the objectURL from the canvas. In webkit, particularly mobile safari (i think youll see similar in PC safari as well) it does not like images with svgs loaded into them that are then written to a canvas. I have updated this method in the library
|
Interesting change... are we sure this works for all incoming I might a beta release for you to test, but I would really like a simple repro JSFiddle to ensure I have something to test against you use case. I also want to adjust to cloning/add order a bit as (as far as my testing shows), we should set the attributes and callbacks before adding the image to the SVG wrapper, and the SVG wrapper to the body (experience shows adding thing first seldom triggers the callbacks or applies the properties as expected). I'm also wondering if we should put this new behaviour behind an option flag (or perhaps at minimum keeping the old behaviour as an opt-in fallback option) |
... just FYI, you can easily create your own |
Is the double SVG really needed? Can we just create the image your way (e.g. Also, coded this way, the image is now part of the |
I'm suggesting perhaps this might work just as well for your use case... no extra SVG wrapper (just creating a SVG element instead of an Image) ... and adding/removing to the body... EDIT: NOPE. This only rendered a blank SVG... no support for non-SVG. More to come. function makeImage(uri) {
if (uri === 'data:,') {
return Promise.resolve();
}
return new Promise(function (resolve, reject) {
// Create an SVG element to house the image
const image = document.createElementNS('http://www.w3.org/2000/svg', 'image'); /* was new Image(); */
if (domtoimage.impl.options.useCredentials) {
image.crossOrigin = 'use-credentials';
}
image.onload = function () {
if (window && window.requestAnimationFrame) {
// In order to work around a Firefox bug (webcompat/web-bugs#119834) we
// need to wait one extra frame before it's safe to read the image data.
window.requestAnimationFrame(function () {
resolve(image);
});
} else {
// If we don't have a window or requestAnimationFrame function proceed immediately.
resolve(image);
}
// Cleanup: remove the SVG from the document
document.body.removeChild(image);
};
image.onerror = (error) => {
reject(error);
// Cleanup: remove the SVG from the document
document.body.removeChild(image);
};
// Add the SVG to the document body (invisible)
document.body.appendChild(image);
image.src = uri;
});
} |
So, this line breaks (almost) all unit-tests... Swapping back to function makeImage(uri) {
if (uri === 'data:,') {
return Promise.resolve();
}
return new Promise(function (resolve, reject) {
// Create an SVG element to house the image
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
// and create the Image element to insert into that wrapper
const image = new Image();
if (domtoimage.impl.options.useCredentials) {
image.crossOrigin = 'use-credentials';
}
image.onload = function () {
// Cleanup: remove theimage from the document
document.body.removeChild(svg);
if (window && window.requestAnimationFrame) {
// In order to work around a Firefox bug (webcompat/web-bugs#119834) we
// need to wait one extra frame before it's safe to read the image data.
window.requestAnimationFrame(function () {
resolve(image);
});
} else {
// If we don't have a window or requestAnimationFrame function proceed immediately.
resolve(image);
}
};
image.onerror = (error) => {
// Cleanup: remove the image from the document
document.body.removeChild(svg);
reject(error);
};
svg.appendChild(image);
image.src = uri;
// Add the SVG to the document body (invisible)
document.body.appendChild(svg);
});
} |
Drafted a v3.5.0-beta.0 release for you to try. |
I will try out this beta release. For me, this has completely fixed the webkit issues that have plagued (as you can see in reported bugs) users of this (really awesome) library for years now. I really hope this helps folks out. I had my back up against a wall for a deadline so hadn't made all of the tests pass yet, so appreciate you looking into it. I will check out the beta release shortly |
this seems to be as effective as what i did on the fly and posted here. Thanks for entertaining this change. |
@IDisposable so does this effectively mean you support WebKit and safari now with the newest release? |
I guess it does! That said, I have no ability to test anything in that environment, so it could break down the road (hope not). |
Hi,
I am using latest version of domtoimage and it works fine everywhere except iPhone. You can check it here on the live site https://www.thecanvasprints.co.uk/canvas?action=upload if you upload the image and click Add to Cart, it should open the preview in a popup. The preview open code is this;
The preview works fine in all browsers except if you check it on actual iPhone. It works fine if you view in chrome in iPhone mode but don't work on actual iPhone.
Please help.
The text was updated successfully, but these errors were encountered: