Unity WebGL and browser communication

I have some issues regarding Unity WebGL and browser communication.

Is it possible to make JavaScript function for events onUnityFinishedLoading or onStartsPlaying?

On the opposite side when calling JavaScript from Unity functions returning strings return null. However functions returning int work fine.

This is a sample code for this:

var MyPlugin = {
    Hello: function()
    {
        window.alert("Hello, world!");
        return "5";
    },
    HelloStr: function()
    {
        window.alert("Hello, world! str");
        return "str 5";
    }
};

mergeInto(LibraryManager.library, MyPlugin);
using System.Runtime.InteropServices;

public class ExternalEval : MonoBehaviour
{
    [DllImport("__Internal")]
    private static extern int Hello();
    [DllImport("__Internal")]
    private static extern string HelloStr();

    // Use this for initialization
    void Start()
    {
        Debug.Log(Hello());
        Debug.Log(HelloStr());
    }
}

How do I resolve this issues?

If I understand, try override

UnityLoader.instantiate(
"",
"",
Module: {
                                   preInit: [onUnityStartInitializing],
                                   onRuntimeInitialized: onUnityInitialized,
                               }

You should allocate string on heap for return to C#

// in my case it's inside window for global scope, but you can create it inside your class
window.ConvertJsToHeapString = function(resultString)
{
    var bufferSize = lengthBytesUTF8(resultString) + 1; // (+1 null terminated)
    var buffer = _malloc(bufferSize);
    stringToUTF8(resultString, buffer, bufferSize);
    return buffer;
};

// Use this function as you need
myReturnStringFunc()
{
 var stringValue = "abc";
 return ConvertJsToHeapString(stringValue);
}