Skip to content

Commit

Permalink
chore(core): Protect OffscreenCanvas reference in Node (#2266)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen authored Sep 20, 2024
1 parent 1e63cd7 commit bd65557
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions modules/core/src/adapter/canvas-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export abstract class CanvasContext {
this.id = props.id || this.canvas.id;
this.type = 'html-canvas';
this.htmlCanvas = this.canvas;
} else if (this.canvas instanceof OffscreenCanvas) {
} else if (typeof OffscreenCanvas !== 'undefined' && this.canvas instanceof OffscreenCanvas) {
this.id = props.id || 'offscreen-canvas';
this.type = 'offscreen-canvas';
this.offscreenCanvas = this.canvas;
Expand Down Expand Up @@ -459,10 +459,14 @@ function getContainer(container: HTMLElement | string | null): HTMLElement {
/** Get a Canvas element from DOM id */
function getCanvasFromDOM(canvasId: string): HTMLCanvasElement {
const canvas = document.getElementById(canvasId);
if (!(canvas instanceof HTMLCanvasElement)) {
if (
typeof canvas !== 'undefined' &&
typeof HTMLCanvasElement !== 'undefined' &&
!(canvas instanceof HTMLCanvasElement)
) {
throw new Error('Object is not a canvas element');
}
return canvas;
return canvas as HTMLCanvasElement;
}

/** Create a new canvas */
Expand Down

0 comments on commit bd65557

Please sign in to comment.