diff --git a/src/library_html5_webgl.js b/src/library_html5_webgl.js
index 370e7b8a25b9c..6f1b4787b9429 100644
--- a/src/library_html5_webgl.js
+++ b/src/library_html5_webgl.js
@@ -45,6 +45,7 @@ var LibraryHtml5WebGL = {
emscripten_webgl_do_create_context__deps: [
#if OFFSCREENCANVAS_SUPPORT
'malloc',
+ 'emscripten_supports_offscreencanvas',
#endif
#if PTHREADS && OFFSCREEN_FRAMEBUFFER
'emscripten_webgl_create_context_proxied',
@@ -95,7 +96,7 @@ var LibraryHtml5WebGL = {
dbg('Performance warning: forcing renderViaOffscreenBackBuffer=true and preserveDrawingBuffer=true since proxying WebGL rendering.');
#endif
// We will be proxying - if OffscreenCanvas is supported, we can proxy a bit more efficiently by avoiding having to create an Offscreen FBO.
- if (typeof OffscreenCanvas == 'undefined') {
+ if (!_emscripten_supports_offscreencanvas()) {
{{{ makeSetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.renderViaOffscreenBackBuffer, '1', 'i32') }}};
{{{ makeSetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.preserveDrawingBuffer, '1', 'i32') }}};
}
@@ -115,12 +116,12 @@ var LibraryHtml5WebGL = {
if (canvas.offscreenCanvas) canvas = canvas.offscreenCanvas;
#if GL_DEBUG
- if (typeof OffscreenCanvas != 'undefined' && canvas instanceof OffscreenCanvas) dbg(`emscripten_webgl_create_context: Creating an OffscreenCanvas-based WebGL context on target "${targetStr}"`);
+ if (_emscripten_supports_offscreencanvas() && canvas instanceof OffscreenCanvas) dbg(`emscripten_webgl_create_context: Creating an OffscreenCanvas-based WebGL context on target "${targetStr}"`);
else if (typeof HTMLCanvasElement != 'undefined' && canvas instanceof HTMLCanvasElement) dbg(`emscripten_webgl_create_context: Creating an HTMLCanvasElement-based WebGL context on target "${targetStr}"`);
#endif
if (contextAttributes.explicitSwapControl) {
- var supportsOffscreenCanvas = canvas.transferControlToOffscreen || (typeof OffscreenCanvas != 'undefined' && canvas instanceof OffscreenCanvas);
+ var supportsOffscreenCanvas = canvas.transferControlToOffscreen || (_emscripten_supports_offscreencanvas() && canvas instanceof OffscreenCanvas);
if (!supportsOffscreenCanvas) {
#if OFFSCREEN_FRAMEBUFFER
diff --git a/test/canvas_animate_resize.cpp b/test/canvas_animate_resize.cpp
index 937a4678c9692..a0ed944a012b1 100644
--- a/test/canvas_animate_resize.cpp
+++ b/test/canvas_animate_resize.cpp
@@ -126,14 +126,14 @@ int main()
printf("Created context with handle %u\n", (unsigned int)ctx);
if (!ctx)
{
- EM_ASM({
- if (typeof OffscreenCanvas === 'undefined') {
+ if (!emscripten_supports_offscreencanvas()) {
+ EM_ASM({
xhr = new XMLHttpRequest();
xhr.open('GET', 'http://localhost:8888/report_result?skipped:%20OffscreenCanvas%20is%20not%20supported!');
xhr.send();
setTimeout(function() { window.close() }, 2000);
- }
- });
+ });
+ }
return 0;
}
emscripten_webgl_make_context_current(ctx);