
Security News
pnpm 10.12 Introduces Global Virtual Store and Expanded Version Catalogs
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.
detect-passive-events
Advanced tools
The detect-passive-events npm package is a utility that helps developers determine if the browser supports passive event listeners. Passive event listeners can improve scrolling performance by letting the browser know that the event listener will not call preventDefault(), allowing the browser to optimize scrolling performance.
Detect Passive Event Support
This feature allows you to check if the browser supports passive event listeners. The code sample demonstrates how to use the detect-passive-events package to log whether passive event listeners are supported.
const detectPassiveEvents = require('detect-passive-events');
if (detectPassiveEvents.hasSupport) {
console.log('Passive event listeners are supported.');
} else {
console.log('Passive event listeners are not supported.');
}
The detect-it package provides a broader range of detection capabilities, including touch support, pointer events, and passive event listeners. It offers a more comprehensive solution for detecting various input capabilities and event listener support compared to detect-passive-events.
Modernizr is a well-known feature detection library that can detect a wide range of HTML5 and CSS3 features, including passive event listener support. It is more extensive and can be used to detect many other features beyond just passive event listeners.
Detects if the browser supports passive event listeners. Tree-shakable and side-effect free. Also available as part of detect-it
.
Note that the code used in the detection is adapted from this Passive Events Explainer.
detect-passive-events
npm install --save detect-passive-events
// 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);
}
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.
<script src="https://unpkg.com/detect-passive-events@2/dist/detect-passive-events.umd.production.js"></script>
// 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);
}
FAQs
Detect if the browser supports passive events
The npm package detect-passive-events receives a total of 161,775 weekly downloads. As such, detect-passive-events popularity was classified as popular.
We found that detect-passive-events demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.
Security News
Amaro 1.0 lays the groundwork for stable TypeScript support in Node.js, bringing official .ts loading closer to reality.
Research
A deceptive PyPI package posing as an Instagram growth tool collects user credentials and sends them to third-party bot services.