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

# Wendung.sendBeacon(): Drain the queue with keepalive requests

> Drain the entire event queue as parallel fetch requests with keepalive, so delivery can continue while the page unloads.

Call `Wendung.sendBeacon()` to send everything in the queue at once. It splits the queue into batches and sends them all in parallel as `fetch` requests with `keepalive: true`, which lets the browser finish the requests even while the page is unloading. Despite the name, it does not use `navigator.sendBeacon`; requests carry the same JSON body and headers (including `X-API-Key`) as [`flush()`](/api-reference/flush).

The SDK already calls this automatically on `visibilitychange` (when the page becomes hidden) and `pagehide`. Call it manually only in a custom unload flow, or when you want to drain the whole queue rather than the single batch `flush()` sends.

Throws if called before [`init()`](/api-reference/init).

```typescript theme={null}
Wendung.sendBeacon(): Promise<void>
```

## Parameters

None.

## Returns

<ResponseField name="Promise<void>" type="Promise<void>">
  Resolves after all batch requests have settled; it never rejects. Failed batches follow the normal [retry rules](/api-reference/flush#error-handling). Resolves immediately if the queue is empty, or if `fetch` is unavailable (events are retained). During a real unload the page may terminate before the promise resolves; `keepalive` lets the requests themselves complete regardless.
</ResponseField>

## Examples

### Draining the queue before teardown

```typescript theme={null}
async function shutdown() {
  await Wendung.sendBeacon()
  Wendung.destroy()
}
```


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