WebViewCompat.WebMessageListener

public interface WebViewCompat.WebMessageListener


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

Summary

Public methods

abstract void
@UiThread
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.

Public methods

onPostMessage

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

Parameters
@NonNull WebView view

The WebView containing the frame which sent this message.

@NonNull WebMessageCompat message

The message from JavaScript.

@NonNull Uri sourceOrigin

The origin of the frame that the message is from.

boolean isMainFrame

true If the message is from the main frame.

@NonNull JavaScriptReplyProxy replyProxy

Used to reply back to the JavaScript object.