> Documentation index: https://developer.android.com/reference/llms.txt

# JavaScriptReplyProxy

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

*** ** * ** ***


```
@UiThread
public abstract class JavaScriptReplyProxy
```

<br />

*** ** * ** ***

This class represents the JavaScript object injected by ` WebViewCompat#addWebMessageListener`. An instance will be given by `WebMessageListener#onPostMessage`. The app can use `postMessage` to talk to the JavaScript context.

There is a 1:1 relationship between this object and the JavaScript object in a frame.

| See also |
|---|---|
| `addWebMessageListener` |   |

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `@RequiresFeature(name = WebViewFeature.JS_INJECTION_IN_FRAME_AND_WORLD, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") executeJavaScript( @NonNull String script, @Nullable WebViewOutcomeReceiver<String, JavaScriptExecutionException> receiver )` Executes JavaScript in the frame and world that sent this `JavaScriptReplyProxy`. |
| `abstract void` | `@RequiresFeature(name = WebViewFeature.WEB_MESSAGE_ARRAY_BUFFER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") postMessage(@NonNull byte[] arrayBuffer)` Post a ArrayBuffer message to the injected JavaScript object which sent this `JavaScriptReplyProxy`. |
| `abstract void` | `@RequiresFeature(name = WebViewFeature.WEB_MESSAGE_LISTENER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") postMessage(@NonNull String message)` Post a String message to the injected JavaScript object which sent this `JavaScriptReplyProxy`. |
| `void` | `@RequiresFeature(name = WebViewFeature.WEB_MESSAGE_SHARED_ARRAY_BUFFER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") postMessage(@NonNull SharedArrayBuffer sharedArrayBuffer)` Post a `SharedArrayBuffer` message to the injected JavaScript object which sent this `JavaScriptReplyProxy`. |

## Public methods

### executeJavaScript

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

```
@RequiresFeature(name = WebViewFeature.JS_INJECTION_IN_FRAME_AND_WORLD, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public abstract void executeJavaScript(
    @NonNull String script,
    @Nullable WebViewOutcomeReceiver<String, JavaScriptExecutionException> receiver
)
```

Executes JavaScript in the frame and world that sent this `JavaScriptReplyProxy`. The result of the JavaScript execution will be passed to the `WebViewOutcomeReceiver` callback.

| Parameters |
|---|---|
| `@Nullable WebViewOutcomeReceiver<String, JavaScriptExecutionException> receiver` | The `WebViewOutcomeReceiver` to receive the result of the JavaScript execution. |
| `@NonNull String script` | The JavaScript to execute. |

| Throws |
|---|---|
| `java.lang.UnsupportedOperationException` | if the `JS_INJECTION_IN_FRAME_AND_WORLD` feature is not supported. This should be checked before use with `isFeatureSupported`. |

### postMessage

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

```
@RequiresFeature(name = WebViewFeature.WEB_MESSAGE_ARRAY_BUFFER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public abstract void postMessage(@NonNull byte[] arrayBuffer)
```

Post a ArrayBuffer message to the injected JavaScript object which sent this `JavaScriptReplyProxy`. Be aware that large byte buffers can lead to out-of-memory crashes on low-end devices.

| Parameters |
|---|---|
| `@NonNull byte[] arrayBuffer` | The ArrayBuffer to send to the JavaScript context. An empty ArrayBuffer is supported. |

| Throws |
|---|---|
| `java.lang.UnsupportedOperationException` | if the `WEB_MESSAGE_ARRAY_BUFFER` feature is not supported. This should be checked before use with `isFeatureSupported`. |

### postMessage

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

```
@RequiresFeature(name = WebViewFeature.WEB_MESSAGE_LISTENER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public abstract void postMessage(@NonNull String message)
```

Post a String message to the injected JavaScript object which sent this `JavaScriptReplyProxy`.

| Parameters |
|---|---|
| `@NonNull String message` | The String data to send to the JavaScript context. |

| Throws |
|---|---|
| `java.lang.UnsupportedOperationException` | if the `WEB_MESSAGE_LISTENER` feature is not supported. This should be checked before use with `isFeatureSupported`. |

### postMessage

Added in [1.19.0-alpha03](https://developer.android.com/jetpack/androidx/releases/webkit.md.txt#1.19.0-alpha03)

```
@RequiresFeature(name = WebViewFeature.WEB_MESSAGE_SHARED_ARRAY_BUFFER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
public void postMessage(@NonNull SharedArrayBuffer sharedArrayBuffer)
```

Post a `SharedArrayBuffer` message to the injected JavaScript object which sent this `JavaScriptReplyProxy`.

Unlike `postMessage`, the contents of the buffer are not copied: writes performed by the application are visible to the JavaScript context, and vice versa, without posting another message.

The receiving JavaScript context has to be [cross-origin isolated](https://developer.mozilla.org/en-US/docs/Web/API/Window/crossOriginIsolated) to be able to receive a `SharedArrayBuffer`; see `setCrossOriginIsolatedAllowlist`.

| Parameters |
|---|---|
| `@NonNull SharedArrayBuffer sharedArrayBuffer` | The `SharedArrayBuffer` to send to the JavaScript context. |

| Throws |
|---|---|
| `java.lang.UnsupportedOperationException` | if the `WEB_MESSAGE_SHARED_ARRAY_BUFFER` feature is not supported. This should be checked before use with `isFeatureSupported`. |