flutter-plugins icon indicating copy to clipboard operation
flutter-plugins copied to clipboard

[desktop_webview_window] listen to page finished loading

Open a-eniou-pvotal opened this issue 3 years ago • 6 comments

I want to listen to the page loaded in the Webiew to parse its content I get content by

final content = await webview.evaluateJavaScript(
                                 "document.documentElement.outerHTML.toString()");

but it prints flutter: <html><head></head><body></body></html> I know you have used Future.delay in your example but It is better to listen to the page loaded

a-eniou-pvotal avatar Dec 12 '21 15:12 a-eniou-pvotal

And same for URL redirection, I want to listen to the page loaded

 ..addOnUrlRequestCallback((url) async {
                  await Future.delayed(Duration(seconds: 2));
                  final content = await webview.evaluateJavaScript(
                                      "document.documentElement.outerHTML.toString()");
                  print('$content');
                                })

I use this library for scraping HTML content

Thanks for your effort. I tried to open the macOS folder in Xcode, but there is no project or workspace there to open, only classes https://github.com/MixinNetwork/flutter-plugins/tree/main/packages/desktop_webview_window/macos

a-eniou-pvotal avatar Dec 12 '21 16:12 a-eniou-pvotal

I tried to open the macOS folder in Xcode, but there is no project or workspace there to open, only classes.

You can go to example folder. and open macos/Runner.xcworkspace. then you can find the macos classes in development pods folder.

image

I want to listen to the page loaded.

Ummm. That's Sounds feasible, but maybe still need took some time to check how to combine WebView2,GtkWebKit,WKWebView all into one library.

boyan01 avatar Dec 12 '21 16:12 boyan01

@boyan01 a temporary workaround, while content.lenght<100 Future.dalay(1 second

  Future<String?>? getContent() async {
    await Future.delayed(Duration(seconds: 1));

    final content = await webview
        ?.evaluateJavaScript('document.documentElement.outerHTML.toString()');
    if (content!.length < 100) {
      return getContent();
    }
    return content;
  }

a-eniou-pvotal avatar Dec 13 '21 09:12 a-eniou-pvotal

I have same request like you!

dodatw avatar Feb 08 '22 05:02 dodatw

I found it have isNavigating https://pub.dev/documentation/desktop_webview_window/latest/desktop_webview_window/Webview/isNavigating.html I workaround by isNavigating.addListener()

dodatw avatar Feb 08 '22 07:02 dodatw

My implementation on @dodatw workaround, just in case someone needs it:

  Future<bool> waitForCompletion() async {
    var completer = Completer<bool>();
    listener() {
      if (webview!.isNavigating.value == false) {
        webview!.isNavigating.removeListener(listener);
        completer.complete(false);
      }
    }

    webview!.isNavigating.addListener(listener);
    return completer.future;
  }

poqueque avatar Feb 22 '23 23:02 poqueque