Hybrid App integration
What is a Hybrid App
A Hybrid App uses both native URL requests and web views to communicate with your server. In the context of HUMAN, it’s crucial to ensure that both native requests and web views are synchronized to provide the expected behavior for end users.
How Do I Know if My App is a Hybrid App
Your app is considered a Hybrid App if it has ALL of the following:
- A web view component (
WKWebViewon iOS orWebViewon Android) that loads your website. - Your website is protected by HUMAN (Bot Defender or Account Defender).
On iOS, if your app uses SFSafariViewController, please let us know, and we will guide you through a specific integration.
How to Enable Hybrid App Support in My App
Integrate the SDK (Native)
You should integrate the SDK into your native app. You may choose one of the following methods:
Enable Hybrid App Support
When starting the SDK, declare your website’s root domain in the policy. This value is used both to decide which WebViews get hybrid support and as the Domain when the SDK sets hybrid cookies (_pxmd, _pxwvm).
Set the same cookie domain your Sensor uses on the website. In browser DevTools, Sensor cookies usually appear with a domain like .example.com for https://www.example.com. Use that root domain in webRootDomains — no scheme and no www prefix.
The SDK enables Hybrid App support ONLY for the specified domains. It matches the WebView host against that root and its subdomains. For example, .example.com covers example.com, www.example.com, and api.example.com.
You should pass the WebView instance to the SDK using the following functions:
- iOS:
HumanSecurity.setupWebView(webView:navigationDelegate:) - Android:
HumanSecurity.setupWebView(webView:webViewClient:)
Important: Do not set the navigationDelegate (iOS) or webViewClient (Android) properties after calling the setupWebView function.
On iOS, you can enable automatic detection and setup of WKWebViews by setting HSHybridAppPolicy.automaticSetup to true. This eliminates the need to manually call setupWebView for each instance.
Example Implementation
Android
Kotlin:
Java:
Kotlin (Activity):
Java (Activity):
iOS
Swift:
Objective-C:
Explanation of the Code
- Adding Web Root Domains:
- Set your website’s root cookie domain (e.g.,
.example.com) in the policy’swebRootDomains. Confirm the value matches the Sensor cookieDomainin DevTools. Do not usewww.example.comorhttps://….
- Set your website’s root cookie domain (e.g.,
- Starting the SDK:
- Initialize the SDK as early as possible on the main thread to ensure all URL requests include the necessary HTTP headers.
- Setting Up Web Views:
- Android: Use
HumanSecurity.setupWebView(webView:webViewClient:)to set up theWebViewwith the SDK’sWebViewClient. Do not set theWebViewClientdirectly after this. - iOS: Use
HumanSecurity.setupWebView(webView:navigationDelegate:)to set up theWKWebViewwith the SDK’snavigationDelegate. Do not set thenavigationDelegatedirectly after this.
- Android: Use
Notes:
- iOS Automatic Setup: If you enable
HSHybridAppPolicy.automaticSetup, the SDK will automatically detect and set up allWKWebViewinstances without needing to callsetupWebViewfor each one. - Multiple AppIDs: If your app communicates with multiple servers having different AppIDs, use the
HumanSecurity.start(appIds:policy:)function to pass an array of AppIDs and specify the relevant AppID for each API call.
Apple Pay on the Web
If your website uses Apple Pay on the Web, you should disable JavaScript evaluation by the SDK. To protect the security of Apple Pay transactions in WKWebView, Apple Pay cannot be used alongside script injection APIs (relevant for iOS 13-15). Disable JavaScript evaluation by setting the SDK’s policy accordingly.
Note: If your app targets only iOS 16 or above, you don’t need to disable JavaScript evaluation by the SDK.
Swift:
Objective-C:
External Web Views (Available from v4.0.1)
If your app uses web views that are created outside the native side of the app but are still based on Apple’s WKWebView or Android’s WebView (e.g., react-native-webview), you should enable support for them in the SDK’s policy.
Android
Kotlin:
Java:
iOS
Swift:
Objective-C: