WebViewResolver: added timeout (#941)

This commit is contained in:
Sofie 2024-02-20 03:18:36 +07:00 committed by GitHub
parent e007714701
commit 93d81ea038
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 3 deletions

View File

@ -31,6 +31,7 @@ import java.net.URI
* @param useOkhttp will try to use the okhttp client as much as possible, but this might cause some requests to fail. Disable for cloudflare. * @param useOkhttp will try to use the okhttp client as much as possible, but this might cause some requests to fail. Disable for cloudflare.
* @param script pass custom js to execute * @param script pass custom js to execute
* @param scriptCallback will be called with the result from custom js * @param scriptCallback will be called with the result from custom js
* @param timeout close webview after timeout
* */ * */
class WebViewResolver( class WebViewResolver(
val interceptUrl: Regex, val interceptUrl: Regex,
@ -38,18 +39,29 @@ class WebViewResolver(
val userAgent: String? = USER_AGENT, val userAgent: String? = USER_AGENT,
val useOkhttp: Boolean = true, val useOkhttp: Boolean = true,
val script: String? = null, val script: String? = null,
val scriptCallback: ((String) -> Unit)? = null val scriptCallback: ((String) -> Unit)? = null,
val timeout: Long = DEFAULT_TIMEOUT
) : ) :
Interceptor { Interceptor {
constructor(
interceptUrl: Regex,
additionalUrls: List<Regex> = emptyList(),
userAgent: String? = USER_AGENT,
useOkhttp: Boolean = true,
script: String? = null,
scriptCallback: ((String) -> Unit)? = null,
) : this(interceptUrl, additionalUrls, userAgent, useOkhttp, script, scriptCallback, DEFAULT_TIMEOUT)
constructor( constructor(
interceptUrl: Regex, interceptUrl: Regex,
additionalUrls: List<Regex> = emptyList(), additionalUrls: List<Regex> = emptyList(),
userAgent: String? = USER_AGENT, userAgent: String? = USER_AGENT,
useOkhttp: Boolean = true useOkhttp: Boolean = true
) : this(interceptUrl, additionalUrls, userAgent, useOkhttp, null, null) ) : this(interceptUrl, additionalUrls, userAgent, useOkhttp, null, null, DEFAULT_TIMEOUT)
companion object { companion object {
private const val DEFAULT_TIMEOUT = 60_000L
var webViewUserAgent: String? = null var webViewUserAgent: String? = null
@JvmName("getWebViewUserAgent1") @JvmName("getWebViewUserAgent1")
@ -262,7 +274,7 @@ class WebViewResolver(
var loop = 0 var loop = 0
// Timeouts after this amount, 60s // Timeouts after this amount, 60s
val totalTime = 60000L val totalTime = timeout
val delayTime = 100L val delayTime = 100L