# WebViewCompat.WebMessageListener

# WebViewCompat.WebMessageListener

Artifact:[androidx.webkit:webkit](https://developer.android.com/jetpack/androidx/releases/webkit)  
[View Source](https://cs.android.com/search?q=file:androidx/webkit/WebViewCompat.java+class:androidx.webkit.WebViewCompat.WebMessageListener)  
Added in[1.3.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.3.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/webkit/WebViewCompat.WebMessageListener "View this page in Java")

<br />

```
interface WebViewCompat.WebMessageListener
```

<br />

*** ** * ** ***

This listener receives messages sent on the JavaScript object which was injected by[addWebMessageListener](https://developer.android.com/reference/kotlin/androidx/webkit/WebViewCompat#addWebMessageListener(android.webkit.WebView,java.lang.String,java.util.Set<java.lang.String>,androidx.webkit.WebViewCompat.WebMessageListener)).

## Summary

|                             ### Public functions                              |
|-------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | `@`[UiThread](https://developer.android.com/reference/kotlin/androidx/annotation/UiThread) [onPostMessage](https://developer.android.com/reference/kotlin/androidx/webkit/WebViewCompat.WebMessageListener#onPostMessage(android.webkit.WebView,androidx.webkit.WebMessageCompat,android.net.Uri,boolean,androidx.webkit.JavaScriptReplyProxy))`(` ` view: `[WebView](https://developer.android.com/reference/android/webkit/WebView.html)`,` ` message: `[WebMessageCompat](https://developer.android.com/reference/kotlin/androidx/webkit/WebMessageCompat)`,` ` sourceOrigin: `[Uri](https://developer.android.com/reference/android/net/Uri.html)`,` ` isMainFrame: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`,` ` replyProxy: `[JavaScriptReplyProxy](https://developer.android.com/reference/kotlin/androidx/webkit/JavaScriptReplyProxy) `)` Receives a message sent by a`postMessage()`on the injected JavaScript object. |

## Public functions

### onPostMessage

Added in[1.3.0](https://developer.android.com/jetpack/androidx/releases/webkit#1.3.0)  

```
@UiThread
fun onPostMessage(
    view: WebView,
    message: WebMessageCompat,
    sourceOrigin: Uri,
    isMainFrame: Boolean,
    replyProxy: JavaScriptReplyProxy
): Unit
```

Receives a message sent by a`postMessage()`on the injected JavaScript object.

Note that when the frame is`file:`or`content:`origin, the value of`sourceOrigin`is a string`"null"`. However we highly recommend to not use`file:`or`content:`URLs, see[WebViewAssetLoader](https://developer.android.com/reference/kotlin/androidx/webkit/WebViewAssetLoader)for serving local content under`http:`or`https:`domain.  

|                                                        Parameters                                                         |
|---------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| `view: `[WebView](https://developer.android.com/reference/android/webkit/WebView.html)                                    | The[WebView](https://developer.android.com/reference/android/webkit/WebView.html)containing the frame which sent this message. |
| `message: `[WebMessageCompat](https://developer.android.com/reference/kotlin/androidx/webkit/WebMessageCompat)            | The message from JavaScript.                                                                                                   |
| `sourceOrigin: `[Uri](https://developer.android.com/reference/android/net/Uri.html)                                       | The origin of the frame that the message is from.                                                                              |
| `isMainFrame: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                        | `true`If the message is from the main frame.                                                                                   |
| `replyProxy: `[JavaScriptReplyProxy](https://developer.android.com/reference/kotlin/androidx/webkit/JavaScriptReplyProxy) | Used to reply back to the JavaScript object.                                                                                   |