canvas.toBlob() silently falls back to PNG when requested format is unsupported
A developer building a client-side image converter discovered that the browser's canvas.toBlob() API does not throw an error when it cannot encode a requested format such as WebP or AVIF. Instead, it silently returns a valid PNG file while calling the callback as if the operation succeeded. This behavior is not a bug but is documented specification, meaning users can unknowingly download a larger PNG file believing they received modern compressed output. The only way to detect the silent fallback is to manually compare the returned blob's MIME type against the originally requested format. Developers can guard against this by throwing an explicit error when the types do not match, allowing the application to surface a meaningful message to the user.
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