# ssr-window

> Better handling for window object in SSR environment

Latest version **5.0.1** (published 2025-06-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install ssr-window
pnpm add ssr-window
yarn add ssr-window
bun add ssr-window
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.1 |
| Published | 2025-06-27 |
| First published | 2018-02-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 141 |
| Author | Vladimir Kharlampidi |
| Maintainers | nolimits4web |
| Keywords | ssr, window, document |

## Links

- npm: https://www.npmjs.com/package/ssr-window
- Repository: https://github.com/nolimits4web/ssr-window
- Issues: https://github.com/nolimits4web/ssr-window/issues
- npm.io page: https://npm.io/package/ssr-window

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 5.0.1 (latest) — 2025-06-27
- 4.0.0-beta.3 (beta) — 2021-08-04
- 3.0.0-alpha.4 (next) — 2020-05-20
- 5.0.0 — 2025-02-12
- 4.0.2 — 2021-12-13
- 4.0.1 — 2021-10-27
- 4.0.0 — 2021-08-25
- 4.0.0-beta.2 — 2021-07-22
- 4.0.0-beta.1 — 2021-07-22
- 3.0.0 — 2020-11-09
- 3.0.0-alpha.3 — 2020-05-12
- 2.0.0 — 2020-05-12
- 2.0.0-beta.8 — 2020-05-12
- 3.0.0-alpha.2 — 2020-05-11
- 3.0.0-alpha.1 — 2020-05-11
- … 8 more at https://npm.io/package/ssr-window/versions

## README

# SSR Window

Better handling for `window` and `document` object in SSR environment.

This library doesn't implement the DOM (like JSDOM), it just patches (or creates `window` and `document` objects) to avoid them to fail (throw errors) during server-side rendering.

Was created for use in:

- [Dom7](https://github.com/nolimits4web/dom7)
- [Swiper](https://github.com/nolimits4web/swiper)
- [Framework7](https://github.com/framework7io/framework7)

## Installation

Library available on NPM:

```
npm i ssr-window
```

## Usage

```js
import { window, document } from 'ssr-window';

window.addEventListener('resize', () => {});

const div = document.querySelectorAll('div');
```

## Extending

If you rely on some window/document properties which are not included here, you can use `extend` helper to add them:

```js
import { window, document, extend } from 'ssr-window';

// add window.navigator.language
extend(window, {
  navigator: {
    language: 'en',
  },
});

// add document.body
extend(document, {
  body: {
    /* ... */
  },
});
```

## Contribution

Yes please! See the [contributing guidelines](https://github.com/nolimits4web/ssr-window/blob/master/CONTRIBUTING.md) for details.

## Licence

This project is licensed under the terms of the [MIT license](https://github.com/nolimits4web/ssr-window/blob/master/LICENSE).

---
_Source: https://npm.io/package/ssr-window · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
