My client-side image conversion works on desktop, but canvas WebP export appears to fall back on iOS Safari. Is there a reliable way to detect support, and what are the practical alternatives?
Why won't canvas export WebP on iOS Safari?
Answers
Test the actual output rather than checking the browser version. Try toDataURL with image/webp on a small canvas, then check whether the result starts with data:image/webp. If it starts with data:image/png, the browser fell back instead of encoding WebP.
For toBlob, check the returned blob's type as well. Handle a null blob or an export error separately, since those aren't the same thing as an unsupported format. Use a nonempty canvas for the test.
Reply to this answer
If WebP is a requirement, a WebAssembly encoder is a reasonable fallback. A library wrapping libwebp can save you from maintaining your own build, though it adds download size and encoding work on the device. Use native canvas export when the feature test passes and load the fallback when it doesn't.
Reply to this answer
Do you actually need WebP before upload? You could upload the original and generate a WebP on the server, then cache the result for delivery. That moves the processing off the phone, but it won't reduce the initial upload size.
Reply to this answer
PNG is the simple fallback if a larger upload is acceptable. Canvas is required to support PNG export, while WebP encoding isn't required. Being able to display a WebP image doesn't necessarily mean the browser can encode one from canvas.
Reply to this answer
I'd be careful about treating this as true for every iOS version. There's a conflicting report of WebP canvas export working on a recent version, so test the devices and versions you support rather than assuming a permanent platform-wide limitation. The discussion doesn't establish when broader native support might arrive.
Reply to this answer
Add your answer
Answers are reviewed before publication.
glue_stick_enthusiast:
Also keep the filename and upload metadata in sync with the actual output. A PNG fallback shouldn't be sent as though it were WebP.