WebViewCompat.WebMessageListener

interface WebViewCompat.WebMessageListener


This listener receives messages sent on the JavaScript object which was injected by addWebMessageListener.

Summary

Public functions

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

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

Public functions

onPostMessage

Added in 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 for serving local content under http: or https: domain.

Parameters
view: WebView

The WebView containing the frame which sent this message.

message: WebMessageCompat

The message from JavaScript.

sourceOrigin: Uri

The origin of the frame that the message is from.

isMainFrame: Boolean

true If the message is from the main frame.

replyProxy: JavaScriptReplyProxy

Used to reply back to the JavaScript object.