Skip to content

API Review: Diagnostic Monitor API#5565

Open
chetanpandey1266 wants to merge 4 commits into
user/chetanpandey/DiagnosticMonitorAPIfrom
user/chetanpandey/DiagnosticMonitorAPI-draft
Open

API Review: Diagnostic Monitor API#5565
chetanpandey1266 wants to merge 4 commits into
user/chetanpandey/DiagnosticMonitorAPIfrom
user/chetanpandey/DiagnosticMonitorAPI-draft

Conversation

@chetanpandey1266
Copy link
Copy Markdown
Contributor

Add Diagnostic Monitor API spec — Introduces ICoreWebView2DiagnosticMonitor, a new observation-only API that
delivers diagnostic signals (e.g., network failures) from all WebViews, profiles, and the environment through a
single DiagnosticReceived event. Host apps create a monitor via CreateDiagnosticMonitor and opt in per category
using AddDiagnosticReceivedFilter.

@chetanpandey1266 chetanpandey1266 added the API Proposal Review WebView2 API Proposal for review. label Apr 15, 2026
Copy link
Copy Markdown

@shrinaths shrinaths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prose, Grammar, and Voice Review

Line-by-line pass focused on grammar, tone, and narrative voice consistency. Suggested corrections are inline below. The overall prose quality is good — these are polish items to bring the spec to Microsoft documentation standard.

Comment thread specs/DiagnosticMonitor.md
Comment thread specs/DiagnosticMonitor.md Outdated
Comment thread specs/DiagnosticMonitor.md
Comment thread specs/DiagnosticMonitor.md Outdated
Comment thread specs/DiagnosticMonitor.md
Comment thread specs/DiagnosticMonitor.md Outdated
Comment thread specs/DiagnosticMonitor.md Outdated
Comment thread specs/DiagnosticMonitor.md
Comment thread specs/DiagnosticMonitor.md
Comment thread specs/DiagnosticMonitor.md
Copy link
Copy Markdown

@shrinaths shrinaths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Sample Issue: The destructor calls m_monitor.Reset() without first calling remove_DiagnosticReceived. This teaches an anti-pattern — callbacks may fire during or after destruction. Best-practice samples should demonstrate proper cleanup order.

Suggested correction:

DiagnosticComponent::~DiagnosticComponent()
{
    if (m_monitor)
    {
        // Unsubscribe before releasing the monitor to
        // ensure no callbacks arrive during teardown.
        m_monitor->remove_DiagnosticReceived(
            m_diagnosticToken);
        m_monitor.Reset();
    }
}

Comment thread specs/DiagnosticMonitor.md
Copy link
Copy Markdown

@shrinaths shrinaths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see inline

Comment thread specs/DiagnosticMonitor.md Outdated
Copy link
Copy Markdown

@shrinaths shrinaths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see inline

Comment thread specs/DiagnosticMonitor.md Outdated
Copy link
Copy Markdown

@shrinaths shrinaths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see inline

Comment thread specs/DiagnosticMonitor.md
Copy link
Copy Markdown

@shrinaths shrinaths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see inline

Comment thread specs/DiagnosticMonitor.md Outdated
Copy link
Copy Markdown

@shrinaths shrinaths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see inline

Comment thread specs/DiagnosticMonitor.md
Comment thread specs/DiagnosticMonitor.md
Comment thread specs/DiagnosticMonitor.md
Comment thread specs/DiagnosticMonitor.md
Comment thread specs/DiagnosticMonitor.md Outdated
Comment thread specs/DiagnosticMonitor.md Outdated
/// `protocol` is the protocol scheme (e.g. "https").
/// `uri` is the request URI.
///
/// For categories the runtime does not yet populate,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking API Issue: Scope tells the kind of source (WebView/Profile/Environment) but not which instance produced the event. The filter supports profileName but the returned details JSON does not include it -- so you can filter by profile but cannot attribute received events to a profile. Add ProfileName and WebViewId properties to the event args: [propget] HRESULT ProfileName([out, retval] LPWSTR* value); [propget] HRESULT WebViewId([out, retval] LPWSTR* value); ProfileName should return empty string when Scope is Environment. WebViewId should return empty string when Scope is not WebView.

Copy link
Copy Markdown
Contributor Author

@chetanpandey1266 chetanpandey1266 Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that we can include profile name as an entry in JSON but for CoreWebView2, not sure which unique id might help here. We can have frame id or something but considering we are only having network error codes for now, would not include that here. Any other enum which might require such details can simply extend the json and add these details.

Comment thread specs/DiagnosticMonitor.md
Comment thread specs/DiagnosticMonitor.md
Comment thread specs/DiagnosticMonitor.md
Chetan Pandey and others added 2 commits April 27, 2026 14:16
…onvention alignment

