Repository navigation
[webview_flutter] WebKitWebResourceError no longer contains information about the failing URL #125682
Copy link
Copy link
Closed
flutter/packages
#3884Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: regressionIt was better in the past than it is nowIt was better in the past than it is nowfound in release: 3.10Found to occur in 3.10Found to occur in 3.10found in release: 3.7Found to occur in 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: webviewThe WebView pluginThe WebView pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-iosiOS applications specificallyiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform teamOwned by iOS platform teamtriaged-iosTriaged by iOS platform teamTriaged by iOS platform team
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
- Trigger a WebResourceError in an iOS app (e.g. by disabling your internet connection or, on a simulator where you can't do that, by loading a malformatted URL)
- Look at the content of the WebResouceError
Expected results
Like on Android with WebResourceError.failingUrl there should be some way of accessing the URL that triggered the WebResourceError. This used to be possible in webview_flutter 2.x.x aswell.
Actual results
In webview_flutter 2.x.x the description attribute of the WebResourceError used to contain the domain where the error occurred roughly like this: NSErrorFailingURLKey=example.com
In webview_flutter 4.2.0 it only contains the error description but not the URL.
I thought it was moved to WebKitWebResourceError.domain as that is supposed to contain "A string representing the domain of the error.". However, that always contains the string "NSURLErrorDomain".
Code sample
Code sample
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_android/webview_flutter_android.dart';
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';
void main() => runApp(const MaterialApp(home: WebViewExample()));
class WebViewExample extends StatefulWidget {
const WebViewExample({Key? key}) : super(key: key);
@override
State<WebViewExample> createState() => _WebViewExampleState();
}
class _WebViewExampleState extends State<WebViewExample> {
late final WebViewController _controller;
@override
void initState() {
super.initState();
_controller = WebViewController();
_controller.setJavaScriptMode(JavaScriptMode.unrestricted);
_controller.loadRequest(Uri.parse('https://brokenurl'));
_controller.setNavigationDelegate(NavigationDelegate(
onWebResourceError: (WebResourceError webResourceError) {
if (webResourceError is WebKitWebResourceError) {
print("WebResourceError: Code ${webResourceError.errorCode} Domain: ${webResourceError.domain} Description: ${webResourceError.description} errorType: ${webResourceError.errorType} isForMainFrame ${webResourceError.isForMainFrame}");
}
}
));
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: WebViewWidget(controller: _controller),
);
}
}
Screenshots or Video
No response
Logs
Logs
Launching lib/main.dart on iPhone 13 Pro Max in debug mode...
Running Xcode build...
Xcode build done. 23.1s
Debug service listening on ws://127.0.0.1:55260/By5UiDWofds=/ws
Syncing files to device iPhone 13 Pro Max...
flutter: WebResourceError: Code -1003 Domain: NSURLErrorDomain Description: A server with the specified hostname could not be found. errorType: null isForMainFrame trueFlutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.7.10, on macOS 12.6.3 21G419 darwin-x64, locale en)
• Flutter version 3.7.10 on channel stable at /Users/administrator/Documents/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 4b12645012 (3 weeks ago), 2023-04-03 17:46:48 -0700
• Engine revision ec975089ac
• Dart version 2.19.6
• DevTools version 2.20.1
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/administrator/Library/Android/sdk
• Platform android-33, build-tools 31.0.0
• ANDROID_HOME = /Users/administrator/Library/Android/sdk
• ANDROID_SDK_ROOT = /Users/administrator/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14C18
• CocoaPods version 1.11.2
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 2022.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
[✓] Connected device (2 available)
• iPhone 13 Pro Max (mobile) • E27A0EED-67B6-4A6C-AF53-612A32ECB74D • ios • com.apple.CoreSimulator.SimRuntime.iOS-16-2 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS 12.6.3 21G419 darwin-x64
[✓] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 1 category.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listc: regressionIt was better in the past than it is nowIt was better in the past than it is nowfound in release: 3.10Found to occur in 3.10Found to occur in 3.10found in release: 3.7Found to occur in 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: webviewThe WebView pluginThe WebView pluginpackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.platform-iosiOS applications specificallyiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform teamOwned by iOS platform teamtriaged-iosTriaged by iOS platform teamTriaged by iOS platform team
Activity
darshankawar commentedon Apr 28, 2023
Thanks for the report @Aulig
Can you take a look at the migration guide for the package : https://pub.dev/packages/webview_flutter#migrating-from-30-to-40
Also, below changes related to
WebResourceErrorand see if it helps in your case further or not:Aulig commentedon Apr 28, 2023
Thanks @darshankawar - yes I used the migration guide to migrate to the new onWebResourceError function. The migration docs don't provide any info as to why the failing URL is no longer accessible though.
stuartmorgan-g commentedon Apr 28, 2023
/cc @bparrishMines for comment
darshankawar commentedon May 2, 2023
Thanks for the update. Seeing the same behavior upon running code sample.
stable, master flutter doctor -v
stuartmorgan-g commentedon May 2, 2023
@bparrishMines Per discussion offline, we should see if the error's
userInfohas a field for the failing URL, which we could extract for direct use (instead of it just being in the description string).[webview_flutter] Adds support for receiving a url with WebResourceEr…
github-actions commentedon Jul 28, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.[webview_flutter] Adds support for receiving a url with WebResourceEr…
[webview_flutter] Adds support for receiving a url with WebResourceEr…
[webview_flutter] Adds support for receiving a url with WebResourceEr…