---
title: "sendMessage(_:completionHandler:)"
framework: webkit
role: symbol
role_heading: Instance Method
path: "webkit/wkwebextension/messageport/sendmessage(_:completionhandler:)"
---

# sendMessage(_:completionHandler:)

Sends a message to the connected web extension.

## Declaration

```swift
func sendMessage(_ message: Any?, completionHandler: (((any Error)?) -> Void)? = nil)
```

```swift
func sendMessage(_ message: Any?) async throws
```

## Parameters

- `message`: The JSON-serializable message to be sent.
- `completionHandler`: An optional block to be invoked after the message is sent, taking an optional error.

## Discussion

Discussion note: The message must be JSON-serializable according to JSONSerialization.
