WKJSHandle
A WKJSHandle object contains a reference to a JavaScript object.
Declaration
class WKJSHandleOverview
There are various ways that JavaScript executing inside web content results in some return value being passed up to the WebKit application. Examples include calls to [WKWebView evaluateJavaScript:...], [WKWebView callAsyncJavaScript:...], and the body of a WKScriptMessage.
Usually these result objects are a foundational type, such as a number, string, array, dictionary, etc. In some environments the result object can be a WKJSHandle or be a container that contains one or more WKJSHandle objects. These environments are:
The JavaScript in question executed in a
WKContentWorldthat hasallowJSHandleCreationset toYESThe most recent navigation in the
WKWebViewhadWKWebpagePreferences.allowsJSHandleCreationInPageWorldset toYES
JavaScript running in those environments can make a WKJSHandle instead of following normal serialization rules by calling window.webkit.createJSHandle(...) with the target value as an argument.
Whatever JavaScript object the WKJSHandle represents, it will be protected from garbage collection for the lifetime of the WKJSHandle The WKJSHandle can also be used as an argument to future JavaScript run via [WKWebView callAsyncJavaScript:...]