diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt index 83481a89c6..2b37306660 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/CloudflareInterceptor.kt @@ -9,6 +9,7 @@ import android.webkit.WebSettings import android.webkit.WebView import android.widget.Toast import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.util.lang.launchUI import eu.kanade.tachiyomi.util.system.WebViewClientCompat import eu.kanade.tachiyomi.util.system.WebViewUtil @@ -98,7 +99,7 @@ class CloudflareInterceptor(private val context: Context) : Interceptor { // Avoid sending empty User-Agent, Chromium WebView will reset to default if empty webview.settings.userAgentString = request.header("User-Agent") - ?: WebViewUtil.DEFAULT_USER_AGENT + ?: HttpSource.DEFAULT_USER_AGENT webview.webViewClient = object : WebViewClientCompat() { override fun onPageFinished(view: WebView, url: String) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/UserAgentInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/network/UserAgentInterceptor.kt index 8d9e43a102..e1669472de 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/UserAgentInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/UserAgentInterceptor.kt @@ -1,6 +1,6 @@ package eu.kanade.tachiyomi.network -import eu.kanade.tachiyomi.util.system.WebViewUtil +import eu.kanade.tachiyomi.source.online.HttpSource import okhttp3.Interceptor import okhttp3.Response @@ -12,7 +12,7 @@ class UserAgentInterceptor : Interceptor { val newRequest = originalRequest .newBuilder() .removeHeader("User-Agent") - .addHeader("User-Agent", WebViewUtil.DEFAULT_USER_AGENT) + .addHeader("User-Agent", HttpSource.DEFAULT_USER_AGENT) .build() chain.proceed(newRequest) } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt index 0824fff2cf..81f705c66f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt @@ -10,7 +10,6 @@ import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga -import eu.kanade.tachiyomi.util.system.WebViewUtil import okhttp3.Headers import okhttp3.OkHttpClient import okhttp3.Request @@ -75,7 +74,7 @@ abstract class HttpSource : CatalogueSource { * Headers builder for requests. Implementations can override this method for custom headers. */ protected open fun headersBuilder() = Headers.Builder().apply { - add("User-Agent", WebViewUtil.DEFAULT_USER_AGENT) + add("User-Agent", DEFAULT_USER_AGENT) } /** @@ -370,4 +369,8 @@ abstract class HttpSource : CatalogueSource { * Returns the list of filters for the source. */ override fun getFilterList() = FilterList() + + companion object { + const val DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36 Edg/88.0.705.63" + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt index e19cc69450..584bffa515 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/WebViewUtil.kt @@ -6,13 +6,9 @@ import android.content.pm.PackageManager import android.webkit.CookieManager import android.webkit.WebSettings import android.webkit.WebView -import eu.kanade.tachiyomi.util.lang.launchUI import timber.log.Timber object WebViewUtil { - var DEFAULT_USER_AGENT: String = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" - private set - const val REQUESTED_WITH = "com.android.browser" const val MINIMUM_WEBVIEW_VERSION = 87 @@ -22,14 +18,6 @@ object WebViewUtil { // May throw android.webkit.WebViewFactory$MissingWebViewPackageException if WebView // is not installed CookieManager.getInstance() - - launchUI { - DEFAULT_USER_AGENT = WebView(context) - .getDefaultUserAgentString() - .replace("; wv", "") - .replace(" Build\\/.+?\\)".toRegex(), ")") - .replace("Version/.*? ".toRegex(), "") - } } catch (e: Exception) { Timber.e(e) return false