Skip to content

[webview_flutter] navigationDelegate, onPageStarted, onPageFinished not always called #108801

@woutervanwijk

Description

@woutervanwijk

Steps to Reproduce

  1. Execute flutter run on the code sample (with webview_flutter: ^3.0.4)
  2. Press the ./ or github button
  3. Navigate to e.g. Actions on github
  4. Or navigate to a story on Slashdot

Expected results:
Log of calls to navigationDelegate, onPageStarted, onPageFinished

Actual results:
No calls. On github only the onPageFinished

Code sample
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late WebViewController webViewController;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            bottomSheet: Row(children: [
              TextButton(
                child: const Text('/.'),
                onPressed: () =>
                    webViewController.loadUrl('https://m.slashdot.org'),
              ),
              TextButton(
                child: const Text('github'),
                onPressed: () =>
                    webViewController.loadUrl('https://github.com/pimusicbox'),
              ),
            ]),
            body: WebView(
              navigationDelegate: (NavigationRequest navigation) async {
                debugPrint('Nav ${navigation.url}');
                return NavigationDecision.navigate;
              },
              key: const Key('webviewkey'),
              javascriptMode: JavascriptMode.unrestricted,
              onWebViewCreated: (WebViewController controller) {
                webViewController = controller;
              },
              onPageStarted: (url) {
                debugPrint('Page started $url');
              },
              onPageFinished: (url) {
                debugPrint('Page finished $url');
              },
              onWebResourceError: (error) async {
                debugPrint(
                    'Webview load error: ${error.description} ${error.failingUrl}  ${error.domain}');
              },
              backgroundColor:
                  Colors.white, //needed for some websites in dark mode
              initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy
                  .require_user_action_for_all_media_types,
              allowsInlineMediaPlayback: true,
              gestureNavigationEnabled: true,
            )));
  }
}
Logs
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.5 21G72 darwin-arm, locale nl-NL)
    • Flutter version 3.0.5 at /Users/wouter/Library/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f1875d570e (3 weeks ago), 2022-07-13 11:24:16 -0700
    • Engine revision e85ea0e79c
    • Dart version 2.17.6
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/wouter/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • ANDROID_SDK_ROOT = /Users/wouter/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.1)
    • 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 11.0.11+0-b60-7772763)

[✓] VS Code (version 1.69.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.44.0

[✓] Connected device (3 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64  • Android 12 (API 32) (emulator)
    • macOS (desktop)             • macos         • darwin-arm64   • macOS 12.5 21G72 darwin-arm
    • Chrome (web)                • chrome        • web-javascript • Google Chrome 103.0.5060.134

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: webviewThe WebView pluginpackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionworkaround availableThere is a workaround available to overcome the issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions