Skip to content

Commit 6658e24

Browse files
authored
Custom Crash Reporting API Review (#2779)
Disable Crash Reporting Spec
1 parent a51796a commit 6658e24

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed

specs/DisableCrashReporting.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
Custom Crash Reports
2+
===
3+
4+
# Background
5+
If any WebView2 process crashes, one or multiple minidump files will be created and sent to Microsoft for diagnosis. This document covers new APIs to allow the end developer to customize crash reporting to help when running diagnostics and doing analysis. They can set the `CoreWebView2EnvironmentOptions.IsCustomCrashReportingEnabled` property to true to prevent crash dumps from being sent to Microsoft and use the `CoreWebView2Environment.CrashDumpFolderPath` property to locate crash dumps and do customization with them instead.
6+
7+
# Examples
8+
## WinRT and .NET
9+
```c#
10+
11+
/// Create WebView Environment with option
12+
13+
void CreateEnvironmentWithOption()
14+
{
15+
CoreWebView2EnvironmentOptions options = new CoreWebView2EnvironmentOptions();
16+
options.CustomizeFailureReporting = true;
17+
CoreWebView2Environment environment = await CoreWebView2Environment.CreateAsync(BrowserExecutableFolder, UserDataFolder, options);
18+
}
19+
20+
void WebView_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
21+
{
22+
webView.CoreWebView2.ProcessFailed += WebView_ProcessFailed;
23+
}
24+
25+
var _processed_dump_files = new HashSet<string>();
26+
27+
void WebView_ProcessFailed(object sender, CoreWebView2ProcessFailedEventArgs e)
28+
{
29+
// When process failed, do custom parsing with dumps
30+
string failureReportFolder = webView.CoreWebView2.Environment.FailureReportFolderPath;
31+
string[] dump_files = Directory.GetFiles(failureReportFolder);
32+
foreach (string dump_file in dump_files) {
33+
if (!_processed_dump_files.Contains(dump_file)) {
34+
_processed_dump_files.Add(dump_file);
35+
ProcessNewCrashDumps(dump_file);
36+
}
37+
}
38+
}
39+
40+
```
41+
## Win32 C++
42+
```cpp
43+
#include <filesystem>
44+
using namespace std;
45+
namespace fs = std::filesystem;
46+
47+
void AppWindow::InitializeWebView()
48+
{
49+
auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
50+
CHECK_FAILURE(options->put_CustomizeFailureReporting(TRUE));
51+
// ... other option properties
52+
53+
// ... CreateCoreWebView2EnvironmentWithOptions
54+
55+
// Set up handler
56+
wil::com_ptr<ICoreWebView2Environment> environment;
57+
CHECK_FAILURE(m_webView->get_Environment(&environment));
58+
wil::com_ptr<ICoreWebView2Environment11> environment11;
59+
CHECK_FAILURE(environment->QueryInterface(IID_PPV_ARGS(&environment11));
60+
wil::unique_cotaskmem_string failureReportFolder;
61+
CHECK_FAILURE(environment11->get_FailureReportFolderPath(&failureReportFolder));
62+
63+
std::set<fs::path> processed_dump_files;
64+
65+
// Register a handler for the ProcessFailed event.
66+
CHECK_FAILURE(m_webView->add_ProcessFailed(
67+
Callback<ICoreWebView2ProcessFailedEventHandler>(
68+
[this, processed_dump_files,
69+
failureReportFolder = std::move(failureReportFolder)](
70+
ICoreWebView2* sender,
71+
ICoreWebView2ProcessFailedEventArgs* argsRaw) -> HRESULT
72+
{
73+
for (const auto& entry: fs::directory_iterator(failureReportFolder.get()))
74+
{
75+
auto dump_file = entry.path().filename();
76+
if (processed_dump_files.count(dump_file) == 0)
77+
{
78+
processed_dump_files.insert(dump_file);
79+
ProcessNewCrashDumps(dump_file);
80+
}
81+
}
82+
return S_OK;
83+
})
84+
.Get(),
85+
&m_processFailedToken));
86+
}
87+
```
88+
89+
# API Details
90+
```
91+
interface ICoreWebView2Environment11;
92+
interface ICoreWebView2EnvironmentOptions3;
93+
94+
/// A continuation of the ICoreWebView2Environment interface for
95+
/// getting the crash dump folder path
96+
[uuid(F619312E-0399-4520-B700-30818441785A), object, pointer_default(unique)]
97+
interface ICoreWebView2Environment11 : ICoreWebView2Environment10 {
98+
/// `FailureReportFolderPath` get the folder path of where minidump files is written.
99+
/// Whenever a WebView2 process crashes, a crash dump file will be created in the crash dump folder.
100+
/// A crash dump format is minidump files, please see
101+
/// https://docs.microsoft.com/en-us/windows/win32/debug/minidump-files for detailed documentation.
102+
/// Normally when a single child process failed, a minidump will be generated and written to disk,
103+
/// then `ProcessFailed` event is raised. But for unexpected crashes, minidump might not be generated
104+
/// at all, despite whether `ProcessFailed` event is raised. For times, that there are multiple
105+
/// processes failed, multiple minidump files could be generated. Thus `FailureReportFolderPath`
106+
/// could contain old minidump files that are not associated with a specific `ProcessFailed` event.
107+
/// `FailureReportFolderPath` remains the same for the lifetime of the environment.
108+
// MSOWNERS: [email protected]
109+
[propget] HRESULT FailureReportFolderPath([out, retval] LPWSTR* value);
110+
}
111+
112+
/// Additional options used to create WebView2 Environment.
113+
[uuid(3FB94506-58AB-4171-9082-E7D683471A48), object, pointer_default(unique)]
114+
interface ICoreWebView2EnvironmentOptions3 : ICoreWebView2EnvironmentOptions2 {
115+
116+
/// When `CustomizeFailureReporting` is set to `TRUE`, Windows won't send crash data to Microsoft endpoint.
117+
/// `CustomizeFailureReporting` is default to be `FALSE`, in this case, WebView respect OS consent.
118+
// MSOWNERS: [email protected]
119+
[propget] HRESULT CustomizeFailureReporting([out, retval] BOOL* value);
120+
121+
/// Sets the `CustomizeFailureReporting` property.
122+
// MSOWNERS: [email protected]
123+
[propput] HRESULT CustomizeFailureReporting([in] BOOL value);
124+
}
125+
```
126+
127+
```c# (but really MIDL3)
128+
namespace Microsoft.Web.WebView2.Core
129+
{
130+
131+
// ...
132+
runtimeclass CoreWebView2EnvironmentOptions
133+
{
134+
// ...
135+
Boolean CustomizeFailureReporting { get; set; };
136+
}
137+
138+
runtimeclass CoreWebView2Environment
139+
{
140+
String FailureReportFolderPath { get; };
141+
}
142+
143+
// ...
144+
}
145+
```
146+

0 commit comments

Comments
 (0)