Browser's convertToBlob() silently returns PNG when requested format fails
A developer building client-side file tools discovered that the browser's canvas.convertToBlob() API does not throw an error or reject a promise when given an unsupported image format. Instead, it silently falls back to PNG while resolving successfully, meaning a file saved as photo.avif could actually contain PNG data. Testing in Chrome confirmed that AVIF encoding is unsupported via canvas, despite browsers widely supporting AVIF decoding. The recommended fix is a simple post-call check comparing blob.type against the requested type, throwing a clear error if they differ. The author advises against silent format substitution, arguing it replicates the same deceptive bug and that WebP already covers most practical conversion needs without extra dependencies.
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