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() + } + } }