From e1176fe2bb75544752843919232c3a910f14061c Mon Sep 17 00:00:00 2001 From: bas-d <7903735+bas-d@users.noreply.github.com> Date: Sat, 11 May 2019 17:15:14 +0200 Subject: [PATCH 1/3] Override print and printErr --- dist-build/emscripten.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dist-build/emscripten.sh b/dist-build/emscripten.sh index d8975e5d..fb810781 100755 --- a/dist-build/emscripten.sh +++ b/dist-build/emscripten.sh @@ -99,6 +99,12 @@ if [ "$DIST" = yes ]; then Module.ready = new Promise(function(resolve, reject) { var Module = _Module; Module.onAbort = reject; + Module.print = function(what) { + console.log(what); + } + Module.printErr = function(what) { + console.warn(what); + } Module.onRuntimeInitialized = function() { try { /* Test arbitrary wasm function */ From 646c0cfd4621a04f7814fb29b75c9712e985cf0e Mon Sep 17 00:00:00 2001 From: bas-d <7903735+bas-d@users.noreply.github.com> Date: Sun, 12 May 2019 12:41:55 +0200 Subject: [PATCH 2/3] Check if console is null or undefined. --- dist-build/emscripten.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dist-build/emscripten.sh b/dist-build/emscripten.sh index fb810781..f5de28d9 100755 --- a/dist-build/emscripten.sh +++ b/dist-build/emscripten.sh @@ -100,10 +100,14 @@ if [ "$DIST" = yes ]; then var Module = _Module; Module.onAbort = reject; Module.print = function(what) { - console.log(what); + if (console != null) { + console.log(what); + } } Module.printErr = function(what) { - console.warn(what); + if (console != null) { + console.warn(what); + } } Module.onRuntimeInitialized = function() { try { From 1fd2422623db6e413054c79931cd4391598c9a1c Mon Sep 17 00:00:00 2001 From: bas-d <7903735+bas-d@users.noreply.github.com> Date: Sun, 12 May 2019 13:04:11 +0200 Subject: [PATCH 3/3] Properly check if console exists. --- dist-build/emscripten.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist-build/emscripten.sh b/dist-build/emscripten.sh index f5de28d9..4dfd899b 100755 --- a/dist-build/emscripten.sh +++ b/dist-build/emscripten.sh @@ -100,12 +100,12 @@ if [ "$DIST" = yes ]; then var Module = _Module; Module.onAbort = reject; Module.print = function(what) { - if (console != null) { + if (typeof(console) !== 'undefined') { console.log(what); } } Module.printErr = function(what) { - if (console != null) { + if (typeof(console) !== 'undefined') { console.warn(what); } }