> ## Documentation Index
> Fetch the complete documentation index at: https://moengage-sdk-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# WebView - WebSDK Support

This article describes how to use the MoEngage Web SDK in WebView inside a Mobile App.

<Info>
  * WebSDK uses browser storage, which is not enabled by default for WebView Applications.
  * For Mobile Apps, we must explicitly enable browser storage by providing javascript permission.
</Info>

## Steps to Enable WebSDK in WebView

To run WebSDK in WebView,

* Ensure you have correctly integrated Web SDK into your website.
* Ensure you provide permission to use JavaScript for your Android/iOS app.

## For Android Apps

**Step 1: Configure Your WebView**

Within your app, locate the `WebView` component for which you wish to enable JavaScript. Ensure you have the proper imports:

<CodeGroup>
  ```javascript Java lines wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import android.webkit.WebView;
  import android.webkit.WebSettings;
  ```
</CodeGroup>

**Step 2: Enable JavaScript and DomStorage Permissions**

Using the `WebSettings` class, enable JavaScript:

<CodeGroup>
  ```javascript Java lines wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  WebView myWebView = (WebView) findViewById(R.id.webview);
  WebSettings webSettings = myWebView.getSettings();
  webSettings.setJavaScriptEnabled(true);webSettings.setDomStorageEnabled(true); // Enable DOM storage API
  ```
</CodeGroup>

**Step 3: Advanced Settings**

For more control, you may use additional settings such as:

<CodeGroup>
  ```javascript Java lines wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  webSettings.setJavaScriptCanOpenWindowsAutomatically(true); // Allow JS to open windows without user interaction
  ```
</CodeGroup>

<Info>
  It is important to consider the security implications of enabling JavaScript. Always validate the URL you load in `WebView`.
</Info>

## For iOS Apps

**Step 1: Import WebKit**

First, ensure you've imported the `WebKit` framework in your ViewController:

<CodeGroup>
  ```swift Swift lines wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import WebKit
  ```
</CodeGroup>

**Step 2: Create a WKWebView**

Create an instance of `WKWebView` and add it to your view:

<CodeGroup>
  ```swift Swift lines wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  var webView: WKWebView! 
  webView = WKWebView(frame: .zero, configuration: WKWebViewConfiguration())
  view.addSubview(webView)
  ```
</CodeGroup>

**Step 3: Enable JavaScript**

JavaScript is enabled by default on `WKWebView`, but you can verify or change the settings through the `WKPreferences` object:

<CodeGroup>
  ```swift Swift lines wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  let preferences = WKPreferences()
  preferences.javaScriptEnabled = true
  let configuration = WKWebViewConfiguration()
  configuration.preferences = preferences
  webView = WKWebView(frame: .zero, configuration: configuration)
  ```
</CodeGroup>

## Supported Modules

In WebView, we support the following modules:

* Data Tracking
* On-site Messaging
* Card's
* Web Personalization
