Partager via


CoreWebView2NavigationCompletedEventArgs Class

Event args for the CoreWebView2.NavigationCompleted event.

Summary

Members Description
HttpStatusCode The HTTP status code of the navigation if it involved an HTTP request. For instance, this will usually be 200 if the request was successful, 404 if a page was not found, etc. See https://developer.mozilla.org/docs/Web/HTTP/Status for a list of common status codes.
IsSuccess true when the navigation is successful; false for a navigation that ended up in an error page (failures due to no network, DNS lookup failure, HTTP server responds with 4xx). Note that WebView2 will report the navigation as 'unsuccessful' if the load for the navigation did not reach the expected completion for any reason. Such reasons include potentially catastrophic issues such network and certificate issues, but can also be the result of intended actions such as the app canceling a navigation or navigating away before the original navigation completed. Applications should not just rely on this flag, but also consider the reported WebErrorStatus to determine whether the failure is indeed catastrophic in their context.
NavigationId Gets the ID of the navigation.
WebErrorStatus Gets the error code if the navigation failed.

Properties

HttpStatusCode

readonly int HttpStatusCode

The HTTP status code of the navigation if it involved an HTTP request. For instance, this will usually be 200 if the request was successful, 404 if a page was not found, etc. See https://developer.mozilla.org/docs/Web/HTTP/Status for a list of common status codes. The HttpStatusCode property will be 0 in the following cases:

  • The navigation did not involve an HTTP request. For instance, if it was a navigation to a file:// URL, or if it was a same-document navigation.
  • The navigation failed before a response was received. For instance, if the hostname was not found, or if there was a network error.

In those cases, you can get more information from the CoreWebView2NavigationCompletedEventArgs.IsSuccess and CoreWebView2NavigationCompletedEventArgs.WebErrorStatus properties.

If the navigation receives a successful HTTP response, but the navigated page calls window.stop() before it finishes loading, then HttpStatusCode may contain a success code like 200, but CoreWebView2NavigationCompletedEventArgs.IsSuccess will be false and CoreWebView2NavigationCompletedEventArgs.WebErrorStatus will be CoreWebView2WebErrorStatus.ConnectionAborted.

Since WebView2 handles HTTP continuations and redirects automatically, it is unlikely for HttpStatusCode to ever be in the 1xx or 3xx ranges.

IsSuccess

readonly bool IsSuccess

true when the navigation is successful; false for a navigation that ended up in an error page (failures due to no network, DNS lookup failure, HTTP server responds with 4xx). Note that WebView2 will report the navigation as 'unsuccessful' if the load for the navigation did not reach the expected completion for any reason. Such reasons include potentially catastrophic issues such network and certificate issues, but can also be the result of intended actions such as the app canceling a navigation or navigating away before the original navigation completed. Applications should not just rely on this flag, but also consider the reported WebErrorStatus to determine whether the failure is indeed catastrophic in their context. WebErrorStatuses that may indicate a non-catastrophic failure include:

This may also be false for additional scenarios such as window.stop() run on navigated page.

readonly uint64_t NavigationId

Gets the ID of the navigation.

WebErrorStatus

readonly CoreWebView2WebErrorStatus WebErrorStatus

Gets the error code if the navigation failed.

Referenced by