Search code examples
javascriptswiftios9wkwebview

What types (next to string) can be passed from JavaScript to Swift inside WKScriptMessage?


I know how to pass strings (e.g. from DOM text nodes) from JavaScript (inside an apps WKWebView) to Swift.

What other types are supported? For instance, could I pass DOM elements inside WKScriptMessage?


Solution

  • I have never seen any proper documentation for this. I have successfully put stuff in there that is JSON compatible.

    I don't think a DOM element works. But just try it and see what you get back. You may have to turn it into a simpler object first in JavaScript.