1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package com.droidyue.webview.webviewclient
import android.net.http.SslError
import android.webkit.*
import com.droidyue.common.debugMessage
import com.droidyue.webview.ext.toSimpleString
/**
* 诊断(错误信息)的WebViewClient,会以日志输出形式输出错误信息,便于发现网页的问题
*/
open class DiagnosableWebViewClient : WebViewClient() {
override fun onReceivedError(view: WebView?, errorCode: Int, description: String?, failingUrl: String?) {
super.onReceivedError(view, errorCode, description, failingUrl)
debugMessage("onReceivedError", "errorCode", errorCode, "description", description,
"failingUrl", failingUrl, "webview.info", view?.toSimpleString())
}
override fun onReceivedError(view: WebView?, request: WebResourceRequest?, error: WebResourceError?) {
super.onReceivedError(view, request, error)
debugMessage("onReceivedError", "request", request?.toSimpleString(), "error", error?.toSimpleString(),
"webview.info", view?.toSimpleString())
}
override fun onSafeBrowsingHit(view: WebView?, request: WebResourceRequest?, threatType: Int, callback: SafeBrowsingResponse?) {
super.onSafeBrowsingHit(view, request, threatType, callback)
debugMessage("onSafeBrowsingHit", "request", request?.toSimpleString(), "threatType", threatType,
"webview.info", view?.toSimpleString())
}
override fun onReceivedHttpError(view: WebView?, request: WebResourceRequest?, errorResponse: WebResourceResponse?) {
super.onReceivedHttpError(view, request, errorResponse)
debugMessage("onReceivedHttpError", "request", request, "errorResponse", errorResponse?.toSimpleString(),
"webview.info", view?.toSimpleString())
}
override fun onReceivedSslError(view: WebView?, handler: SslErrorHandler?, error: SslError?) {
super.onReceivedSslError(view, handler, error)
debugMessage("onReceivedSslError", "error", error, "webview.info", view?.toSimpleString())
}
}
|