<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WKScriptMessageHandlerWithReply/userContentController(_:didReceive:replyHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(pl)WKScriptMessageHandlerWithReply(im)userContentController:didReceiveScriptMessage:replyHandler:"
  },
  "title" : "userContentController(_:didReceive:replyHandler:)"
}
-->

# userContentController(_:didReceive:replyHandler:)

Tells the handler that a webpage sent a script message that included a reply.

```
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage, replyHandler: @escaping @MainActor @Sendable (Any?, String?) -> Void)
```

## Parameters

`userContentController`

The user content controller that delivered the message to your handler.

`message`

An object that contains the message details.

`replyHandler`

A reply handler block to execute with the response to send back to the webpage. This block has no return value and takes the following parameters:

- reply: An object that contains the data to return to the webpage. Allowed types for this parameter are <doc://com.apple.documentation/documentation/Foundation/NSNumber>, <doc://com.apple.documentation/documentation/Foundation/NSString>, <doc://com.apple.documentation/documentation/Foundation/NSDate>, <doc://com.apple.documentation/documentation/Foundation/NSArray>, <doc://com.apple.documentation/documentation/Foundation/NSDictionary>, and <doc://com.apple.documentation/documentation/Foundation/NSNull>. Specify `nil` if an error occurred.
- errorMessage: `nil` on success, or a string that describes the error that occurred.

## Discussion

Use this method to handle a message from the webpage and provide an appropriate response.

---

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)