Skip to navigation

Hybrid app integration

Learn how to integrate hybrid apps with the HUMAN Mobile SDK.

This guide is relevant for the current Mobile SDK. While we highly recommend using the latest version, if you are using a legacy integration, refer to the iOS or Android documentation.

A hybrid app uses both native URL requests and in-app WebViews to communicate with your servers. HUMAN must treat those as one visitor, where the native SDK VID and the WebView VID must be the same. Your app is a hybrid app if both of the following are true:

  1. It loads your website (or a HUMAN-protected page on it) in an in-app WebView, AND
  2. That site is protected by HUMAN Bot Defender or Account Defender

The app doesn’t necessarily need to be called “hybrid” to be considered a hybrid app. These topologies all count:

  • Login, signup, account, billing, or help pages shown in a WebView
  • OAuth or SSO pages on a login subdomain of the same registrable root (for example login.example.com when the root is example.com)
  • A Cordova (or similar) app whose UI is a whole-app WebView of a protected site
  • Cross-platform WebViews such as react-native-webview, Expo WebView, Flutter webview_flutter, or Ionic or Capacitor

A WebView that only loads an unprotected static page (for example, a privacy policy that is not behind HUMAN) does not need hybrid configuration. However, if that same WebView later loads a protected login or account flow, treat it as hybrid.

You can learn how to integrate hybrid apps with the HUMAN Mobile SDK with this guide.

Prerequisites

SFSafariViewController and Chrome Custom Tabs own a cookie jar the app cannot write with the default Hybrid App path, so they need a unique integration. See External browser integration for details.

Integrate with a hybrid app

1

Domain configuration

Set hybridAppPolicy.webRootDomains to the bare registrable root of the site in the WebView with a canonical form example.com. This value is used to decide which WebView host gets hybrid support. It also determines the Domain when the SDK sets _pxmd and _pxwvm. webRootDomains = ["example.com"] is sufficient for the apex and every subdomain of that root.

  • A URL without a leading dot is preferred and should be used whenever possible. However, a leading dot is accepted and equivalent, which means .example.com is stored and matched the same as example.com. Configure example.com even when DevTools shows .example.com.
  • Do not add a leading www, scheme (https://), path, or port.

A host matches when it equals the root or ends with a dot plus the root. notexample.com does not match example.com.

WebView hostwebRootDomains = ["example.com"]
example.comMatch
www.example.comMatch
api.example.comMatch
login.example.comMatch
notexample.comNo match

For more domain configuration scenarios, open the options below.

If the WebView loads a different registrable domain, not a subdomain of the first root, list that root under the Application ID that protects it. OAuth on login.example.com does not need a second entry when example.com is already configured.

val policy = HSPolicy().apply {
hybridAppPolicy.setWebRootDomains(setOf("example.com"), "PX123")
hybridAppPolicy.setWebRootDomains(setOf("other-shop.com"), "PX456")
}
HumanSecurity.start(this, listOf("PX123", "PX456"), policy)

HUMAN can push hybrid root domains for your Application ID from the Portal. The SDK unions those domains with the list in policy. A domain correction does not require an app release. Still set webRootDomains in the app when you can and contact HUMAN if you need a server-side domain update.

A common misconfiguration is listing a subdomain (api.example.com, login.example.com) instead of the registrable root, which fails silently. Instrumentation still matches that host, so the integration looks healthy, but cookies are scoped to the subdomain. Other hosts on the same site never share the VID with native. Configured subdomains are kept as-is and are not reduced to the root. login.example.com is already covered by example.com.

Do not copy the dotted cookie name (.example.com) from DevTools into webRootDomains. Configure the bare root instead (example.com).

Notably, a leading www. is not this type of failure. Instead, www.s are stripped similarly to leading dots.

2

Enable external WebViews support

If WebViews are created outside native code but still use WKWebView or Android WebView (for example react-native-webview), enable supportExternalWebViews.

The HUMAN React Native wrapper and Expo module already set supportExternalWebViews = true. Flutter, Ionic, Capacitor, and Cordova do not. Instead, set the flag in native start together with webRootDomains. See WebView container support for more information.

policy.hybridAppPolicy.supportExternalWebViews = true
3

Disable JavaScript evaluation for Apple Pay on the Web

If your website uses Apple Pay on the Web, disable JavaScript evaluation by the SDK. Apple Pay can’t be used alongside script injection APIs on iOS 13-15.

If your app only targets iOS 16 or above, you don’t need to disable JavaScript evaluation, and you can skip this step.

policy.hybridAppPolicy.allowJavaScriptEvaluation = false
4

Enable Hybrid App support

  1. In your native integration, pass the WebView instance to the SDK:
    • Android: HumanSecurity.setupWebView(webView:webViewClient:)
    • iOS: HumanSecurity.setupWebView(webView:navigationDelegate:)

Do not set the webViewClient (Android) or navigationDelegate (iOS) after setupWebView.

  1. On iOS, set HSHybridAppPolicy.automaticSetup to true to detect and set up WKWebView instances without calling setupWebView for each one.

Below are example implementations in Android and iOS.

If you have multiple Application IDs, use HumanSecurity.start(appIds:policy:) and pass the Application ID that owns each root.

import android.app.Application
import com.humansecurity.mobile_sdk.HumanSecurity
import com.humansecurity.mobile_sdk.main.policy.HSPolicy
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
startHumanSDK()
}
private fun startHumanSDK() {
try {
val policy = HSPolicy().apply {
// Configure the policy...
automaticInterceptorPolicy.interceptorType = HSAutomaticInterceptorType.INTERCEPT_WITH_DELAYED_RESPONSE // or INTERCEPT_AND_RETRY_REQUEST
hybridAppPolicy.setWebRootDomains(setOf("example.com"), "<APP_ID>")
}
HumanSecurity.start(this, "<APP_ID>", policy)
} catch (exception: Exception) {
println("Exception: ${exception.message}")
}
}
}

