# detect-passive-events

> Detect if the browser supports passive events

Latest version **2.0.3** (published 2021-02-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install detect-passive-events
pnpm add detect-passive-events
yarn add detect-passive-events
bun add detect-passive-events
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2021-02-12 |
| First published | 2016-11-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 24.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Author | Rafael Pedicini |
| Maintainers | rafgraph |
| Keywords | detect, passive, passive events |

## Links

- npm: https://www.npmjs.com/package/detect-passive-events
- Repository: https://github.com/rafgraph/detect-passive-events
- Homepage: https://detect-it.rafgraph.dev
- Issues: https://github.com/rafgraph/detect-passive-events/issues
- npm.io page: https://npm.io/package/detect-passive-events

## Dependencies (1)

- [detect-it](https://npm.io/package/detect-it.md) ^4.0.1

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 2.0.3 (latest) — 2021-02-12
- 2.0.2 — 2020-11-27
- 2.0.1 — 2020-10-15
- 2.0.0 — 2020-10-15
- 1.0.5 — 2020-09-10
- 1.0.4 — 2017-09-26
- 1.0.3 — 2017-09-25
- 1.0.2 — 2017-02-27
- 1.0.1 — 2017-02-24
- 1.0.0 — 2016-11-08

## README

# Detect Passive Events

Detects if the browser supports passive event listeners. Tree-shakable and side-effect free. Also available as part of [`detect-it`][detectitrepo].

[Live detection test][livedetectiontest]

[![npm](https://img.shields.io/npm/dm/detect-passive-events?label=npm)](https://www.npmjs.com/package/detect-passive-events) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/detect-passive-events?color=purple)](https://bundlephobia.com/result?p=detect-passive-events) ![npm type definitions](https://img.shields.io/npm/types/detect-passive-events?color=blue)

> Note that the code used in the detection is adapted from this [Passive Events Explainer][passiveexplainer].

### Using `detect-passive-events`

```
npm install --save detect-passive-events
```

```js
// supportsPassiveEvents is a boolean
import { supportsPassiveEvents } from 'detect-passive-events';

if (supportsPassiveEvents) {
  // passive events are supported by the browser
  document.addEventListener('scroll', handleScroll, { capture: false, passive: true });
} else {
  // passive events are not supported by the browser
  document.addEventListener('scroll', handleScroll, false);
}
```

### Or use the script directly in the browser

Optionally, instead using `npm install` you can the load the script directly in the browser. A minified UMD version is available from Unpkg for this purpose.

```html
<script src="https://unpkg.com/detect-passive-events@2/dist/detect-passive-events.umd.production.js"></script>
```

```js
// it will be available on the window as DetectPassiveEvents
if (window.DetectPassiveEvents.supportsPassiveEvents) {
  document.addEventListener('scroll', handleScroll, { capture: false, passive: true });
} else {
  document.addEventListener('scroll', handleScroll, false);
}
```

<!-- links -->

[livedetectiontest]: https://detect-it.rafgraph.dev
[passiveexplainer]: https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
[detectitrepo]: https://github.com/rafgraph/detect-it

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