Skip to content

Commit 63ec14f

Browse files
authored
Merge pull request #237 from adamkobor/request-error-propagation
provide information about the frame in WebViewError
2 parents 811a9c2 + 878bb85 commit 63ec14f

File tree

6 files changed

+14
-6
lines changed

6 files changed

+14
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class WebViewState(webContent: WebContent) {
108108
/**
109109
* A list for errors captured in the last load. Reset when a new page is loaded.
110110
* Errors could be from any resource (iframe, image, etc.), not just for the main page.
111-
* For more fine grained control use the OnError callback of the WebView.
111+
* To filter for only main frame errors, use [WebViewError.isFromMainFrame].
112112
*/
113113
val errorsForCurrentRequest: SnapshotStateList<WebViewError> = mutableStateListOf()
114114

webview/src/androidMain/kotlin/com/multiplatform/webview/web/AccompanistWebView.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,9 @@ open class AccompanistWebViewClient : WebViewClient() {
324324
if (error != null) {
325325
state.errorsForCurrentRequest.add(
326326
WebViewError(
327-
error.errorCode,
328-
error.description.toString(),
327+
code = error.errorCode,
328+
description = error.description.toString(),
329+
isFromMainFrame = request?.isForMainFrame ?: false,
329330
),
330331
)
331332
}

webview/src/commonMain/kotlin/com/multiplatform/webview/web/WebViewError.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ data class WebViewError(
1919
* The error that was reported.
2020
*/
2121
val description: String,
22+
/**
23+
* Is the error related to a request from the main frame?
24+
*/
25+
val isFromMainFrame: Boolean,
2226
)

webview/src/commonMain/kotlin/com/multiplatform/webview/web/WebViewState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class WebViewState(webContent: WebContent) {
5959
/**
6060
* A list for errors captured in the last load. Reset when a new page is loaded.
6161
* Errors could be from any resource (iframe, image, etc.), not just for the main page.
62-
* For more fine grained control use the OnError callback of the WebView.
62+
* To filter for only main frame errors, use [WebViewError.isFromMainFrame].
6363
*/
6464
val errorsForCurrentRequest: SnapshotStateList<WebViewError> = mutableStateListOf()
6565

webview/src/desktopMain/kotlin/com/multiplatform/webview/web/WebEngineExt.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ internal fun CefBrowser.addLoadListener(
153153
WebViewError(
154154
code = errorCode?.code ?: 404,
155155
description = "Failed to load url: ${failedUrl}\n$errorText",
156+
isFromMainFrame = frame?.isMain ?: false,
156157
),
157158
)
158159
}

webview/src/iosMain/kotlin/com/multiplatform/webview/web/WKNavigationDelegate.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ class WKNavigationDelegate(
103103
}
104104
state.errorsForCurrentRequest.add(
105105
WebViewError(
106-
withError.code.toInt(),
107-
withError.localizedDescription,
106+
code = withError.code.toInt(),
107+
description = withError.localizedDescription,
108+
// on iOS all errors are from the main frame
109+
isFromMainFrame = true,
108110
),
109111
)
110112
KLogger.e {

0 commit comments

Comments
 (0)