Skip to content

[webview_flutter] WebKitWebResourceError no longer contains information about the failing URL #125682

@Aulig

Description

@Aulig

Is there an existing issue for this?

Steps to reproduce

  1. 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)
  2. 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 true

Flutter 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.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: regressionIt was better in the past than it is nowfound in release: 3.10Found to occur in 3.10found in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: webviewThe WebView pluginpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyr: fixedIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform teamtriaged-iosTriaged by iOS platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions