From 43d3a2cc6a7342a50978c1b8a9c8c9a26a1cf8d5 Mon Sep 17 00:00:00 2001 From: Koitharu Date: Wed, 17 Sep 2025 09:14:28 +0300 Subject: [PATCH] Fix crash on WebView.stopLoading() --- .../kotatsu/core/network/webview/WebViewExecutor.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/network/webview/WebViewExecutor.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/network/webview/WebViewExecutor.kt index 1fe47735d..02fe15b1a 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/network/webview/WebViewExecutor.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/network/webview/WebViewExecutor.kt @@ -25,6 +25,7 @@ import java.lang.ref.WeakReference import javax.inject.Inject import javax.inject.Provider import javax.inject.Singleton +import kotlin.coroutines.EmptyCoroutineContext import kotlin.coroutines.resume import kotlin.coroutines.suspendCoroutine @@ -77,7 +78,7 @@ class WebViewExecutor @Inject constructor( continuation = cont, ) cont.invokeOnCancellation { - webView.stopLoading() + webView.stopLoadingAsync() } webView.loadUrl(exception.url) } @@ -115,4 +116,10 @@ class WebViewExecutor @Inject constructor( val repository = mangaRepositoryFactoryProvider.get().create(this) as? ParserMangaRepository return repository?.getRequestHeaders()?.get(CommonHeaders.USER_AGENT) } + + private fun WebView.stopLoadingAsync() { + Dispatchers.Main.dispatch(EmptyCoroutineContext) { + stopLoading() + } + } }