Skip to content

Avalonia: Executing EvaluateScript<string> returns always null #392

@systec-tressin

Description

@systec-tressin

I use the WebView for Displaying the MonacoEditor in my Avalonia Project. And I'm trying to get the content of the Editor by executing window.monacoEditor.getValue() in JavaScript. Which works in a normal browser, but not with webView.EvaluateScript<T>().

Here's my implementation:

private async Task SaveCode()
    {
        if (_webView != null && _webView.IsJavascriptEngineInitialized)
        {
            var result = await _webView.EvaluateScript<string>("window.monacoEditor.getValue()");
            
            Console.WriteLine("result: " + result);
        }
    }

But what works is _webView.ExecuteScript("window.monacoEditor.setValue('value')");. My I guess is that there might some type of timing issue.

I hope some of yall can help me out :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions