# JavaScriptReplyProxy

Artifact: [androidx.webkit:webkit](https://developer.android.com/jetpack/androidx/releases/webkit) [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#1.3.0)

*** ** * ** ***

<br />

```
@UiThread
abstract class JavaScriptReplyProxy
```

<br />

*** ** * ** ***

This class represents the JavaScript object injected by `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)`. An instance will be given by `https://developer.android.com/reference/kotlin/androidx/webkit/WebViewCompat.WebMessageListener#onPostMessage(android.webkit.WebView,androidx.webkit.WebMessageCompat,android.net.Uri,boolean,androidx.webkit.JavaScriptReplyProxy)`. The app can use `https://developer.android.com/reference/kotlin/androidx/webkit/JavaScriptReplyProxy#postMessage(java.lang.String)` to talk to the JavaScript context.

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

| See also |
|---|---|
| `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 |
|---|---|
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature.JS_INJECTION_IN_FRAME_AND_WORLD, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/kotlin/androidx/webkit/JavaScriptReplyProxy#executeJavaScript(java.lang.String,androidx.webkit.WebViewOutcomeReceiver<java.lang.String,androidx.webkit.JavaScriptExecutionException>)( script: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, receiver: https://developer.android.com/reference/kotlin/androidx/webkit/WebViewOutcomeReceiver<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://developer.android.com/reference/kotlin/androidx/webkit/JavaScriptExecutionException!>? )` Executes JavaScript in the frame and world that sent this `https://developer.android.com/reference/kotlin/androidx/webkit/JavaScriptReplyProxy`. |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature.WEB_MESSAGE_ARRAY_BUFFER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/kotlin/androidx/webkit/JavaScriptReplyProxy#postMessage(byte[])(arrayBuffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>)` Post a ArrayBuffer message to the injected JavaScript object which sent this `https://developer.android.com/reference/kotlin/androidx/webkit/JavaScriptReplyProxy`. |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresFeature(name = https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature.WEB_MESSAGE_LISTENER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported") https://developer.android.com/reference/kotlin/androidx/webkit/JavaScriptReplyProxy#postMessage(java.lang.String)(message: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Post a String message to the injected JavaScript object which sent this `https://developer.android.com/reference/kotlin/androidx/webkit/JavaScriptReplyProxy`. |

## Public functions

### executeJavaScript

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

```
@RequiresFeature(name = WebViewFeature.JS_INJECTION_IN_FRAME_AND_WORLD, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract fun executeJavaScript(
    script: String,
    receiver: WebViewOutcomeReceiver<String!, JavaScriptExecutionException!>?
): Unit
```

Executes JavaScript in the frame and world that sent this `https://developer.android.com/reference/kotlin/androidx/webkit/JavaScriptReplyProxy`. The result of the JavaScript execution will be passed to the `https://developer.android.com/reference/kotlin/androidx/webkit/WebViewOutcomeReceiver` callback.

| Parameters |
|---|---|
| `receiver: https://developer.android.com/reference/kotlin/androidx/webkit/WebViewOutcomeReceiver<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://developer.android.com/reference/kotlin/androidx/webkit/JavaScriptExecutionException!>?` | The `https://developer.android.com/reference/kotlin/androidx/webkit/WebViewOutcomeReceiver` to receive the result of the JavaScript execution. |
| `script: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The JavaScript to execute. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature#JS_INJECTION_IN_FRAME_AND_WORLD()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |

### postMessage

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

```
@RequiresFeature(name = WebViewFeature.WEB_MESSAGE_ARRAY_BUFFER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract fun postMessage(arrayBuffer: ByteArray<Byte>): Unit
```

Post a ArrayBuffer message to the injected JavaScript object which sent this `https://developer.android.com/reference/kotlin/androidx/webkit/JavaScriptReplyProxy`. Be aware that large byte buffers can lead to out-of-memory crashes on low-end devices.

| Parameters |
|---|---|
| `arrayBuffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>` | The ArrayBuffer to send to the JavaScript context. An empty ArrayBuffer is supported. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature#WEB_MESSAGE_ARRAY_BUFFER()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |

### postMessage

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

```
@RequiresFeature(name = WebViewFeature.WEB_MESSAGE_LISTENER, enforcement = "androidx.webkit.WebViewFeature#isFeatureSupported")
abstract fun postMessage(message: String): Unit
```

Post a String message to the injected JavaScript object which sent this `https://developer.android.com/reference/kotlin/androidx/webkit/JavaScriptReplyProxy`.

| Parameters |
|---|---|
| `message: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The String data to send to the JavaScript context. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | if the `https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature#WEB_MESSAGE_LISTENER()` feature is not supported. This should be checked before use with `https://developer.android.com/reference/kotlin/androidx/webkit/WebViewFeature#isFeatureSupported(java.lang.String)`. |