# Initialization

## getClient(selector)

Get an instance of the Appetize client.

{% hint style="warning" %}
When using `getClient(selector)`, you **must set** the iframe’s `src` attribute *before* calling `getClient` to configure the initial session.
{% endhint %}

```javascript
const client = await window.appetize.getClient('#my_iframe')
```

**Parameters**

| Name     | Type     | Description                                             |
| -------- | -------- | ------------------------------------------------------- |
| selector | `string` | A query selector string pointing to the embedded iframe |

## getClient(selector, config)

Get an instance of the Appetize client as well as set the initial config when loading the client.

*Useful when the embed link might not be known up front and the configuration has to be applied at runtime.*

{% hint style="warning" %}
When using `getClient(selector, config)`, **do not set** `iframe.src`.\
Setting the `src` manually may cause a race condition where the iframe loads before the SDK connects.\
\
For Private Cloud embeds, use `data-appetize-url` on the iframe instead of `src`.
{% endhint %}

```javascript
const client = await window.appetize.getClient('#my_iframe', {
    buildId: '{buildId|publicKey}',
    device: 'iphone11pro',
    osVersion: '15.0'
    ...
})
```

**Parameters**

| Name     | Type                                                                  | Description                                                                                                                  |
| -------- | --------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| selector | `string`                                                              | A query selector string pointing to the embedded iframe                                                                      |
| config   | [SessionConfig](/javascript-sdk/api-reference/types/sessionconfig.md) | A JSON object describing the [Configuration options](/javascript-sdk/configuration.md#configuration-options) for the device. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.appetize.io/javascript-sdk/api-reference/initialization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
