cefsharp / cefsharp/CefSharp

CefSharp.WinForms.Example.netcore crashes when popup window

Đang mở
#4,656 5 bình luận 0 reaction 0 người được giao Xem trên GitHub
upstream
Ngôn ngữ chính
C#
Star
10.3k
Fork
2.9k
Merge trung bình
5 ngày 22 giờ
Pull request đã merge (30 ngày)
4

Mô tả

### Is there an existing issue for this?

- [X] I have searched both open/closed issues, no issue already exists.

### CefSharp Version

120.1.80

### Operating System

Windows 11

### Architecture

x64

### .Net Version

.Net 6.0

### Implementation

WinForms

### Reproduction Steps

1. Run CefSharp.WinForms.Example.netcore
2. Show popup window
3. Close popup window
4. Repeat 2 - 3.

### Expected behavior

Expectations is that it will not crash when you close the popup window

### Actual behavior

![crash](https://github.com/cefsharp/CefSharp/assets/53356723/7e7c58f5-ac77-4dbc-932a-461451f0d634)

### Regression?

_No response_

### Known Workarounds

Is this due to DoClose in LifeSpanHandler.cs?
Excluding control.Dispose() from InnvokeSyncOnUiThreadIfRequired stops crashing.

### Does this problem also occur in the CEF Sample Application

No

### Other information

html source
``` html

Popup!
Close!

const popup_open = () => {
window.open("index.html?pop=on")
}
const popup_close = () => {
parent.window.close()
}
const params = new URLSearchParams(document.location.search)
if (params.has("pop")) {
document.getElementById("open").style.display = "none"
document.title = "Popup!!"
} else {
document.getElementById("close").style.display = "none"
document.title = "Popup Main"
}

```
edit source code
CefSharp.WinForms\Handler\LifeSpanhandler.cs
``` c#
control.InvokeSyncOnUiThreadIfRequired(new Action(() =>
{
onPopupDestroyed?.Invoke(control, browser);

//control.Dispose(); // Comment out!!
}));
// Add
control.InvokeOnUiThreadIfRequired(new Action(() =>
{
control.Dispose();
}));
```
CefSharp.WinForms.Example\BrowserTabUserControl.cs
``` c#
.OnPopupDestroyed((ctrl, popupBrowser) =>
{
//If we docked DevTools (hosted it ourselves rather than the default popup)
//Used when the BrowserTabUserControl.ShowDevToolsDocked method is called
if (popupBrowser.MainFrame.Url.Equals("devtools://devtools/devtools_app.html"))
{
//Dispose of the parent control we used to host DevTools, this will release the DevTools window handle
//and the ILifeSpanHandler.OnBeforeClose() will be call after.
ctrl.Dispose();
}
else
{
//If browser is disposed or the handle has been released then we don't
//need to remove the tab in this example. The user likely used the
// File -> Close Tab menu option which also calls BrowserForm.RemoveTab
if (!ctrl.IsDisposed && ctrl.IsHandleCreated)
{
if (ctrl.FindForm() is BrowserForm owner)
{
owner.RemoveTab(ctrl);
}

//ctrl.Dispose(); // Comment out!!
}
}
})
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện chuỗi mở/đóng cửa sổ popup lặp lại trong CefSharp.WinForms.Example.netcore trên Windows 11 với .NET 6, sau đó kiểm tra CefSharp.WinForms\Handler\LifeSpanhandler.cs và BrowserTabUserControl.cs. Theo dõi callback DoClose và thứ tự giải phóng control, bao gồm workaround InvokeSyncOnUiThreadIfRequired được cung cấp. Được xem là hoàn thành khi việc đóng lặp lại các cửa sổ popup không còn gây crash và hành vi giải phóng DevTools hiện có vẫn được giữ nguyên.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
csharp
Lĩnh vực
desktop
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.