From 11071a5972de19c426b39addb2d1ae824375edb2 Mon Sep 17 00:00:00 2001 From: Gator Date: Mon, 5 Jun 2023 09:29:46 +0200 Subject: [PATCH] feat (canvas): OffscreenCanvas fallback --- src/components/CanvasBoard.vue | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/CanvasBoard.vue b/src/components/CanvasBoard.vue index 1de00d2..d196ef8 100644 --- a/src/components/CanvasBoard.vue +++ b/src/components/CanvasBoard.vue @@ -81,10 +81,19 @@ store.renderer.ctx = store.renderer.canvas.getContext("2d", { willReadFrequently: true, }); - store.renderer.workCanvas = new OffscreenCanvas( - canvas.parentElement.clientWidth, - canvas.parentElement.clientHeight - ); + if (typeof OffscreenCanvas != "undefined") { + store.renderer.workCanvas = new OffscreenCanvas( + canvas.parentElement.clientWidth, + canvas.parentElement.clientHeight + ); + } + // https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/OffscreenCanvas#Browser_compatibility + // Fallback for when offscreenCanvas is unsupported or disabled (Firefox < 44, default for Firefox?) + else { + store.renderer.workCanvas = document.createElement("canvas"); + store.renderer.workCanvas.width = canvas.parentElement.clientWidth; + store.renderer.workCanvas.height = canvas.parentElement.clientHeight; + } store.renderer.workCtx = store.renderer.workCanvas.getContext("2d", { willReadFrequently: true, }); -- 2.45.2