Переглянути джерело

Enable more WebView settings to better mimic regular browser

arkon 4 роки тому
батько
коміт
a928d9fa0b

+ 2 - 1
app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt

@@ -14,6 +14,7 @@ import androidx.webkit.WebViewFeature
 import eu.kanade.tachiyomi.R
 import eu.kanade.tachiyomi.source.online.HttpSource
 import eu.kanade.tachiyomi.util.system.isOutdated
+import eu.kanade.tachiyomi.util.system.setDefaultSettings
 import eu.kanade.tachiyomi.util.system.toast
 import java.io.IOException
 import java.util.concurrent.CountDownLatch
@@ -85,7 +86,7 @@ class CloudflareInterceptor(private val context: Context) : Interceptor {
         handler.post {
             val webview = WebView(context)
             webView = webview
-            webview.settings.javaScriptEnabled = true
+            webview.setDefaultSettings()
 
             // Avoid sending empty User-Agent, Chromium WebView will reset to default if empty
             webview.settings.userAgentString = request.header("User-Agent")

+ 3 - 3
app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt

@@ -22,6 +22,7 @@ import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
 import eu.kanade.tachiyomi.ui.main.ForceCloseActivity
 import eu.kanade.tachiyomi.util.system.getResourceColor
 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.view.invisible
 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.setDefaultSettings()
+
             supportActionBar?.subtitle = url
 
             // Debug mode (chrome://inspect/#devices)
@@ -78,9 +81,6 @@ class WebViewActivity : BaseActivity<WebviewActivityBinding>() {
                 WebView.setWebContentsDebuggingEnabled(true)
             }
 
-            binding.webview.settings.javaScriptEnabled = true
-            binding.webview.settings.domStorageEnabled = true
-
             binding.webview.webChromeClient = object : WebChromeClient() {
                 override fun onProgressChanged(view: WebView?, newProgress: Int) {
                     binding.progressBar.visible()

+ 13 - 0
app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt

@@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.util.system
 import android.content.Context
 import android.content.pm.PackageManager
 import android.webkit.CookieManager
+import android.webkit.WebSettings
 import android.webkit.WebView
 
 object WebViewUtil {
@@ -29,6 +30,18 @@ fun WebView.isOutdated(): Boolean {
     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
 private fun getWebViewMajorVersion(webview: WebView): Int {
     val originalUA: String = webview.settings.userAgentString