mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-13 01:07:18 +00:00
More defensive use of isTypeSupported
This commit is contained in:
@@ -1,12 +1,19 @@
|
|||||||
import { drawableToImageData } from '../canvas';
|
import { drawableToImageData } from '../canvas';
|
||||||
|
|
||||||
const hasImageDecoder = typeof ImageDecoder !== 'undefined';
|
const hasImageDecoder = typeof ImageDecoder !== 'undefined';
|
||||||
|
|
||||||
export async function isTypeSupported(mimeType: string): Promise<boolean> {
|
export async function isTypeSupported(mimeType: string): Promise<boolean> {
|
||||||
if (!hasImageDecoder) {
|
if (!hasImageDecoder) return false;
|
||||||
|
// Some old versions of this API threw here.
|
||||||
|
// It only impacted folks with experimental web platform flags enabled in Chrome 90.
|
||||||
|
// The API was updated in Chrome 91.
|
||||||
|
try {
|
||||||
|
return await ImageDecoder.isTypeSupported(mimeType);
|
||||||
|
} catch (err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return ImageDecoder.isTypeSupported(mimeType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function decode(
|
export async function decode(
|
||||||
blob: Blob | File,
|
blob: Blob | File,
|
||||||
mimeType: string,
|
mimeType: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user