Google is committed to advancing racial equity for Black communities. See how.

WebMessageListener

interface WebMessageListener
androidx.webkit.WebViewCompat.WebMessageListener

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

Summary

Public methods

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

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

Public methods

onPostMessage

@UiThread abstract fun onPostMessage(
    @NonNull view: WebView,
    @NonNull message: WebMessageCompat,
    @NonNull sourceOrigin: Uri,
    isMainFrame: Boolean,
    @NonNull 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.