# 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)

*** ** * ** ***


```
public interface WebViewCompat.WebMessageListener
```

<br />

*** ** * ** ***

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

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `@https://developer.android.com/reference/androidx/annotation/UiThread https://developer.android.com/reference/androidx/webkit/WebViewCompat.WebMessageListener#onPostMessage(android.webkit.WebView,androidx.webkit.WebMessageCompat,android.net.Uri,boolean,androidx.webkit.JavaScriptReplyProxy)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/webkit/WebView.html view, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/WebMessageCompat message, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html sourceOrigin, boolean isMainFrame, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/JavaScriptReplyProxy replyProxy )` Receives a message sent by a `postMessage()` on the injected JavaScript object. |

## Public methods

### onPostMessage

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

```
@UiThread
abstract void onPostMessage(
    @NonNull WebView view,
    @NonNull WebMessageCompat message,
    @NonNull Uri sourceOrigin,
    boolean isMainFrame,
    @NonNull JavaScriptReplyProxy replyProxy
)
```

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 `https://developer.android.com/reference/androidx/webkit/WebViewAssetLoader` for serving local content under `http:` or `https:` domain.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/webkit/WebView.html view` | The `https://developer.android.com/reference/android/webkit/WebView.html` containing the frame which sent this message. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/WebMessageCompat message` | The message from JavaScript. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/net/Uri.html sourceOrigin` | The origin of the frame that the message is from. |
| `boolean isMainFrame` | `true` If the message is from the main frame. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/webkit/JavaScriptReplyProxy replyProxy` | Used to reply back to the JavaScript object. |