compose-webview-multiplatform icon indicating copy to clipboard operation
compose-webview-multiplatform copied to clipboard

Error Handling specifically for main page load

Open Vaibhav2002 opened this issue 2 years ago • 2 comments

How can i add error handling only for the main page load?

This is the current errors exposed, which says to use OnError callback, but how to pass this callback?

/**
 * A list for errors captured in the last load. Reset when a new page is loaded.
 * Errors could be from any resource (iframe, image, etc.), not just for the main page.
 * For more fine grained control use the OnError callback of the WebView.
 */
val errorsForCurrentRequest: SnapshotStateList<WebViewError> = mutableStateListOf()

Vaibhav2002 avatar Mar 30 '24 06:03 Vaibhav2002

val webviewState = rememberWebViewState(url = "https://www.suyambu.net")

LaunchedEffect(webviewState.errorsForCurrentRequest.toList()) {
    for (err in webviewState.errorsForCurrentRequest) {
        println("Err => ${err.code} | ${err.description}")
    }
}

I disconnected my internet and try to load the page I got the following output.

Err => -106 | Failed to load url: https://www.suyambu.net
ERR_INTERNET_DISCONNECTED

errorForCurrentRequest is updating the list from this function

https://github.com/KevinnZou/compose-webview-multiplatform/blob/af895b60ff6afac255807354327ee1b262574026/webview/src/desktopMain/kotlin/com/multiplatform/webview/web/WebEngineExt.kt#L136C1-L136C12

I don't see any listener that I can bind to webviewstate or navigator tol listen for page load error.

whoisjeeva avatar Mar 30 '24 18:03 whoisjeeva

@Vaibhav2002 Thanks for your feedback. I apologize for the confusion. Unfortunately, we do not provide an onError callback for this library, despite the comment being copied over from the Android version. As a result, the only way to access error information is by listening to errorsForCurrentRequest, as @whoisjeeva has done. I'm sorry for any inconvenience this may have caused.

KevinnZou avatar Mar 31 '24 07:03 KevinnZou

Sorry to bring this issue back up, but it seems that there still are some inconsistencies between the README and the actual capabilities of this library. For example here it mentions an onError callback that I can't seem to find anywhere.

Also: are there any plans for exposing errors from the webview to the compose side of things? I need to catch when my webview 401s, so that I can set a cookie. To do that however, I need to know the HTTP Status of the current request. Am I missing features or are there any workarounds for the Moment? ~~The solution mentioned previously does not seem to work for me.~~

Edit: The previously mentioned solution works for me, the issue was on my side

Tommyten avatar Oct 17 '24 06:10 Tommyten