Data exchange between HTML5 build and JS

I was wondering is there a way to exchange data between HTML5 game build and JavaScript in the browser?

The official documentations says that Unreal uses emscripten to compile C++ code to JS, and emscripten itself seems to have ways to expose functions to JS and to call inline scripts:

https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#interacting-with-code-access-memory

However, I haven’t found any info on how to use these functions in my Unreal C++ code. I am relatively new to the engine as well as C++ in general, so I don’t feel confident enough to do any experiments myself yet, but maybe someone has already tried to do something similar?

Say, I would like to type a name to an HTML form and then display it in my game — how would I do that?

UE4 does feed all user C++ files through the Emscripten compiler, so it should be possible to just type in Emscripten-specific code. Something like:

#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#endif

int someFunc()
{
#ifdef __EMSCRIPTEN__
  EM_ASM(console.log('hello, this is from Javascript'));
#endif
}

To get a string from JavaScript land, you can do something like

void someFunc()
{
#ifdef __EMSCRIPTEN__
  char utf8StringInCHeap[256];
  EM_ASM_INT({
    var javaScriptString = "from JavaScript";
    stringToUTF8(javaScriptString, $0, $1);
  }, utf8StringInCHeap, 256);
  printf("This is a string: %s\n", utf8StringInCHeap);
#endif
}

The stringToUTF8(javaScriptString, memoryAreaInHeapForString, memoryAreaSize); function takes a JavaScript string and converts that to UTF8-encoded form in UE4 heap area. UE4 internal logging functions often like to take in UTF32, so further converting UTF8 to UTF32 may be needed depending on where you are pushing the string to.

That’s a place to start, thanks!