---
title: WKScriptMessage
framework: webkit
role: symbol
role_heading: Class
path: webkit/wkscriptmessage
---

# WKScriptMessage

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

## Declaration

```swift
@MainActor class WKScriptMessage
```

## Overview

Overview Use a WKScriptMessage object to get details about a JavaScript message sent to a custom message handler in your app. You don’t create WKScriptMessage objects directly. When JavaScript code targets one of your app’s message handlers, the WKUserContentController object of the web view creates a 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 and WKScriptMessageHandlerWithReply protocols. For information about how to register message handlers, see the methods of WKUserContentController.

## Topics

### Getting the Message Contents

- [body](webkit/wkscriptmessage/body.md)

### Getting Message-Related Information

- [frameInfo](webkit/wkscriptmessage/frameinfo.md)
- [webView](webkit/wkscriptmessage/webview.md)
- [world](webkit/wkscriptmessage/world.md)

### Getting the Message Handler’s Name

- [name](webkit/wkscriptmessage/name.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [Sendable](swift/sendable.md)

## See Also

### Receiving Messages

- [userContentController(_:didReceive:)](webkit/wkscriptmessagehandler/usercontentcontroller(_:didreceive:).md)