In particular, note the following:

  1. Web root domains: Set the registrable root (example.com) in webRootDomains. Prefer the bare form, as a leading www. is stripped to that root. Do not use https://.
  2. Start the SDK as early as possible on the main thread so URL requests include HUMAN headers.
  3. Set up WebViews:
    • Android: HumanSecurity.setupWebView(webView:webViewClient:). Do not set the WebViewClient directly after this.
    • iOS: HumanSecurity.setupWebView(webView:navigationDelegate:). Do not set the navigationDelegate directly after this.
5

Confirm the integration is working

Confirm the following:

The native VID and the WebView VID must be identical.

SideVID and where to read
NativeRead X-PX-VID on a request your app sends to a protected host (from SDK headers)
WebViewRead _pxvid cookie (and the matching Sensor session) on the loaded page

If your sync is successful, you should see the following cookies in an instrumented WebView:

NameWriterRole
_pxmdMobile SDKPayload for the Sensor (cookies channel only). Events and session-storage modes may show only _pxwvm plus Sensor cookies, so missing _pxmd in those modes is not a failed sync.
_pxwvmMobile SDKMarks the page as an in-app WebView
_pxvidSensorVisitor ID adopted from the SDK

If those VIDs differ after the first navigation, refer to Troubleshooting.

6

Verification

Run the Doctor App Web view test before production. Treat a passing hybrid/WebView test as a release gate.

  1. Enable the Doctor App (HSDoctorAppPolicy.enabled = true). See our verification guide for more information.
  2. Choose the Web view framework test and exercise the WebView that loads your protected site.
  3. On the summary screen, confirm the test passed.
  4. Export the result JSON and keep it. That export is the standard attachment for HUMAN Support.
  5. Ensure you disable the Doctor App (enabled = false) before you ship.

Preserve cookies & storage on logouts

If your app clears cookies or WebView storage on logout, use Mobile SDK 5.3.0 or later. That release restores missing _pxmd/_pxwvm after a wipe (cookies channel; other channels restore _pxwvm as appropriate). Older SDKs stay broken until the next full handshake.

