Contents

WKJSHandle

A WKJSHandle object contains a reference to a JavaScript object.

Declaration

class WKJSHandle

Overview

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 WKContentWorld that has allowJSHandleCreation set to YES

  • The most recent navigation in the WKWebView had WKWebpagePreferences.allowsJSHandleCreationInPageWorld set to YES

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:...]

Topics

Instance Properties

Instance Methods

See Also

Page content