flutter-plugins
flutter-plugins copied to clipboard
[desktop_webview_window] listen to page finished loading
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
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
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.
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 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;
}
I have same request like you!
I found it have isNavigating https://pub.dev/documentation/desktop_webview_window/latest/desktop_webview_window/Webview/isNavigating.html I workaround by isNavigating.addListener()
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;
}