Prevention still matters, especially on Android native and wrapper-hosted WebViews where hybrid often depends on cookies. If you write deletion logic, skip HUMAN keys. Do not delete every cookie in the WebView store.

See Use of cookies and web storage for full descriptions.

  • _pxmd
  • _pxwvm
  • _pxvid
  • _pxmvid
  • _pxhd
  • _pxda
  • _px_mobile_data
  • _px / _px2 / _px3
  • _pxde
  • _pxff_*
  • _pxttld
  • pxcts
  • __pxvid

Maintain VIDs for external browsers

When embedding web content using SFSafariViewController on iOS or Chrome Custom Tabs on Android, those components run in a separate process and use an isolated cookie jar that the SDK cannot access directly. To maintain Visitor ID (VID) alignment between your native app and the web sessions inside these external browsers, you must explicitly pass the SDK’s VID in the URL query parameters.

Important timing considerations

The SDK retrieves its Visitor ID asynchronously from the HUMAN Collector during the startup flow (HumanSecurity.start()). This means the VID getter may return nil (or null) if you attempt to launch the external browser immediately on application launch before the SDK has completed its initial handshake.

If your application flow requires opening the browser immediately upon app launch and the VID is not ready in time, contact HUMAN Support for a custom solution.

  1. Initialize and run the HUMAN Mobile SDK.
  2. Contact HUMAN Support or your Technical Account Manager (TAM) to enable the “Extract VID from URL” configuration for your Application ID on the backend. Without this server-side configuration, the embedded web sensor ignores the URL parameter.
  3. Pass the VID following the examples below.

To pass the VID on Android, append it as the _pxvid query parameter to your Uri before launching the Custom Tab.

import android.content.Context
import android.net.Uri
import androidx.browser.customtabs.CustomTabsIntent
import com.humansecurity.mobile_sdk.HumanSecurity
fun openProtectedWebsite(context: Context, appId: String) {
val uriBuilder = Uri.parse("https://your-protected-website.com").buildUpon()
// 1. Retrieve the VID from the SDK.
// Note: This may be null if the SDK hasn't finished its initial sync.
val vid = HumanSecurity.vid(appId)
// 2. Append the _pxvid query parameter if available
if (!vid.isNullOrEmpty()) {
uriBuilder.appendQueryParameter("_pxvid", vid)
} else {
println("HUMAN VID is not yet available.")
}
// 3. Launch the Custom Tab
val uri = uriBuilder.build()
CustomTabsIntent.Builder()
.build()
.launchUrl(context, uri)
}

Leave _pxhd to the SDK

_pxhd is an HTTP cookie that carries an encrypted VID and socket IP. On Enforcer traffic, it is consulted before _pxvid. Inside an instrumented WebView, the SDK and Sensor manage _pxhd, so the SDK’s VID wins. You may see _pxhd disappear in that WebView. That is expected.

If native and WebView VIDs diverge on a domain that is also a desktop property, _pxhd is the first thing support checks. This can’t be fixed by changing webRootDomains alone, so in this case, contact HUMAN Support.

Troubleshooting

First check: webRootDomains is the bare root (example.com), not a subdomain. Confirm matching with the table above.

Then check the following:

  1. The WebView is a supported container
  2. setupWebView / automaticSetup / supportExternalWebViews matches how the WebView is created
  3. Contact HUMAN if _pxhd is on a domain shared with desktop.

Check the VID split (native vs. _pxvid). A challenge loop usually means two identities. Confirm the container is supported. SFSafariViewController and Chrome Custom Tabs require an external browser integration.

Check that the app is deleting cookies or storage (logout, “clear site data”, WebView data APIs). Skip HUMAN keys and use SDK 5.3.0 or later so recovery can restore _pxmd/_pxwvm. Also confirm that you didn’t list a subdomain as the only webRootDomains entry.

This is expected. The first navigation after a cold start can run before the SDK has a VID to publish. Later navigations should match. This is an accepted first-launch limitation, not a domain-config bug.