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

# WKScriptMessage

An object that encapsulates a message sent by JavaScript code from a webpage.

```
@MainActor class WKScriptMessage
```

## Overview

Use a [`WKScriptMessage`](/documentation/WebKit/WKScriptMessage) object to get details about a JavaScript message sent to a custom message handler in your app. You don’t create [`WKScriptMessage`](/documentation/WebKit/WKScriptMessage) objects directly. When JavaScript code targets one of your app’s message handlers, the [`WKUserContentController`](/documentation/WebKit/WKUserContentController) object of the web view creates a [`WKScriptMessage`](/documentation/WebKit/WKScriptMessage) object and delivers it to the message handler’s delegate method. Use the object you’re provided to process the message and provide an appropriate response.

For more information about handling script messages, see the [`WKScriptMessageHandler`](/documentation/WebKit/WKScriptMessageHandler) and [`WKScriptMessageHandlerWithReply`](/documentation/WebKit/WKScriptMessageHandlerWithReply) protocols. For information about how to register message handlers, see the methods of [`WKUserContentController`](/documentation/WebKit/WKUserContentController).

## Topics

### Getting the Message Contents

[`body`](/documentation/WebKit/WKScriptMessage/body)

The body of the message.

### Getting Message-Related Information

[`frameInfo`](/documentation/WebKit/WKScriptMessage/frameInfo)

The frame that sent the message.

[`webView`](/documentation/WebKit/WKScriptMessage/webView)

The web view that sent the message.

[`world`](/documentation/WebKit/WKScriptMessage/world)

The namespace in which the JavaScript code executes.

### Getting the Message Handler’s Name

[`name`](/documentation/WebKit/WKScriptMessage/name)

The name of the message handler to which the message is sent.



---

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)