From d1ccb7e47f5bc6d569e76b773f019eb07ab42065 Mon Sep 17 00:00:00 2001 From: Phil Ruffwind Date: Fri, 8 Apr 2022 22:48:03 -0700 Subject: [PATCH] Update js_usage.markdown to use onRuntimeInitialized The Emscripten library is not guaranteed to be fully loaded during the script element's onload event. Module.onRuntimeInitialized seems to be more reliable. --- doc/js_tutorials/js_setup/js_usage/js_usage.markdown | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/doc/js_tutorials/js_setup/js_usage/js_usage.markdown b/doc/js_tutorials/js_setup/js_usage/js_usage.markdown index 7992fd4096..c543b5dd79 100644 --- a/doc/js_tutorials/js_setup/js_usage/js_usage.markdown +++ b/doc/js_tutorials/js_setup/js_usage/js_usage.markdown @@ -122,11 +122,14 @@ imgElement.onload = function() { mat.delete(); }; -function onOpenCvReady() { - document.getElementById('status').innerHTML = 'OpenCV.js is ready.'; -} +var Module = { + // https://emscripten.org/docs/api_reference/module.html#Module.onRuntimeInitialized + onRuntimeInitialized() { + document.getElementById('status').innerHTML = 'OpenCV.js is ready.'; + } +}; - + @endcode