Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebView2 crash in combination with the print preview of PDF.js #3832

Closed
fvanheeswijk opened this issue Sep 29, 2023 · 12 comments
Closed

WebView2 crash in combination with the print preview of PDF.js #3832

fvanheeswijk opened this issue Sep 29, 2023 · 12 comments
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@fvanheeswijk
Copy link

fvanheeswijk commented Sep 29, 2023

Description
The WebView2 browser crashes when a page showing a PDF via PDF.js gets closed while the print preview dialog is open.

Version
SDK: 1.0.2045.28
Runtime: Stable 117.0.2045.43
Framework: Windows Forms
OS: Windows 11 (Version 22H2, Build 22621.2283)

Regression
Was this working before but has regressed? Not as far as we know as this is new functionality from our side.

Repro Steps
This issue can be reproduced by following the steps below after running the example application available below.

  1. Click the button below to open the pdf viewer.
  2. Use the toolbar to open the print preview.
  3. Wait for the print preview to be completely loaded.
  4. Close the entire form by pressing the Close button in the top right-hand corner of the window containing the pdf viewer.
  5. As a result the WebView2 instance on the first window will crash.
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;

using Microsoft.Web.WebView2.WinForms;

namespace WebView2PrintCrash
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(CreateTestForm(true));
        }

        public static Form CreateTestForm(bool initial)
        {
            var form = new Form
            {
                Size = new Size(1280, 1024)
            };

            var webView2 = new WebView2
            {
                Dock = DockStyle.Fill
            };
            webView2.EnsureCoreWebView2Async();
            webView2.CoreWebView2InitializationCompleted += (sender, e) =>
            {
                if (initial)
                {
                    webView2.CoreWebView2.AddHostObjectToScript("handler", new Handler(form));
                    webView2.CoreWebView2.NavigateToString(
    @"<html>
    <head>
        <title>Test</title>
    </head>
    <body>
        Steps to reproduce: <br>
        <ol>
            <li>Click the button below to open the pdf viewer.</li>
            <li>Use the toolbar to open the print preview.</li>
            <li>Wait for the print preview to be completely loaded.</li>
            <li>Close the entire form by pressing the Close button in the top right-hand corner of the window containing the pdf viewer.</li>
            <li>As a result the WebView2 instance on this window will crash.</li>
        </ol>
        <br>
        <button onclick='window.chrome.webview.hostObjects.sync.handler.openForm();'><h1>Open PDF Viewer</h1></button>
    </body>
</html>");
                }
                else
                {
                    webView2.CoreWebView2.NavigateToString(
@"<html>
	<head>
		<title>PDF Viewer</title>
		<style type='text/css'>
            html, body {
                padding: 0;
                margin: 0;
            }
			iframe {
				width: 100%;
				height: 100%;
                border: 0;
			}
		</style>
	</head>
	<body>
		<iframe src='https://mozilla.github.io/pdf.js/web/viewer.html' />
	</body>
</html>");
                }
            };

            form.Controls.Add(webView2);

            return form;
        }
    }

    [ComVisible(true)]
    public class Handler
    {
        private readonly Form owner;

        public Handler(Form owner)
        {
            this.owner = owner;
        }

        public void openForm()
        {
            var ownerHandle = owner.Handle;
            var thread = new Thread(() =>
            {
                var newForm = Program.CreateTestForm(false);
                newForm.Shown += (sender, e) => newForm.BringToFront();
                var nativeWindow = new NativeWindow();
                nativeWindow.AssignHandle(IntPtr.Zero);
                newForm.ShowDialog(nativeWindow);
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }
    }
}

AB#46815720

@fvanheeswijk fvanheeswijk added the bug Something isn't working label Sep 29, 2023
@fvanheeswijk fvanheeswijk changed the title WebView2 crash in combination with the print preview of pdf.js WebView2 crash in combination with the print preview of PDF.js Sep 29, 2023
@vickiez vickiez added the tracked We are tracking this work internally. label Oct 2, 2023
@fvanheeswijk
Copy link
Author

Is there any news on this?

@fabiorocha
Copy link
Member

@fvanheeswijk I wasn't able to repro in both Stable 117 and Canary 119. Do you have crash dumps you can share?

@fabiorocha fabiorocha reopened this Oct 9, 2023
@fabiorocha
Copy link
Member

Not repro.

@fabiorocha fabiorocha closed this as not planned Won't fix, can't repro, duplicate, stale Oct 9, 2023
@fvanheeswijk
Copy link
Author

@fabiorocha I don't understand why you cannot reproduce it, I just tried it again and it still reproduces.

Just to be clear, I am putting this code inside a new Windows Forms project created with Visual Studio 2019 using .NET Framework 4.7.2. There I added a NuGet reference to Microsoft.Web.WebView2. Then I run this code with the defaults of Debug and Any CPU.

Also, when opening the DevTools Console and executing navigator.userAgent the output is as follows:

'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.60'

I do have a minidump to share, please find it here: c58623e0-f809-4345-a41f-395e116812cd.zip.

@victorhuangwq victorhuangwq reopened this Oct 10, 2023
@victorhuangwq
Copy link
Collaborator

Reopening issue based on new information

@fvanheeswijk
Copy link
Author

Is there any news on this?

@lflores-ms
Copy link
Contributor

Hi @fvanheeswijk,

Thanks for your report. We confirmed a repro of this issue and made a fix. It should be available in latest Canary 121.0.2261.0. You can try it out by following these steps: Approaches to making your app use a specific browser channel.

@fvanheeswijk
Copy link
Author

@lflores-ms The browser indeed does not crash anymore, that is good news! However the print preview does not load anymore in the Canary 121.0.2262.0 build, this seems to be a regression.

@lflores-ms
Copy link
Contributor

Confirmed repro in Canary 122.0.2337.0
Issue does not repro in Beta 121.0.2277.49 or Stable 120.0.2210.133

@lflores-ms lflores-ms reopened this Jan 13, 2024
@fvanheeswijk
Copy link
Author

Unfortunately the print preview not loading issue has never been fixed so now it got into the beta runtime. I made a new issue about this: #4371.

@victorhuangwq
Copy link
Collaborator

Thanks for the re-report @fvanheeswijk.

@fabiorocha
Copy link
Member

Resolving this issue as the crash has been resolved and will track the loading problem separately in #4371

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

5 participants