I was using the async IJSRuntime to run JsInterrop function in my WASM project with a JS module to load the function.
private readonly Lazy<Task<IJSObjectReference>> moduleTask; public LocalJsInterop(IJSRuntime jsRuntime) { moduleTask = new(() => jsRuntime.InvokeAsync<IJSObjectReference>("import", "./../_content/WebPlayerControls/localJsInterop.js").AsTask()); }and then using it like that to call a function
public async ValueTask<string> GetWindowLocation() { var module = await moduleTask.Value; string value = await module.InvokeAsync<string>("GetWindowLocation"); return value; }I just saw recently that I can use IJSInProcessRuntime to run the function synchronously and tried to change my functions to use it.
But I can't get my module to work. I tried to init it like this
module = jsRuntime.Invoke<IJSObjectReference>("import", "./../_content/WebPlayerControls/localJsInterop.js");But then it wouldn't give access to the sync Invoke<> but only the asnyc InvokeAsync<>
I could probably put the functions in the index.html to use them but I was wondering if I could still work with the module. Does someone know how to make the import module work in a synchronous way ?
EDIT
I tried using IJSInProcessObjectReference like this
private readonly Lazy<IJSInProcessObjectReference> moduleTask; public LocalJsInterop(IJSInProcessRuntime jsRuntime) { moduleTask = new(() => jsRuntime.Invoke<IJSInProcessObjectReference>("import", "./../_content/WebPlayerControls/localJsInterop.js")); m_jsRuntime = jsRuntime; } public void ShowMessage() { var module = moduleTask.Value; module.InvokeVoid("ShowMessage"); }But now the code execution is stuck at the InvokeVoid line. And if I try to use the InvokeVoidAsync, it give a no function found exception