You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Turnstile is designed to run in a standard browser environment, which includes mobile devices. On native mobile applications, Turnstile can be used with WebViews. This applies to native web applications for iOS and Android. When implementing Turnstile for mobile, ensure you address the common issues below to avoid integration problems.
9
+
Turnstile is designed to run in standard browser environments, which includes mobile devices accessing your website through mobile browsers.
10
10
11
-
Any modifications to the environment, such as the User Agent, [Content Security Policy settings](/turnstile/reference/content-security-policy/), or domain allowlisting, can disrupt the successful completion of Turnstile challenges. To ensure compatibility, it is recommended to start with a default, unmodified environment and gradually introduce changes, validating Turnstile's functionality after each adjustment.
11
+
For native mobile applications, Turnstile can be integrated using WebViews that render your web content containing Turnstile widgets.
12
12
13
+
---
14
+
15
+
## WebView integration
16
+
17
+
WebViews are components that allow native mobile applications to display web content. They embed a browser engine within your native application, enabling you to show web pages, forms, and JavaScript-powered content like Turnstile widgets.
18
+
19
+
### Requirements
20
+
21
+
For Turnstile to function properly in WebView, the following requirements must be met.
22
+
23
+
#### JavaScript support
24
+
25
+
- JavaScript execution must be enabled.
26
+
- DOM storage API must be available.
27
+
- Standard web APIs must be accessible.
28
+
29
+
#### Network access
13
30
14
-
## WebView configurations
31
+
- Access to `challenges.cloudflare.com`
32
+
- Support for both HTTP and HTTPS connections.
33
+
- Allow connections to `about:blank` and `about:srcdoc`
15
34
16
-
Turnstile requires specific WebView settings to function properly. For Android implementations, refer to [`setJavaScriptEnabled`](https://developer.android.com/reference/android/webkit/WebSettings#setJavaScriptEnabled(boolean)) to tell the WebView to enable JavaScript execution and [`setDomStorageEnabled`](https://developer.android.com/reference/android/webkit/WebSettings#setDomStorageEnabled(boolean)) to enable the DOM storage API.
35
+
#### Environment consistency
17
36
18
-
These settings ensure that the mobile WebView can properly load and execute the Turnstile challenge. If these configurations are missing, Turnstile may malfunction.
37
+
- Consistent User Agent throughout the session
38
+
- Stable device and browser characteristics
39
+
- No modification to core browser behavior
19
40
20
-
##Update allowed origins
41
+
### Platform-specific implementation
21
42
22
-
In addition to ensuring proper WebView settings, if you have allowed origins configured, it is essential to update the list to include:
Only [React Native](https://github.com/react-native-webview/react-native-webview/blob/master/docs/Reference.md#originwhitelist) contains the allowed origins above by default.
When implementing Turnstile with WebViews, the user agent must stay consistent as changing the user agent will cause the challenges to fail.
137
+
## Common implementation issues
40
138
41
-
##Use clearance cookies
139
+
### User Agent consistency
42
140
43
-
When using [clearance cookies](/cloudflare-challenges/concepts/clearance/#pre-clearance-support-in-turnstile) with Turnstile, make sure that it is executed in the same environment where the challenges will occur, including the same browser and device configuration. The `cf_clearance` cookie will be only accepted in the same configured domain for Turnstile widget with the corresponding zone. Domains configured with the Turnstile widget must match the Cloudflare zone that issues [challenges](/cloudflare-challenges/).
141
+
Changing the User Agent during a session causes Turnstile challenges to fail because the system relies on consistent browser characteristics to validate the visitor's authenticity. When the User Agent changes mid-session, Turnstile treats this as a potential security risk and rejects the challenge.
44
142
45
-
If pre-clearance is done in a different environment, the clearance cookie may become invalid and lead to more issued challenges.
Strict [Content Security Policy](/turnstile/reference/content-security-policy/) settings can prevent Turnstile from loading the necessary scripts and making required network connections. This happens when CSP headers or meta tags block access to the domains and resources that Turnstile needs to function properly.
WebView security restrictions can prevent access to the domains that Turnstile requires for proper operation. Some WebViews are configured to only allow specific domains or block certain types of connections, which can interfere with Turnstile's ability to load challenges and communicate with Cloudflare's servers.
46
168
47
-
## Use Flutter with Turnstile
169
+
To resolve this, configure your WebView's allowed origins to include all domains that Turnstile needs:
170
+
171
+
- `challenges.cloudflare.com`
172
+
- `about:blank`
173
+
- `about:srcdoc`
174
+
- Your own domain(s)
175
+
176
+
The exact configuration method varies by platform, but the principle is to explicitly allow network access for these domains.
177
+
178
+
### Cookie and storage issues
179
+
180
+
Cookies and local storage not persisting between sessions can cause Turnstile to fail because it relies on these mechanisms to maintain state and track visitor behavior. This commonly occurs when WebView storage settings are too restrictive or when the app clears storage between sessions. Ensure that your WebView is configured to properly handle cookies and local storage.
For developers using [Flutter](https://pub.dev/packages/flutter_inappwebview), Turnstile is compatible and tested with Flutter's WebView implementation. Refer to the official Flutter WebView package for more details and usage.
0 commit comments