> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Enable Offline Support

> Turn on local caching and the durable send outbox, and verify offline support is active with the CometChat JavaScript SDK.

> [accordion] AI Integration Quick Reference
>
> ```javascript theme={null}
> // 1. Attach an offline config to AppSettings (off by default — enabled must be true).
> const appSetting = new CometChat.AppSettingsBuilder()
>   .setRegion("REGION")
>   .setOfflineConfig({ enabled: true })   // explicit config; its `enabled` wins
>   // .offline(true)                      // shorthand: enable with all defaults
>   .build();
>
> // 2. Pass the settings to init.
> await CometChat.init("APP_ID", appSetting);
>
> // 3. Verify it is active for the logged-in user.
> const active = CometChat.isOfflineEnabled();   // boolean
> ```

Offline support is **off by default**. You turn it on once, at initialization, by passing an offline config to the `AppSettingsBuilder`. Until you do, the SDK behaves exactly as before. This page covers the minimal setup; for every tunable option see the [Configuration & API Reference](https://www.cometchat.com/docs/sdk/javascript/offline-reference.md).

**1. Requirements**

Offline support requires CometChat JavaScript SDK **4.3.0** or later.

```bash theme={null}
npm install @cometchat/chat-sdk-javascript@4.3.0
```

If you are new to the SDK, complete the [standard setup](https://www.cometchat.com/docs/sdk/javascript/setup-sdk.md) first; the steps below only add offline configuration to your existing `init`.

**2. Attach an offline config to AppSettings**

Call `setOfflineConfig(...)` on the `AppSettingsBuilder` with an object whose `enabled` is `true`. Every other key has a sensible default, so set only what you need. To enable with all defaults, use the `offline(true)` shorthand instead.

> [tab] TypeScript
>
> ```typescript theme={null}
> const appSetting: CometChat.AppSettings = new CometChat.AppSettingsBuilder()
>   .subscribePresenceForAllUsers()
>   .setRegion("REGION")
>   .autoEstablishSocketConnection(true)
>   .setOfflineConfig({ enabled: true })   // explicit config
>   // .offline(true)                      // shorthand: enable with defaults
>   .build();
> ```

> [tab] JavaScript
>
> ```javascript theme={null}
> const appSetting = new CometChat.AppSettingsBuilder()
>   .subscribePresenceForAllUsers()
>   .setRegion("REGION")
>   .autoEstablishSocketConnection(true)
>   .setOfflineConfig({ enabled: true })   // explicit config
>   // .offline(true)                      // shorthand: enable with defaults
>   .build();
> ```

> [!NOTE]
>
> Offline turns on only for an explicit `enabled: true`. A config object without `enabled` leaves it off. If you call both `setOfflineConfig(...)` and `offline(...)`, the explicit config wins.

**3. Initialize the SDK**

Pass the settings to `CometChat.init(...)` as you do today. No other call changes.

> [tab] TypeScript
>
> ```typescript theme={null}
> CometChat.init("APP_ID", appSetting).then(
>   (initialized: boolean) => {
>     console.log("Initialization completed successfully", initialized);
>   },
>   (error: CometChat.CometChatException) => {
>     console.log("Initialization failed with error:", error);
>   }
> );
> ```

> [tab] JavaScript
>
> ```javascript theme={null}
> CometChat.init("APP_ID", appSetting).then(
>   () => {
>     console.log("Initialization completed successfully");
>   },
>   (error) => {
>     console.log("Initialization failed with error:", error);
>   }
> );
> ```

**4. Verify it is active**

Call `CometChat.isOfflineEnabled()`. It returns `true` only while offline support is actually running for the logged-in user — so it is `false` before anyone logs in (even when you enabled it in `AppSettings`), after logout or session expiry, while the local store is still opening, and when the encrypted cache cannot open. Read it at the moment of each decision and keep no copy of the result.

> [tab] TypeScript
>
> ```typescript theme={null}
> const active: boolean = CometChat.isOfflineEnabled();
> console.log("Offline support active:", active);
> ```

> [tab] JavaScript
>
> ```javascript theme={null}
> const active = CometChat.isOfflineEnabled();
> console.log("Offline support active:", active);
> ```

## Supported runtimes

| Runtime | Data store | Media bytes |
| - | - | - |
| Browser | IndexedDB | OPFS. Where OPFS is missing, media is not cached. |
| Electron | SQLite in the main process | Files on disk |

Where IndexedDB is missing or blocked (for example some private-browsing modes), offline stays off for the session and the SDK works online as before.

> [!NOTE]
>
> **Electron setup.** Install the optional peer dependencies `electron` and `better-sqlite3-multiple-ciphers`, call `registerOfflineIpc()` from `@cometchat/chat-sdk-javascript/electron/main` in the main process, and `installCometChatBridge()` from `@cometchat/chat-sdk-javascript/electron/preload` in your preload script (with `contextIsolation: true`). Browser apps need nothing extra.

## Next steps

Offline support is now active for the logged-in user. Continue with [Show Cached Data](https://www.cometchat.com/docs/sdk/javascript/offline-cached-data.md) to adopt the fetch listeners, and [Send While Offline](https://www.cometchat.com/docs/sdk/javascript/offline-send.md) for the durable outbox. Tune caps, TTLs, media, and encryption from the [Configuration & API Reference](https://www.cometchat.com/docs/sdk/javascript/offline-reference.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.