mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-30 20:18:08 +00:00
Check if HTMLCanvasElement exists (i.e. we are not running in a webworker) (#22153)
This fixes #22152 ### Description Tensor.fromImage fails in a webworker context, because HTMLCanvasElement does not exist: > HTMLCanvasElement is not defined ### Motivation and Context This fixes #22152 --------- Co-authored-by: Yulong Wang <7679871+fs-eire@users.noreply.github.com>
This commit is contained in:
parent
a47254eaef
commit
3494f80e83
1 changed files with 1 additions and 1 deletions
|
|
@ -152,7 +152,7 @@ export const tensorFromImage = async (
|
|||
}
|
||||
};
|
||||
const createCanvasContext = (canvas: HTMLCanvasElement | OffscreenCanvas) => {
|
||||
if (canvas instanceof HTMLCanvasElement) {
|
||||
if (typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement) {
|
||||
return canvas.getContext('2d');
|
||||
} else if (canvas instanceof OffscreenCanvas) {
|
||||
return canvas.getContext('2d') as OffscreenCanvasRenderingContext2D;
|
||||
|
|
|
|||
Loading…
Reference in a new issue