CoreWebView2.NavigationCompleted Event

Definition

NavigationCompleted is raised when the WebView has completely loaded (body.onload has been raised) or loading stopped with error.

public event EventHandler<Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs> NavigationCompleted;
member this.NavigationCompleted : EventHandler<Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs> 
Public Custom Event NavigationCompleted As EventHandler(Of CoreWebView2NavigationCompletedEventArgs) 

Event Type

Examples

control.NavigationCompleted += WebView_NavigationCompleted;
void DOMContentLoadedCmdExecuted(object target, ExecutedRoutedEventArgs e)
{
    webView.CoreWebView2.DOMContentLoaded += WebView_DOMContentLoaded;
    webView.CoreWebView2.FrameCreated += WebView_FrameCreatedDOMContentLoaded;
    webView.NavigateToString(@"<!DOCTYPE html>" +
                              "<h1>DOMContentLoaded sample page</h1>" +
                              "<h2>The content to the iframe and below will be added after DOM content is loaded </h2>" +
                              "<iframe style='height: 200px; width: 100%;'/>");
    webView.CoreWebView2.NavigationCompleted += (sender, args) =>
    {
        webView.CoreWebView2.DOMContentLoaded -= WebView_DOMContentLoaded;
        webView.CoreWebView2.FrameCreated -= WebView_FrameCreatedDOMContentLoaded;
    };
}

void WebView_DOMContentLoaded(object sender, CoreWebView2DOMContentLoadedEventArgs arg)
{
    _ = webView.ExecuteScriptAsync(
            "let content = document.createElement(\"h2\");" +
            "content.style.color = 'blue';" +
            "content.textContent = \"This text was added by the host app\";" +
            "document.body.appendChild(content);");
}

Applies to