interface ICoreWebView2ExperimentalDiagnosticMonitor

Note

This an experimental API that is shipped with our prerelease SDK. See WebView2 release notes.

interface ICoreWebView2ExperimentalDiagnosticMonitor
  : public IUnknown

A diagnostic monitor that receives diagnostic signals from all layers - WebView, Profile, and Environment.

Summary

Members Descriptions
add_DiagnosticReceived Adds an event handler for the DiagnosticReceived event.
Close Release the diagnostic subscription and any registered handlers.
remove_DiagnosticReceived Removes an event handler previously added with add_DiagnosticReceived.
RemoveDiagnosticFilter Removes the diagnostic filter for the specified category.
SetDiagnosticFilter Sets a diagnostic filter for the specified category.

Created via ICoreWebView2ExperimentalEnvironment16::CreateDiagnosticMonitor. Each monitor has its own filters and event handlers, allowing multiple independent consumers (for example, one for telemetry, one for a debug panel).

The monitor is active from creation until it is released. Releasing the monitor automatically stops all events and clears all filters.

All members of this interface must be called on the same thread that created the ICoreWebView2Environment. Calling from a different thread returns RPC_E_WRONG_THREAD. Handlers must not block this thread.

Applies to

Product Introduced
WebView2 Win32 N/A
WebView2 Win32 Prerelease 1.0.4181

Members

add_DiagnosticReceived

Adds an event handler for the DiagnosticReceived event.

public HRESULT add_DiagnosticReceived(ICoreWebView2ExperimentalDiagnosticReceivedEventHandler * eventHandler, EventRegistrationToken * token)

Subscribes to diagnostic events on this monitor. The handler is invoked on the thread that created the environment. It fires every time a diagnostic signal passes a filter set with SetDiagnosticFilter.

Multiple handlers can be registered. They are invoked in registration order.

Close

Release the diagnostic subscription and any registered handlers.

public HRESULT Close()

The application should call this API when no access to the monitor is needed any more, to ensure that the underlying resources are released timely even if the monitor object itself is not released due to some leaked reference.

remove_DiagnosticReceived

Removes an event handler previously added with add_DiagnosticReceived.

public HRESULT remove_DiagnosticReceived(EventRegistrationToken token)

RemoveDiagnosticFilter

Removes the diagnostic filter for the specified category.

public HRESULT RemoveDiagnosticFilter(COREWEBVIEW2_DIAGNOSTIC_CATEGORY category)

After this call, DiagnosticReceived will no longer fire for events in this category.

If no filter was previously set for the category, this method is a no-op and returns S_OK.

SetDiagnosticFilter

Sets a diagnostic filter for the specified category.

public HRESULT SetDiagnosticFilter(COREWEBVIEW2_DIAGNOSTIC_CATEGORY category, LPCWSTR jsonFilter)

After this call, DiagnosticReceived will fire for events in this category that match the JSON criteria.

The filter JSON schema is category-specific and is documented on the corresponding COREWEBVIEW2_DIAGNOSTIC_CATEGORY enum value.

Pass "{}" as jsonFilter to receive all events in the category without field-level filtering.

Calling this method again for the same category replaces the previous filter for that category.

Returns E_INVALIDARG if jsonFilter is an empty string, is malformed JSON, or does not match the category's filter schema. On failure, the filter state is unchanged.