ICoreWebView2WebMessageReceivedEventArgs.TryGetWebMessageAsString

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

The caller must free the returned string with CoTaskMemFree. See API Conventions.

interface ICoreWebView2WebMessageReceivedEventArgs
HRESULT
TryGetWebMessageAsString

Meta