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

# .init()

> Initialize the cart session

```javascript theme={null}
openbridge.cart.init()
```

Initializes the cart by loading an existing cart from session storage or creating a new one.

<Warning>You must call `init()` before using any other cart methods.</Warning>

## Parameters

None

## Returns

`Promise<`[`ShopifyCart`](/api/types/cart#shopifycart)`>`

## Examples

### Basic initialization

```javascript theme={null}
await openbridge.cart.init()

console.log('Cart ready:', openbridge.cart.count(), 'items')
```

### Initialize on page load

```javascript theme={null}
document.addEventListener('DOMContentLoaded', async () => {
    await openbridge.init({
        token: 'your-token',
        storeDomain: 'your-store.myshopify.com'
    })

    await openbridge.cart.init()
})
```

### With subscription

```javascript theme={null}
// Subscribe before init to catch the initial state
openbridge.cart.subscribe((cart) => {
    updateCartUI(cart)
})

await openbridge.cart.init()
```

## Behavior

1. Checks `sessionStorage` for an existing cart ID
2. If found, fetches the cart from Shopify
3. If not found (or cart expired), creates a new cart
4. Stores the cart ID in `sessionStorage`
5. Notifies all subscribers with the cart state
