Beispiel #1
0
        private void ProcessFailed(object sender, CoreWebView2ProcessFailedEventArgs e)
        {
            string message = $"Browser process failed...{Environment.NewLine}Description: {Description}{Environment.NewLine}Version: { CoreWebView2Environment.GetAvailableBrowserVersionString()}{Environment.NewLine}Url: {CurrentUrl}{Environment.NewLine}Error: {e.ProcessFailedKind}";

            Errors.AddToCrashFile(message);
            Errors.ReportProblem(message, "Fear not though, Arksplorer will attempt to keep going!", "Browser crashed!");
            RecreateBrowser();
            Navigate(CurrentUrl);
        }
Beispiel #2
0
        void WebView_ProcessFailed(object sender, CoreWebView2ProcessFailedEventArgs e)
        {
            void ReinitIfSelectedByUser(CoreWebView2ProcessFailedKind kind)
            {
                string caption;
                string message;

                if (kind == CoreWebView2ProcessFailedKind.BrowserProcessExited)
                {
                    caption = "Browser process exited";
                    message = "WebView2 Runtime's browser process exited unexpectedly. Recreate WebView?";
                }
                else
                {
                    caption = "Web page unresponsive";
                    message = "WebView2 Runtime's render process stopped responding. Recreate WebView?";
                }

                var selection = MessageBox.Show(message, caption, MessageBoxButton.YesNo);

                if (selection == MessageBoxResult.Yes)
                {
                    // The control cannot be re-initialized so we setup a new instance to replace it.
                    // Note the previous instance of the control has been disposed of and removed from
                    // the visual tree before attaching the new one.
                    WebView2 replacementControl = GetReplacementControl();
                    if (_isControlInVisualTree)
                    {
                        RemoveControlFromVisualTree(webView);
                    }
                    // Dispose of the control so additional resources are released. We do this only
                    // after creating the replacement control as properties for the replacement
                    // control are taken from the existing instance.
                    webView.Dispose();
                    webView = replacementControl;
                    AttachControlToVisualTree(webView);
                }
            }

            void ReloadIfSelectedByUser(CoreWebView2ProcessFailedKind kind)
            {
                string caption;
                string message;

                if (kind == CoreWebView2ProcessFailedKind.RenderProcessExited)
                {
                    caption = "Web page unresponsive";
                    message = "WebView2 Runtime's render process exited unexpectedly. Reload page?";
                }
                else
                {
                    caption = "App content frame unresponsive";
                    message = "WebView2 Runtime's render process for app frame exited unexpectedly. Reload page?";
                }

                var selection = MessageBox.Show(message, caption, MessageBoxButton.YesNo);

                if (selection == MessageBoxResult.Yes)
                {
                    webView.Reload();
                }
            }

            bool IsAppContentUri(Uri source)
            {
                // Sample virtual host name for the app's content.
                // See CoreWebView2.SetVirtualHostNameToFolderMapping: https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.setvirtualhostnametofoldermapping
                return(source.Host == "appassets.example");
            }

            switch (e.ProcessFailedKind)
            {
            case CoreWebView2ProcessFailedKind.BrowserProcessExited:
                // Once the WebView2 Runtime's browser process has crashed,
                // the control becomes virtually unusable as the process exit
                // moves the CoreWebView2 to its Closed state. Most calls will
                // become invalid as they require a backing browser process.
                // Remove the control from the visual tree so the framework does
                // not atempt to redraw it, which would call the invalid methods.
                RemoveControlFromVisualTree(webView);
                goto case CoreWebView2ProcessFailedKind.RenderProcessUnresponsive;

            case CoreWebView2ProcessFailedKind.RenderProcessUnresponsive:
                System.Threading.SynchronizationContext.Current.Post((_) =>
                {
                    ReinitIfSelectedByUser(e.ProcessFailedKind);
                }, null);
                break;

            case CoreWebView2ProcessFailedKind.RenderProcessExited:
                System.Threading.SynchronizationContext.Current.Post((_) =>
                {
                    ReloadIfSelectedByUser(e.ProcessFailedKind);
                }, null);
                break;

            case CoreWebView2ProcessFailedKind.FrameRenderProcessExited:
                // A frame-only renderer has exited unexpectedly. Check if reload is needed.
                // In this sample we only reload if the app's content has been impacted.
                foreach (CoreWebView2FrameInfo frameInfo in e.FrameInfosForFailedProcess)
                {
                    if (IsAppContentUri(new System.Uri(frameInfo.Source)))
                    {
                        goto case CoreWebView2ProcessFailedKind.RenderProcessExited;
                    }
                }
                break;

            default:
                // Show the process failure details. Apps can collect info for their logging purposes.
                StringBuilder messageBuilder = new StringBuilder();
                messageBuilder.AppendLine($"Process kind: {e.ProcessFailedKind}");
                messageBuilder.AppendLine($"Reason: {e.Reason}");
                messageBuilder.AppendLine($"Exit code: {e.ExitCode}");
                messageBuilder.AppendLine($"Process description: {e.ProcessDescription}");
                System.Threading.SynchronizationContext.Current.Post((_) =>
                {
                    MessageBox.Show(messageBuilder.ToString(), "Child process failed", MessageBoxButton.OK);
                }, null);
                break;
            }
        }
Beispiel #3
0
 private void CoreWebView2_ProcessFailed(object sender, CoreWebView2ProcessFailedEventArgs e)
 {
     MessageBox.Show($"WebView2 ProcessFailed {e.ProcessFailedKind}");
 }