Never found a single functioning example of WKScriptMessageHandlerWithReply using the replyHandler with the signature func userContentController(
_ userContentController: WKUserContentController,
didReceive message: WKScriptMessage,
replyHandler: @MainActor (Any?, String?) -> Void
Don't believe it has ever worked.
You can reliably add a message handler and capture a javascript message pushed to WkWebView by window.webkit.messageHandlers....postMessage, but the replyHandler back to javascript always fails with JavaScript evaluation error: Error Domain=WKErrorDomain Code=5 "JavaScript execution returned a result of an unsupported type" UserInfo={NSLocalizedDescription=JavaScript execution returned a result of an unsupported type}.
This has been going on for at least 7 years.
Tried every permutation of Sendable, MainActor. Javascipt push reliably works, reply back fails.
Don't think a sample exists.
Would like one.
Topic:
Programming Languages
SubTopic:
Swift
Tags: