The AsyncExecute method evaluates a JavaScript
expression within the context of the currently loaded page and returns
the result asynchronously. Unlike Execute, this method
does not block while waiting for the script to complete. Instead, the
result is delivered through the ScriptCompleted event.
The script must be valid JavaScript and should not assume synchronous
execution. Results are returned in the event handler which will
provide you with the response in JSON-encoded form; for example,
string values will be quoted. Because script execution is dispatched
to the underlying WebView2 control, this function will fail if
navigation is still in progress. Applications should always
wait for the NavigationCompleted event before invoking
script execution.
JavaScript must be enabled for scripts to execute. The
AllowScripting property must be set to True when the browser
is created. If scripting is disabled, this method will fail indicating
that the operation is not supported.
The AddStartupScript method can be used to insert JavaScript
which is executed whenever a new document is loaded.