Skip to content

feat: host the server-delivered mobile core (JS brain) in a hidden WebView with native fallback - #59

Draft
pandeymangg wants to merge 1 commit into
epic/js-brainfrom
anshuman/eng-2912-android-land-the-webview-brain-host-behind-a-config-flag
Draft

feat: host the server-delivered mobile core (JS brain) in a hidden WebView with native fallback#59
pandeymangg wants to merge 1 commit into
epic/js-brainfrom
anshuman/eng-2912-android-land-the-webview-brain-host-behind-a-config-flag

Conversation

@pandeymangg

Copy link
Copy Markdown
Contributor

Ref ENG-2912

What & why

Was: The survey display decision (display types, recontact days, segments, display percentage, language resolution) is compiled into the SDK; changing it requires an SDK release plus a customer app store release.

Now: setup() fetches a small JS bundle from the Formbricks server (/js/mobile/v1/core.umd.cjs), evaluates it in a hidden, never-attached WebView (Play-policy-exempt interpreter path), and track() asks it which survey to show. Any failure — no bundle, wrong protocol version, evaluation error, unreadable decision — falls back to the untouched native logic (nativeTrack), so behaviour without a bundle is identical to today. The brain receives the raw originalResponseMap JSON, so no native re-encoding sits in the bridge contract.

First Android PR of the JS-brain epic (targets epic/js-brain, not main). Server side: formbricks/formbricks#9152 · iOS twin: formbricks/ios#55.

Where to look

  • android/src/main/java/com/formbricks/android/mobilecore/MobileCoreRuntime.kt — off-screen WebView host, main-thread confined, protocol-version gate
  • android/src/main/java/com/formbricks/android/mobilecore/MobileCoreLoader.kt — OkHttp fetch + per-host SharedPreferences cache
  • android/src/main/java/com/formbricks/android/manager/SurveyManager.kt — brain-first track(), native path unchanged as fallback

Testing

  • 8 new instrumented tests in MobileCoreRuntimeInstrumentedTest (init validation, protocol rejection, state pass-through across the bridge, brain-throws fallback, loader URL shape).
  • Full instrumented suite: 132/132 green on a Pixel 9a emulator (API 36).
  • End-to-end verified earlier against a live local server: brain fetched, decision logged from server-delivered JS, survey rendered — including multi-language resolution (setLanguage("hi") → survey in Hindi, response persisted as hi-IN).

Draft — remaining scope for ENG-2912

  • Opt-out flag on FormbricksConfig (disable remote code for enterprise policies).
  • This diff ships no http/cleartext relaxations; local-testing conveniences stay out of the SDK.

Note

AI model usedclaude-fable-5, reasoning effort unknown.

@sonarqubecloud

sonarqubecloud Bot commented Sep 5, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
46.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant