interface IWebView2WebMessageReceivedEventArgs

Note

This reference is no longer being maintained. For the latest API reference, see WebView2 API Reference.

interface IWebView2WebMessageReceivedEventArgs
  : public IUnknown

Event args for the WebMessageReceived event.

Summary

Members Descriptions
get_Source The URI of the document that sent this web message.
get_WebMessageAsJson The message posted from the webview content to the host converted to a JSON string.
get_WebMessageAsString If the message posted from the webview content to the host is a string type, this method will return the value of that string.

Members

get_Source

The URI of the document that sent this web message.

public HRESULT get_Source(LPWSTR * source)

get_WebMessageAsJson

The message posted from the webview content to the host converted to a JSON string.

public HRESULT get_WebMessageAsJson(LPWSTR * webMessageAsJson)

Use this to communicate via JavaScript objects.

For example the following postMessage calls result in the following WebMessageAsJson values:

postMessage({'a': 'b'})      L"{\"a\": \"b\"}"
postMessage(1.2)             L"1.2"
postMessage('example')       L"\"example\""

get_WebMessageAsString

If the message posted from the webview content to the host is a string type, this method will return the value of that string.

public HRESULT get_WebMessageAsString(LPWSTR * webMessageAsString)

If the message posted is some other kind of JavaScript type this method will fail with E_INVALIDARG. Use this to communicate via simple strings.

For example the following postMessage calls result in the following WebMessageAsString values:

postMessage({'a': 'b'})      E_INVALIDARG
postMessage(1.2)             E_INVALIDARG
postMessage('example')       L"example"