Fix offscreen canvas breaking with split-brained firefox support (#7440)

pull/21833/head
Michael Telatynski 2022-01-04 08:57:35 +00:00 committed by GitHub
parent 8339d5fdee
commit cdbe59900c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -127,15 +127,18 @@ async function createThumbnail(
}
let canvas: HTMLCanvasElement | OffscreenCanvas;
if (window.OffscreenCanvas) {
let context: CanvasRenderingContext2D;
try {
canvas = new window.OffscreenCanvas(targetWidth, targetHeight);
} else {
context = canvas.getContext("2d");
} catch (e) {
// Fallback support for other browsers (Safari and Firefox for now)
canvas = document.createElement("canvas");
(canvas as HTMLCanvasElement).width = targetWidth;
(canvas as HTMLCanvasElement).height = targetHeight;
context = canvas.getContext("2d");
}
const context = canvas.getContext("2d");
context.drawImage(element, 0, 0, targetWidth, targetHeight);
let thumbnailPromise: Promise<Blob>;