- Fix grammar: 'An empty JSON' -> 'An empty JSON object' (2x)
- Clarify ambiguity: 'mixed-content blocks' -> 'mixed-content blocked requests'
- Use prescriptive language: 'should match' -> 'must match' in API contract
- Add missing 'that' in relative clause + imperative voice for CoTaskMemFree
- Remove markdown bold (**any**) from IDL comments (plain text only)
- Add missing comma after introductory phrase 'On failure'
- Split run-on sentence in event handler comment
- Add missing comma before 'but' in compound sentence
- Remove 'NetworkContext' reference from profile scope comment
- C++ destructor: unsubscribe before Reset() for proper cleanup order
- C# Dispose: unsubscribe before Dispose() for proper cleanup order
- Add _environment field declaration in filtered C# sample
- Name opaque error codes: ERR_NAME_NOT_RESOLVED (-105), ERR_TIMED_OUT (-7)
- Align section headers: 'COM' -> 'Win32 C++', '.NET C#' -> '.NET, WinRT'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@chetanpandey1266 chetanpandey1266 force-pushed the user/chetanpandey/DiagnosticMonitorAPI-draft branch from c4ce409 to 0894cc0 Compare April 27, 2026 09:28
@david-risney david-risney self-requested a review May 6, 2026 18:00
Comment thread specs/DiagnosticMonitor.md Outdated
/// }
/// ```
///
/// `errorCode` is the Chromium net error code (integer).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is chromium net error code already defined somewhere? If so link to that documentation. If not, you need to fully document the values this can be and what they mean.

/// `httpMethod` is the HTTP method string.
/// `elapsedTime` is the request duration in
/// milliseconds (integer).
/// `protocol` is the protocol scheme (e.g. "https").
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'scheme' may be a more accurate name if this is the URI's scheme name and not necessarily a network protocol

/// Network request failure including DNS resolution
/// errors, TLS handshake failures, connection timeouts,
/// HTTP error status codes (4xx/5xx), CORS violations,
/// and mixed-content blocked requests.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need more information about exactly what is being reported and when. If this corresponds with existing webview2 events you can describe it in terms of the existing events. Including when it happens in relation to the existing events (before, after, either)

If this doesn't correspond with an existing webview2 event, you need to spell out exactly what network requests this happens for. Like: is it only navigation network requests, or including sub-resource network requests, and fetch, or additionally things like service worker that's not associated with one webview2, or csp error reports that aren't under direct control/observation of a document?

And you say 'Network request failure including ...' which makes it sound like this doesn't fully describe the set of possible failures. If the full set of possible failures is defined by one of the properties that is fully defined you can say that. Otherwise you need to define that.

/// this method returns `"{}"`.
///
/// Free the returned string with `CoTaskMemFree`.
HRESULT GetDetailsAsJson(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a Get method rather than a property?

}

/// A diagnostic monitor that receives signals from
/// all layers. Implements IClosable for deterministic
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More elaboration about IClosable required here. What resources are held open and require the use of IClosable? And how does it work for COM - I don't see anything in the COM IDL for this (and I don't recall how that works - do we need something for COM?)

typedef enum COREWEBVIEW2_DIAGNOSTIC_SCOPE {
/// The diagnostic signal originated from a specific
/// WebView instance.
COREWEBVIEW2_DIAGNOSTIC_SCOPE_WEB_VIEW,
Copy link
Copy Markdown
Contributor

@david-risney david-risney May 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elsewhere we treat WebView as one word for this sort of thing eg _SCOPE_WEBVIEW (like at the front with COREWEBVIEW2_...)

[propget] HRESULT Timestamp(
[out, retval] INT64* value);

/// Returns category-specific diagnostic data as a JSON
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We prefer giving data an API versus representing it with JSON or some other format inside a string. Strings are a weak contract that skips our API tooling for compat validation and documentation, isn't discoverable via intellisense, gives the end devs more work to actually get a property value out.

If this was only for telemetry and the details string varied dramatically with no set form - like devtools console.log messages - then it would make sense to have it as a string. But in this case so far there's one kind of networking event that has a well-defined shape for a bunch of different kinds of errors.

Can we add a Details object that varies type based on the kind of error? Eg CoreWebView2DiagnosticReceivedEventArgs.Details property that for networking errors is a CoreWebView2DiagnosticNetworkErrorDetails class. Or if the networking error only corresponds to an existing event - use that existing event as the details object. And remove the SetDiagnosticFilter and instead allow the end dev to implement their own filtering using the details object.

COREWEBVIEW2_DIAGNOSTIC_SCOPE* value);

/// Monotonic timestamp in microseconds since an
/// unspecified epoch. You can use this value to order
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this an actual wall-clock time? Presumably the end dev will want to collect these diagnostic events together with diagnostic events from other sources and want to compare the timestamps.

/// `uri` is the request URI.
///
/// For categories that the runtime does not yet populate,
/// this method returns `"{}"`.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only have one category and it is populated. We shouldn't have any categories documented or used that aren't populated to avoid confusion and compat issues.

@chetanpandey1266 chetanpandey1266 force-pushed the user/chetanpandey/DiagnosticMonitorAPI-draft branch from daaab37 to 82a6439 Compare May 14, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API Proposal Review WebView2 API Proposal for review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants