I'm trying to sign in to an app via WebView, and at the end of the process it gives me a response with a token. How can I get the response data from the WebView? Any workarounds for this?

You can launch request url in a webview and inject javascript to get response. Example code using flutter webview plugin:
final webView = FlutterWebviewPlugin();
webView.launch(requestUrl); //hidden: true if necessary
webView.onStateChanged.listen((event) async {
if (event.type == WebViewState.finishLoad) {
final response = await webView
.evalJavascript("document.documentElement.innerText");
print(response);
}
);
Using webview_flutter you can get your response by injecting javascript like that:
late WebViewController _controller;
your webview widget
WebView(
initialUrl: YOUR_URL,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) {
_controller = controller;
},
onPageFinished: (finish) {
//reading response on finish
final response = await _controller.runJavascriptReturningResult("document.documentElement.innerText");
print(jsonDecode(response)); //don't forget to decode into json
},
),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With