WebViewBridge

interface WebViewBridge

提供脚本与网页端交互的桥接接口,支持注册原生方法供JS调用、调用JS函数及执行JS代码等功能。

该接口封装了WebView与JavaScript之间的通信能力,允许原生代码与网页端进行双向数据交互, 适用于需要通过脚本控制网页行为或接收网页事件的场景。

Author

M8Test, [email protected], https://m8test.com

Functions

Link copied to clipboard
abstract fun callHandler(functionName: String, params: String?, callback: (String?) -> Unit?): Result

调用网页端JavaScript中定义的函数,并可接收其返回结果。

Link copied to clipboard
abstract fun evaluateJs(url: String, repeatable: Boolean, callback: (String?) -> Unit?): Result

加载并执行网络中的JavaScript文件。

Link copied to clipboard
abstract fun evaluateJsFile(file: ScriptFile, repeatable: Boolean, callback: (String?) -> Unit?): Result

执行本地存储的JavaScript文件。

Link copied to clipboard
abstract fun evaluateJsString(content: String, repeatable: Boolean, callback: (String?) -> Unit?): Result

直接执行一段JavaScript字符串代码。

Link copied to clipboard
abstract fun getController(): Controller

获取 WebView 自动化控制器对象

Link copied to clipboard
abstract fun onPageFinished(callback: (webView: WebView, url: String?) -> Unit)

注册网页加载完成时的回调事件。

Link copied to clipboard
abstract fun onPageStarted(callback: (webView: WebView, url: String?, favicon: Bitmap?) -> Unit)

注册网页开始加载时的回调事件。

Link copied to clipboard
abstract fun registerHandler(handlerName: String, handler: (params: String?) -> String?): Result

注册原生处理器,供网页端JavaScript调用。

Link copied to clipboard
abstract fun unregisterHandler(handlerName: String): Result

取消注册指定名称的原生处理器,使其不再响应JS端的调用。