Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit cdbe599

Browse files
authored
Fix offscreen canvas breaking with split-brained firefox support (#7440)
1 parent 8339d5f commit cdbe599

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/ContentMessages.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,18 @@ async function createThumbnail(
127127
}
128128

129129
let canvas: HTMLCanvasElement | OffscreenCanvas;
130-
if (window.OffscreenCanvas) {
130+
let context: CanvasRenderingContext2D;
131+
try {
131132
canvas = new window.OffscreenCanvas(targetWidth, targetHeight);
132-
} else {
133+
context = canvas.getContext("2d");
134+
} catch (e) {
135+
// Fallback support for other browsers (Safari and Firefox for now)
133136
canvas = document.createElement("canvas");
134137
(canvas as HTMLCanvasElement).width = targetWidth;
135138
(canvas as HTMLCanvasElement).height = targetHeight;
139+
context = canvas.getContext("2d");
136140
}
137141

138-
const context = canvas.getContext("2d");
139142
context.drawImage(element, 0, 0, targetWidth, targetHeight);
140143

141144
let thumbnailPromise: Promise<Blob>;

0 commit comments

Comments
 (0)