<!--
{
  "availability" : [
    "iOS: 18.4.0 -",
    "iPadOS: 18.4.0 -",
    "macCatalyst: 18.4.0 -",
    "macOS: 15.4.0 -",
    "visionOS: 2.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WebKit",
  "identifier" : "/documentation/WebKit/WKWebExtensionControllerDelegate/webExtensionController(_:sendMessage:toApplicationWithIdentifier:for:replyHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "WebKit"
    ],
    "preciseIdentifier" : "c:objc(pl)WKWebExtensionControllerDelegate(im)webExtensionController:sendMessage:toApplicationWithIdentifier:forExtensionContext:replyHandler:"
  },
  "title" : "webExtensionController(_:sendMessage:toApplicationWithIdentifier:for:replyHandler:)"
}
-->

# webExtensionController(_:sendMessage:toApplicationWithIdentifier:for:replyHandler:)

Called when an extension context wants to send a one-time message to an application.

```
optional func webExtensionController(_ controller: WKWebExtensionController, sendMessage message: Any, toApplicationWithIdentifier applicationIdentifier: String?, for extensionContext: WKWebExtensionContext, replyHandler: @escaping (Any?, (any Error)?) -> Void)
```

## Parameters

`controller`

The web extension controller that is managing the extension.

`message`

The message to be sent.

`applicationIdentifier`

The unique identifier for the application, or \c nil if none was specified.

`extensionContext`

The context in which the web extension is running.

`replyHandler`

A block to be called with a JSON-serializable reply message or an error.

## Discussion

This method should be implemented by the app to handle one-off messages to applications.

If not implemented, the default behavior is to pass the message to the app extension handler within the extension’s bundle, if the extension was loaded from an app extension bundle; otherwise, no action is performed if not implemented.

> Note: The reply message must be JSON-serializable according to <doc://com.apple.documentation/documentation/Foundation/JSONSerialization>.

---

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)