
Product
Socket for Jira Is Now Available
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.
default-passive-events
Advanced tools
Makes {passive: true} by default when EventListenerOptions are supported
default-passive-events Makes {passive: true} by default when EventListenerOptions are supported
50 lines snippet that enables passive event listeners by default for some events (see list below). It basically will set { passive: true } automatically every time you declare a new event listener.
yarn add default-passive-events
Simply import the package:
import 'default-passive-events';
or require it:
require('default-passive-events');
or include it locally:
<script
type="text/javascript"
src="node_modules/default-passive-events/dist/index.js"
></script>
<script
type="text/javascript"
src="https://unpkg.com/default-passive-events"
></script>
This package is distributed as multiple, different types of output bundles. The most often your bundler will properly choose the correct version by itself.
To get more information about supported bundle formats have a look at official microbundle documentation. Especially interesting is the modern format which - if used properly with your bundle system - might produce significantly smaller output code.
Those are some examples and their output:
document.addEventListener('mouseup', onMouseUp); // {passive: true, capture: false}
document.addEventListener('mouseup', onMouseUp, true); // {passive: true, capture: true}
document.addEventListener('mouseup', onMouseUp, false); // {passive: true, capture: false}
document.addEventListener('mouseup', onMouseUp, { passive: false }); // {passive: false, capture: false}
document.addEventListener('mouseup', onMouseUp, {
passive: false,
capture: false,
}); // {passive: false, capture: false}
document.addEventListener('mouseup', onMouseUp, {
passive: false,
capture: true,
}); // {passive: false, capture: true}
document.addEventListener('mouseup', onMouseUp, {
passive: true,
capture: false,
}); // {passive: true, capture: false}
document.addEventListener('mouseup', onMouseUp, {
passive: true,
capture: true,
}); // {passive: true, capture: true}
Check the demo page for a working example.
Just to take benefit in your apps without having to edit every single event listener you already have.
Default-passive-events package makes following event listeners passive by default:
You can configure library to override different set of events than the default ones.
To do that set the window.defaultPassiveEvents_supportedPassiveEvents property like so:
window.defaultPassiveEvents_supportedPassiveEvents = ['scroll', 'wheel'];
Well, that's true, partly. First of all specification says that you shouldn't ever try to preventDefault from the context of passive listener. But if that's not a possibility you should know that in the console you see only error-looking log messages, which are not actual errors (ergo: they do not break your code).
Unfortunately, no. Since they are not actual errors there is no way to catch them and (more importantly) there is no way to distinguish whether you're inside of the passive listener context to know when not to call/override preventDefault method. Now, we look at the regarding issue in WHATWG repo whatwg/dom#587.
Yes, original addEventListener is available under _original property of our's addEventListener's implementation (so - element.addEventListener._original). Having that in mind, you can bring it back for however you want, e.g.:
element.addEventListener = element.addEventListener._original;
To release, simply run npm version <new_Version_number> and then pnpm publish.
FAQs
Makes {passive: true} by default when EventListenerOptions are supported
The npm package default-passive-events receives a total of 20,502 weekly downloads. As such, default-passive-events popularity was classified as popular.
We found that default-passive-events demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket for Jira lets teams turn alerts into Jira tickets with manual creation, automated ticketing rules, and two-way sync.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.