CoreWebView2ServiceWorker.PostWebMessageAsJson(String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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. Both the AreWebViewScriptApisEnabledForServiceWorkers and IsWebMessageEnabled settings 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.