---
title: "messageReceived(withName:from:userInfo:)"
framework: safariservices
role: symbol
role_heading: Instance Method
path: "safariservices/sfsafariextensionhandling/messagereceived(withname:from:userinfo:)"
---

# messageReceived(withName:from:userInfo:)

A method the system calls when the extension receives a message from an injected script.

## Declaration

```swift
optional func messageReceived(withName messageName: String, from page: SFSafariPage, userInfo: [String : Any]? = nil)
```

## Parameters

- `messageName`: A string that identifies the message.
- `page`: The page that sent the message.
- `userInfo`: Optional message content. If specified, the dictionary’s value objects conform to the W3C standard for safe passing of structured data, such as Boolean objects, numeric values, strings, and arrays.

## Mentioned in

Passing messages between Safari app extensions and injected scripts

## See Also

### Receiving Messages in Your App Extension

- [messageReceivedFromContainingApp(withName:userInfo:)](safariservices/sfsafariextensionhandling/messagereceivedfromcontainingapp(withname:userinfo:).md)
