diff --git a/server/src/main/kotlin/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt b/server/src/main/kotlin/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt index ddc8cb7dd..8a044b10f 100644 --- a/server/src/main/kotlin/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt +++ b/server/src/main/kotlin/eu/kanade/tachiyomi/network/interceptor/CloudflareInterceptor.kt @@ -128,6 +128,21 @@ object CFClearance { .build() } + fun getWebViewUserAgent(): String { + Playwright.create().use { playwright -> + playwright.chromium().launch( + LaunchOptions() + .setHeadless(true) + ).use { browser -> + browser.newPage().use { page -> + val userAgent = page.evaluate("() => {return navigator.userAgent}") as String + logger.debug { "WebView User-Agent is $userAgent" } + return userAgent + } + } + } + } + private fun getCookies(page: Page, url: String): List { applyStealthInitScripts(page) page.navigate(url) diff --git a/server/src/main/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt b/server/src/main/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt index bf0faf3a3..7ad2ec8b5 100644 --- a/server/src/main/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt +++ b/server/src/main/kotlin/eu/kanade/tachiyomi/source/online/HttpSource.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.source.online import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.asObservableSuccess +import eu.kanade.tachiyomi.network.interceptor.CFClearance.getWebViewUserAgent import eu.kanade.tachiyomi.network.newCallWithProgress import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.model.FilterList @@ -372,6 +373,6 @@ abstract class HttpSource : CatalogueSource { 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" + val DEFAULT_USER_AGENT by lazy { getWebViewUserAgent() } } }