Safari silently returns PNG when WebP encoding is requested via canvas API
A developer building a browser-based image converter discovered that Safari does not support WebP encoding through the HTML canvas API, despite being able to decode WebP since Safari 14. When a WebP is requested via canvas.toBlob(), Safari silently falls back to PNG without throwing an error or warning, as the HTML spec permits. This means users can unknowingly download a PNG file mislabeled with a .webp extension, which may cause failures in downstream systems. The only reliable fix is to explicitly check the returned blob's MIME type after the call. When canvas encoding cannot be trusted, developers must ship a WebAssembly-compiled codec like libwebp directly, which introduces its own set of build-tool challenges in environments like Vite.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in