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

Commit

Permalink
Fix offscreen canvas breaking with split-brained firefox support (#7440)
Browse files Browse the repository at this point in the history
  • Loading branch information
t3chguy authored Jan 4, 2022
1 parent 8339d5f commit cdbe599
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/ContentMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down

0 comments on commit cdbe599

Please sign in to comment.