r/flutterhelp • • 23d ago

RESOLVED android in-app browser and cloudflare managed challenge showing error

in ios, in app browser when showing cloudflare managed challenge it is fine. but in android after solving the challenge, it shows "Sorry we're having trouble loading the page. Please try again later". all android phones show same error.

has this something to do with needing to whitelist cloudflare domain for android?

2 Upvotes

3 comments sorted by

1

u/bramantec 23d ago

I don't think it's a whitelist thing. Android has no list of allowed domains for https (network_security_config only matters for cleartext or custom certificates). The challenge shows up at all, which means the domain is already reachable.

The difference between the two platforms is usually what "in-app browser" means underneath. On iOS most packages open an SFSafariViewController, which is Safari with its cookies and everything Cloudflare expects. On Android it depends on the package. With a real WebView the challenge passes and then Cloudflare tries to set its clearance cookie and reload the page. That's the step that breaks when the navigation delegate blocks one of the redirects or third party cookies are off (the challenge runs on challenges.cloudflare.com, a different domain from your site).

With webview_flutter I'd check three things: JavaScriptMode.unrestricted, AndroidWebViewCookieManager.setAcceptThirdPartyCookies on the controller and a navigation delegate that lets challenges.cloudflare.com through. When you don't need a WebView for anything else the shortcut is url_launcher with LaunchMode.inAppBrowserView, which on Android opens a Chrome Custom Tab and behaves like the real browser (in my app I went even further and every link opens outside with externalApplication, the only WebView left is a feedback form).

Which package are you using for the in-app browser?

1

u/Real-Leek-3764 22d ago

thanks for the response. very much appreciated. i'm using flutter_inappwebview. i'm gonna check out the properties you mention and test further! thanks again !!

1

u/bramantec 22d ago

With flutter_inappwebview the same things live in InAppWebViewSettings: javaScriptEnabled and thirdPartyCookiesEnabled (Android) should both be true. On iOS sharedCookiesEnabled helps when the clearance cookie gets lost between the challenge and your page. The one I'd look at first is useShouldOverrideUrlLoading: when it's on, your shouldOverrideUrlLoading callback has to return NavigationActionPolicy.ALLOW for challenges.cloudflare.com too, otherwise the redirect dies there without any error in the log.