How to change emscripten browser input method from window.prompt to something more sensible?

I have a C++ function which once called consumes input from stdin. Exporting this function to javascript using emscripten causes calls to window.prompt.

Interacting with browser prompt is really tedious task. First of all you can paste only one line at time. Secondly the only way to indicate EOF is by pressing 'cancel'. Last but not least the only way (in case of my function) to make it stop asking user for input by window.prompt is by checking the checkbox preventing more prompts to pop up.

For me the best input method would be reading some blob. I know I can hack library.js but I see some problems:

  1. Reading blob is asynchronous.
  2. To read a blob, first you have to open a file user has to select first.
  3. I don't really know how to prevent my function from reading this blob forever - there is no checkbox like with window.prompt and I'm not sure if spotting EOF will stop it if it didn't in window.prompt case (only checking a checkbox helped).

The best solution would be some kind of callback but I would like to see sime hints from more experienced users.

From what I understand you could try the following:

  1. Implement selecting a file in Javascript and access it via Javascript Blob interface.
  2. Allocate some memory in Emscripten

    var buf = Module._malloc( blob.size );
    
  3. Write the content of your Blob into the returned memory location from Javascript.

    Module.HEAPU8.set( new Uint8Array(blob), buf );
    
  4. Pass that memory location to a second Emscripten compiled function, which then processes the file content and

  5. Deallocate allocated memory.

    Module._free( buf );
    

Best to read the wiki first.