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

# plugin-window-events

The `@appsignal/plugin-window-events` plugin binds to the `window.onerror` and `window.onunhandledrejection` event handlers to catch any errors that are otherwise not caught elsewhere in your code.

## Installation

Add the `@appsignal/plugin-window-events` and `@appsignal/javascript` packages to your `package.json` file and run `yarn install`/`npm install`.

You can also add these packages to your `package.json` on the command line:

<CodeGroup>
  ```bash Bash theme={null}
  yarn add @appsignal/javascript @appsignal/plugin-window-events
  npm install @appsignal/javascript @appsignal/plugin-window-events
  ```
</CodeGroup>

## Usage

<CodeGroup>
  ```javascript JavaScript theme={null}
  import { plugin } from `@appsignal/plugin-window-events`
  appsignal.use(plugin(options));
  ```

  ### Use with Next.js

  Even with `"use client"`, Next.js pre-renders client components on the server, where the `window` object is not available. Guard the plugin initialization with:

  ```javascript JavaScript theme={null}
  if (typeof window !== "undefined") {
    appsignal.use(plugin(options));
  }
  ```
</CodeGroup>

## `plugin` options

The `plugin` can be initialized with the following options:

| Param                | Type    | Description                                                                                                                              |
| -------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| onerror              | Boolean | (optional) A boolean value representing whether the plugin should bind to the `window.onerror` handler. Defaults to `true`.              |
| onunhandledrejection | Boolean | (optional) A boolean value representing whether the plugin should bind to the `window.onunhandledrejection` handler. Defaults to `true`. |
