This page demonstrates basic interaction between the host app and dedicated workers by means of Web Messages.
Messages can be posted from the host app to the dedicated worker on this document using
the APIs ICoreWebView2DedicatedWorker::PostWebMessageAsJson and
ICoreWebView2DedicatedWorker::PostWebMessageAsString.
Messages can be posted from the dedicated worker to the host app using
self.chrome.webview.postMessage. The host app can receive messages by
registering an event handler with
ICoreWebView2DedicatedWorker::add_WebMessageReceived.
This document creates a dedicated worker that listens for messages from the host app in the form of a command (ADD, SUB, MUL, DIV) and two numbers (first and second). It performs the specified arithmetic operation and responds with the result."
When the dedicated worker is created, a dialog will be opened to enter a message. Enter a
JSON string with a command and two numbers to receive a response from the worker. Ex:
{"command":"ADD","first":2,"second":3} will send a reply back with 5.