My question is pretty simple. how can I get the html data form the loaded page in webview. The data is in JSON format. for a reason I cannot use a post request for any get request here so I need to get the data with webview only. how to achive this ?
flutterWebViewPlugin.onUrlChanged.listen((String url) {
if (url.contains('/recon?')) {
print('printing url : $url');
// need to get data ( html content ) on this url
flutterWebViewPlugin.close();
Navigator.of(context).pop(url);
}
});
});
WebviewScaffold(
userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) Gecko/20100101 Firefox/61.0",
url: myurl,
)
Well the answer for me was to get the token from a url and not from html content
as I am not able to extract it properly and get errors
[VERBOSE-2:ui_dart_state.cc(166)] Unhandled Exception: FormatException: Unexpected character (at character 1)
<html><head></head><body><pre style="word-wrap: break-word; white-space: pr...
^
so what worked for me for the start is the below solution:
WebView(
userAgent: "random",
initialUrl: mainUrl,
onWebViewCreated: (controller) {
_controller = controller;
print(_controller.currentUrl());
},
javascriptMode: JavascriptMode.unrestricted,
gestureNavigationEnabled: true,
onPageFinished: (_) {
_controller.currentUrl().then(
(url) {
if (url.contains("recon?")) {
var token = url.split('recon?')[1];
_prefs.setString('token', token);
}
if (url.contains("dashboard")) {
_controller.clearCache();
_controller.loadUrl(mainUrl);
}
},
);
},
),
here we are taking the url, spliting it based on keyword and then storing the other half which is the token and continuing. I was able to do this in both ways that is with flutter_webview_plugin
as well as flutter_inappwebview
its the same procedure but URL thing only worked for me. extracting context didn't so they are not marked as an answer but an up vote for helping me out understanding the possibility.