Share via


CoreWebView2ServiceWorker.PostWebMessageAsJson(String) Method

Definition

Posts the specified webMessageAsJson to this worker. The worker receives the message by subscribing to the message event of the self.chrome.webview of the worker.

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

        The event args is an instance of `MessageEvent`. The
        `ICoreWebView2Settings::IsWebMessageEnabled` setting must be `TRUE` or
        the web message will not be sent. The `data` property of the event arg 
        is the `webMessageAsJson` string parameter parsed as a JSON string into a 
        JS object. The `source` property of the event arg is the path
        to the worker script. The message is delivered asynchronously. 
        If the worker is terminated or destroyed before the message is posted,
        the message is discarded.
        Worker Javascript may subscribe and unsubscribe to the event 
        using the following code:
        ```javascript
        self.chrome.webview.addEventListener('message', handler)
        self.chrome.webview.removeEventListener('message', handler)
        ```
        ```cpp
        See also the equivalent methods: `ICoreWebView2::PostWebMessageAsJson`,
        `ICoreWebView2Frame::PostWebMessageAsJson`,
        `ICoreWebView2DedicatedWorker::PostWebMessageAsJson`.
        ```
public void PostWebMessageAsJson(string webMessageAsJson);
member this.PostWebMessageAsJson : string -> unit
Public Sub PostWebMessageAsJson (webMessageAsJson As String)

Parameters

webMessageAsJson
String

Applies to