Enable the MoEngage Web SDK inside a mobile app WebView on Android and iOS, including the JavaScript and storage settings the SDK requires.
This article describes how to use the MoEngage Web SDK in WebView inside a Mobile App.
WebSDK uses browser storage (LocalStorage and IndexedDB) to queue and persist events. This storage is not enabled by default in a WebView, unlike a regular browser tab.
If storage is not explicitly enabled on both Android and iOS, the SDK fails to queue events. This failure is silent — there is no user-facing error — but appears in your app’s error monitoring (for example, Bugsnag or Sentry) as No available storage method found, sometimes followed by MOE_QUEUE_TIMEOUT: exceeded 10000ms.
For Mobile Apps, you must explicitly enable JavaScript and browser storage — both are required, not just JavaScript.
Step 1: Configure Your WebViewWithin your app, locate the WebView component for which you wish to enable JavaScript. Ensure you have the proper imports:
Step 2: Enable JavaScript and DomStorage PermissionsUsing the WebSettings class, enable JavaScript and DOM storage:
WebView myWebView = (WebView) findViewById(R.id.webview);WebSettings webSettings = myWebView.getSettings();webSettings.setJavaScriptEnabled(true);webSettings.setDomStorageEnabled(true); // Required for LocalStorage — without this, the SDK cannot queue events
setDomStorageEnabled(true) covers LocalStorage/SessionStorage. IndexedDB is generally available by default on modern Chromium-based WebView once DOM storage is enabled, but some custom WebView builds or privacy-hardened configurations may restrict it independently. If you continue to see storage errors after enabling DOM storage, verify IndexedDB availability directly inside the WebView session using chrome://inspect.
Step 3: Advanced SettingsFor more control, you may use additional settings such as:
webSettings.setJavaScriptCanOpenWindowsAutomatically(true); // Allow JS to open windows without user interaction
Validate the URL you load in WebView before enabling JavaScript navigation, to avoid executing untrusted scripts.
Step 1: Import WebKitFirst, ensure you’ve imported the WebKit framework in your ViewController:
import WebKit
Step 2: Create a WKWebView with Persistent StorageCreate an instance of WKWebView, and make sure its WKWebViewConfiguration uses a persistent website data store rather than a non-persistent/ephemeral one. A non-persistent data store blocks the storage APIs (LocalStorage/IndexedDB) the SDK depends on to queue events, and discards any SDK data once the WebView is deallocated.
var webView: WKWebView!let configuration = WKWebViewConfiguration()configuration.websiteDataStore = WKWebsiteDataStore.default() // Use .default(), not .nonPersistent()webView = WKWebView(frame: .zero, configuration: configuration)view.addSubview(webView)
Step 3: Enable JavaScriptJavaScript is enabled by default on WKWebView. To verify or change the setting, use WKWebpagePreferences.allowsContentJavaScript on iOS 14 and later, and fall back to WKPreferences.javaScriptEnabled for earlier versions:
Before raising a support ticket for missing or delayed events in a WebView session, confirm the following inside the actual WebView (not a regular browser tab — WebView storage behavior can differ even on the same device):
Android: setDomStorageEnabled(true) is set on the specific WebView instance loading the site.
iOS: the WKWebView is configured with WKWebsiteDataStore.default(), not a non-persistent store.
IndexedDB is accessible inside the WebView session — check via remote inspector (chrome://inspect for Android, Safari Web Inspector for iOS) that window.indexedDB is defined and usable.