---
url: >-
  https://game-engine-io.github.io/enginex-frontend-sdk/reference/api/@getenginex/sdk-igaming/first-frame/functions/connectFirstFrame.md
---
[Reference](../../../../index.md) / [@getenginex/sdk-igaming/first-frame](../index.md) / connectFirstFrame

# connectFirstFrame()

> **connectFirstFrame**(`iframe`, `handlers`, `options?`): [`FirstFrame`](../interfaces/FirstFrame.md)

Connects to the FIRST sportsbook iframe: receives FIRST's events in typed handlers and sends
commands with `send`. It only delivers messages whose `origin` is the `src` origin of the iframe **and** whose
`source` is the iframe's `contentWindow`; invalid JSON or JSON without `eventType` is ignored without throwing.
The payload arrives as FIRST sent it (`unknown`): validate before using it.

## Parameters

### iframe

[`FirstFrameTarget`](../interfaces/FirstFrameTarget.md)

### handlers

[`FirstFrameHandlers`](../interfaces/FirstFrameHandlers.md)

### options?

[`ConnectFirstFrameOptions`](../interfaces/ConnectFirstFrameOptions.md) = `{}`

## Returns

[`FirstFrame`](../interfaces/FirstFrame.md)

## Example

```ts
import { connectFirstFrame } from '@getenginex/sdk-igaming/first-frame'

const frame = connectFirstFrame(iframe, {
  onBetPlaced: () => void enginex.wallet.getBalance().then(showBalance),
  onLoginRequired: () => openLogin(),
})
// when unmounting the iframe:
frame.dispose()
```

## Throws

`CONFIGURATION_ERROR` if the window (`options.window` or `globalThis`) has no
`addEventListener`/`removeEventListener`.
