![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
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 135,113 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.