<!--
{
  "availability" : [
    "iOS: 27.0.0 -",
    "iPadOS: 27.0.0 -",
    "macCatalyst: 27.0.0 -",
    "macOS: 27.0.0 -",
    "visionOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WKJSHandle",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(cs)WKJSHandle"
  },
  "title" : "WKJSHandle"
}
-->

# WKJSHandle

A WKJSHandle object contains a reference to a JavaScript object.

```
@MainActor class WKJSHandle
```

## Overview\discussion 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

[`var contentWorld: WKContentWorld?`](/documentation/WebKit/WKJSHandle/contentWorld)

[`var sourceFrame: WKFrameInfo`](/documentation/WebKit/WKJSHandle/sourceFrame)

### Instance Methods

[`func getWindowProxyFrame(completionHandler: (WKFrameInfo?) -> Void)`](/documentation/WebKit/WKJSHandle/getWindowProxyFrame(completionHandler:))

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`Equatable`](/documentation/Swift/Equatable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Hashable`](/documentation/Swift/Hashable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)