Hi!
I'm trying to invoke a JSFunction callback on a single page application (SPA) written in React in the EO.WebView.
I'm having issues with my JSObject/JSFunction pointers as they seem to become invalid at certain points.
The function is sent from JS to .NET with something like:
Code: JavaScript
window.external.SetCallback(this, functionName)
and is received on the C# side like:
Code: C#
public void SetCallback(JSObject context, JSFunction callback) {
this.Context = context;
this.Callback = callback;
}
When it's time to trigger the callback it's called like:
Code: C#
private void TriggerCallback(object[] args) {
try {
if(this.WebView.CanEvalScript)
this.Callback.Invoke(this.Context, true, args);
} catch(Exception e) {
Debug.WriteLine(e.Message);
}
}
This method works for a while. But when the SPA changes some state, an exception is thrown:
Code: C#
Invoking function '' failed because object is invalid
This happens when a user signs in or out, even though the page has not been reloaded. The function and object sent to .NET is still accessible on the JS side.
The way I interpret this is that the pointer that .NET has available gets "out of sync" after a while.
Do you have any suggestions of how to fix or debug this?
Is there any other way of sending callbacks to JS?
Best regards
Anton