onRuntimeInitialized is called in Firefox but not in Chrome

57 views
Skip to first unread message

Thomas Grund

unread,
Jun 12, 2025, 6:11:12 PMJun 12
to emscripten-discuss
Hello,

(I want to pass large strings (around 100 MB) from JavaScript to C++ in the first place.
This is a really reduced Code to show the problem, even if the code makes no sense anymore.)
The Code IsNotWorking.html is working in Firefox but not in Chrome. Working means, that I can see the two console outputs:

within onRuntimeInitialized
within loadString


The Code IsWorking.html is working in Firefox and in Chrome.
The difference is just two lines which are not needed at all.
Even by just commenting out these two lines, it does not work in Chrome.
I put the code on Github, since there are large strings involved:


Windows 11, emcc 4.0.3, Firefox 139.0.4 64 Bit, Chrome 137.0.7151.104 64 Bit
Can somebody reproduce this?

Thanks for Your help!!




Sam Clegg

unread,
Jun 12, 2025, 6:48:33 PMJun 12
to emscripte...@googlegroups.com
If you want to be sure that `onRuntimeInitialized` is called you need to set it on the `Module` object before you import the generated code.  Otherwise the runtime could get initialized before you set `Module.onRuntimeInitialized`.

In debug builds you should see a warning when these things happen in the wrong order.  See `consumedModuleProp('onRuntimeInitialized');` for how this is supposed to work.

cheers,
sam

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/emscripten-discuss/fe17b884-8722-4e70-a7c5-6a1b655bb088n%40googlegroups.com.

Thomas Grund

unread,
Jun 13, 2025, 5:05:49 AMJun 13
to emscripten-discuss
Ah ok, it is working now by changing order and putting `var Module={};` in front of `Module.onRuntimeInitialized=function() {...`.
Thanks for explaining!

Thomas

Sam Clegg

unread,
Jun 13, 2025, 2:16:55 PMJun 13
to emscripte...@googlegroups.com
On Fri, Jun 13, 2025 at 2:05 AM Thomas Grund <thomas.g...@gmail.com> wrote:
Ah ok, it is working now by changing order and putting `var Module={};` in front of `Module.onRuntimeInitialized=function() {...`.

Great!

You could also do `var Module = { onRuntimeInitialized = () => ... }` .

BTW, did you try a debug build?  Can you confirm if you saw the assertion/warning about assigning to onRuntimeInitialized too late?

Thomas Grund

unread,
Jun 15, 2025, 3:52:10 PMJun 15
to emscripten-discuss
I compiled with `emcc -g ...` and did not get any message in the browser console.

Sam Clegg

unread,
Jun 16, 2025, 2:56:42 PMJun 16
to emscripte...@googlegroups.com
On Sun, Jun 15, 2025 at 12:52 PM Thomas Grund <thomas.g...@gmail.com> wrote:
I compiled with `emcc -g ...` and did not get any message in the browser console.

Did you also compile with `-O0` ?  Or rather, without `-O1` or above? 

Thomas Grund

unread,
Jun 18, 2025, 6:41:20 AMJun 18
to emscripten-discuss
I checked the `-O0` without getting assertions/warnings.
Reply all
Reply to author
Forward
0 new messages