Skip to content

Latest commit

 

History

History
79 lines (52 loc) · 2.61 KB

icorewebview2webmessagereceivedeventargs.md

File metadata and controls

79 lines (52 loc) · 2.61 KB
description title ms.date keywords
Event args for the `WebMessageReceived` event.
WebView2 Win32 C++ ICoreWebView2WebMessageReceivedEventArgs
02/09/2022
IWebView2, IWebView2WebView, webview2, webview, win32 apps, win32, edge, ICoreWebView2, ICoreWebView2Controller, browser control, edge html, ICoreWebView2WebMessageReceivedEventArgs

interface ICoreWebView2WebMessageReceivedEventArgs

[!INCLUDE deprecation-note]

interface ICoreWebView2WebMessageReceivedEventArgs
  : 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.
TryGetWebMessageAsString If the message posted from the WebView content to the host is a string type, this method returns the value of that string.

Applies to

Product Introduced
WebView2 Win32 0.9.430
WebView2 Win32 Prerelease 0.9.488

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)

Run this operation to communicate using JavaScript objects.

For example, the following postMessage runs result in the following WebMessageAsJson values.

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

TryGetWebMessageAsString

If the message posted from the WebView content to the host is a string type, this method returns the value of that string.

public HRESULT TryGetWebMessageAsString(LPWSTR * webMessageAsString)

If the message posted is some other kind of JavaScript type this method fails with the following error.

E_INVALIDARG

Run this operation to communicate using simple strings.

For example, the following postMessage runs result in the following WebMessageAsString values.

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