Enable more WebView settings to better mimic regular browser
This commit is contained in:
parent
d8f4e6b45f
commit
a928d9fa0b
3 changed files with 18 additions and 4 deletions
|
@ -14,6 +14,7 @@ import androidx.webkit.WebViewFeature
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||||
import eu.kanade.tachiyomi.util.system.isOutdated
|
import eu.kanade.tachiyomi.util.system.isOutdated
|
||||||
|
import eu.kanade.tachiyomi.util.system.setDefaultSettings
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.util.concurrent.CountDownLatch
|
import java.util.concurrent.CountDownLatch
|
||||||
|
@ -85,7 +86,7 @@ class CloudflareInterceptor(private val context: Context) : Interceptor {
|
||||||
handler.post {
|
handler.post {
|
||||||
val webview = WebView(context)
|
val webview = WebView(context)
|
||||||
webView = webview
|
webView = webview
|
||||||
webview.settings.javaScriptEnabled = true
|
webview.setDefaultSettings()
|
||||||
|
|
||||||
// Avoid sending empty User-Agent, Chromium WebView will reset to default if empty
|
// Avoid sending empty User-Agent, Chromium WebView will reset to default if empty
|
||||||
webview.settings.userAgentString = request.header("User-Agent")
|
webview.settings.userAgentString = request.header("User-Agent")
|
||||||
|
|
|
@ -22,6 +22,7 @@ import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
||||||
import eu.kanade.tachiyomi.ui.main.ForceCloseActivity
|
import eu.kanade.tachiyomi.ui.main.ForceCloseActivity
|
||||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||||
import eu.kanade.tachiyomi.util.system.openInBrowser
|
import eu.kanade.tachiyomi.util.system.openInBrowser
|
||||||
|
import eu.kanade.tachiyomi.util.system.setDefaultSettings
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import eu.kanade.tachiyomi.util.view.invisible
|
import eu.kanade.tachiyomi.util.view.invisible
|
||||||
import eu.kanade.tachiyomi.util.view.visible
|
import eu.kanade.tachiyomi.util.view.visible
|
||||||
|
@ -71,6 +72,8 @@ class WebViewActivity : BaseActivity<WebviewActivityBinding>() {
|
||||||
binding.webview.settings.userAgentString = source.headers["User-Agent"]
|
binding.webview.settings.userAgentString = source.headers["User-Agent"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.webview.setDefaultSettings()
|
||||||
|
|
||||||
supportActionBar?.subtitle = url
|
supportActionBar?.subtitle = url
|
||||||
|
|
||||||
// Debug mode (chrome://inspect/#devices)
|
// Debug mode (chrome://inspect/#devices)
|
||||||
|
@ -78,9 +81,6 @@ class WebViewActivity : BaseActivity<WebviewActivityBinding>() {
|
||||||
WebView.setWebContentsDebuggingEnabled(true)
|
WebView.setWebContentsDebuggingEnabled(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.webview.settings.javaScriptEnabled = true
|
|
||||||
binding.webview.settings.domStorageEnabled = true
|
|
||||||
|
|
||||||
binding.webview.webChromeClient = object : WebChromeClient() {
|
binding.webview.webChromeClient = object : WebChromeClient() {
|
||||||
override fun onProgressChanged(view: WebView?, newProgress: Int) {
|
override fun onProgressChanged(view: WebView?, newProgress: Int) {
|
||||||
binding.progressBar.visible()
|
binding.progressBar.visible()
|
||||||
|
|
|
@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.util.system
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
|
import android.webkit.WebSettings
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
|
|
||||||
object WebViewUtil {
|
object WebViewUtil {
|
||||||
|
@ -29,6 +30,18 @@ fun WebView.isOutdated(): Boolean {
|
||||||
return getWebViewMajorVersion(this) < WebViewUtil.MINIMUM_WEBVIEW_VERSION
|
return getWebViewMajorVersion(this) < WebViewUtil.MINIMUM_WEBVIEW_VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun WebView.setDefaultSettings() {
|
||||||
|
with(settings) {
|
||||||
|
javaScriptEnabled = true
|
||||||
|
domStorageEnabled = true
|
||||||
|
databaseEnabled = true
|
||||||
|
setAppCacheEnabled(true)
|
||||||
|
useWideViewPort = true
|
||||||
|
loadWithOverviewMode = true
|
||||||
|
cacheMode = WebSettings.LOAD_DEFAULT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Based on https://stackoverflow.com/a/29218966
|
// Based on https://stackoverflow.com/a/29218966
|
||||||
private fun getWebViewMajorVersion(webview: WebView): Int {
|
private fun getWebViewMajorVersion(webview: WebView): Int {
|
||||||
val originalUA: String = webview.settings.userAgentString
|
val originalUA: String = webview.settings.userAgentString
|
||||||
|
|
Reference in a new issue