Langue

CoreWebView2DedicatedWorker.PostWebMessageAsJson(String) Method

Definition

Posts the specified webMessageAsJson to this worker.

public void PostWebMessageAsJson(string webMessageAsJson);
member this.PostWebMessageAsJson : string -> unit
Public Sub PostWebMessageAsJson (webMessageAsJson As String)

Parameters

webMessageAsJson
String

The web message to be posted to this worker.

Examples

Runs the message event of the self.chrome.webview of this worker. Worker Javascript may subscribe and unsubscribe to the event using the following code:

self.chrome.webview.addEventListener('message', handler)
self.chrome.webview.removeEventListener('message', handler)

Remarks

The event args is an instance of MessageEvent. The IsWebMessageEnabled setting must be true or the message will not be sent. The event arg's data property of the event arg is the webMessageAsJson string parameter parsed as a JSON string into a JavaScript object. The event arg's source property of the event arg is the path to the worker script. For information about sending messages from the worker to the host, navigate to WebMessageReceived. The message is sent asynchronously. If the worker is terminated or destroyed before the message is posted, the message is discarded.

Applies to

See also