# Polyfills and runtime setup

Canonical page: https://docs.ovok.com/native-sdk/guide/components/polyfills

Runtime setup has a dedicated `@ovok/native/polyfills` subpath so it can run before
the app imports the rest of the SDK. `polyfillOvokWebAPIs` is the preferred
initializer for new code.

```js
// index.js: initialize before Expo Router loads the app bundle.
const { polyfillOvokWebAPIs } = require("@ovok/native/polyfills");

polyfillOvokWebAPIs();
require("expo-router/entry");
```

Set the app's `package.json` `main` field to `index.js` so this file runs before
Expo Router imports the app. Keep this entry file in CommonJS form; a static import
of the app or `expo-router/entry` can evaluate SDK modules before the initializer.

## Public exports [#public-exports]

| Export | Purpose |
| --- | --- |
| `polyfillOvokWebAPIs` | Installs the web APIs required by the OVOK native runtime |
| `cleanupOvokNativeRuntime` | Removes the installed polyfills for tests or controlled teardown |
| `ExpoClientStorage` | Client storage implementation backed by Expo storage primitives |
| `ExtendedExpoCrypto` | Expo-compatible crypto implementation |
| `IExpoClientStorage` | Storage adapter type |
| `PolyfillEnabledConfig` | Optional polyfill configuration type |
| `initWebSocketManager` | Initializes the WebSocket manager used by the client runtime |

Call `polyfillOvokWebAPIs` once from the application entry point, before importing
the app module, creating, or using the `Ovok` client. Do not call it during render or
once per screen. Use `cleanupOvokNativeRuntime` only when a test or controlled
runtime teardown needs to remove the globals.

## Storage and credentials [#storage-and-credentials]

The `Ovok` client from `@ovok/native/next` keeps its session in the `secureStore` you
pass it, such as `expo-secure-store`; `ExpoClientStorage` is not needed for it. For
credentials needed after an Android background relaunch, use the dedicated adapter from
[`@ovok/native/background-sync`](/native-sdk/guide/components/background-sync/).

## Public import boundary [#public-import-boundary]

Import runtime setup from `@ovok/native/polyfills`; this subpath loads the polyfill
module without evaluating the package root and its other SDK modules. Import the app
and other native features only after the setup call.
