{"id":14384914,"url":"https://github.com/addityasingh/add-eventlistener-with-options","last_synced_at":"2026-01-16T15:31:06.197Z","repository":{"id":12236598,"uuid":"71156389","full_name":"addityasingh/add-eventlistener-with-options","owner":"addityasingh","description":"A utility function to check if EventTarget.addEventListener supports adding passive events","archived":false,"fork":false,"pushed_at":"2022-12-06T14:35:48.000Z","size":1356,"stargazers_count":9,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-02T01:18:09.430Z","etag":null,"topics":["addeventlistener","event-listener","nodejs","npm","passive","touch"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/addityasingh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"contributing.json","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-17T16:04:12.000Z","updated_at":"2023-07-05T02:19:57.000Z","dependencies_parsed_at":"2023-01-13T16:50:57.205Z","dependency_job_id":null,"html_url":"https://github.com/addityasingh/add-eventlistener-with-options","commit_stats":null,"previous_names":["addi90/add-eventlistener-with-options"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/addityasingh/add-eventlistener-with-options","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addityasingh%2Fadd-eventlistener-with-options","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addityasingh%2Fadd-eventlistener-with-options/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addityasingh%2Fadd-eventlistener-with-options/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addityasingh%2Fadd-eventlistener-with-options/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/addityasingh","download_url":"https://codeload.github.com/addityasingh/add-eventlistener-with-options/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addityasingh%2Fadd-eventlistener-with-options/sbom","scorecard":{"id":165984,"data":{"date":"2025-08-11","repo":{"name":"github.com/addityasingh/add-eventlistener-with-options","commit":"92ad402f6a5c3601f8fc9901aa268a13e11e347a"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/3 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"40 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-pp7h-53gx-mx7r","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx","Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-hr2v-3952-633q","Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3","Warn: Project is vulnerable to: MAL-2023-462","Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq","Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq","Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm","Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-282f-qqgm-c34q","Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f","Warn: Project is vulnerable to: GHSA-6394-6h9h-cfjg","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-gqgv-6jq5-jjj9","Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-xc7v-wxcw-j472","Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-16T14:52:32.624Z","repository_id":12236598,"created_at":"2025-08-16T14:52:32.624Z","updated_at":"2025-08-16T14:52:32.624Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28479409,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T11:59:17.896Z","status":"ssl_error","status_checked_at":"2026-01-16T11:55:55.838Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["addeventlistener","event-listener","nodejs","npm","passive","touch"],"created_at":"2024-08-28T18:01:46.604Z","updated_at":"2026-01-16T15:31:06.151Z","avatar_url":"https://github.com/addityasingh.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# add-eventlistener-with-options\nA utility function to check if [EventTarget.addEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener) supports adding `passive` (or `capture`, `once`) event options.\n\n[![NPM](https://nodei.co/npm/add-eventlistener-with-options.png)](https://npmjs.org/package/add-eventlistener-with-options)\n\n## Build status\n[![Build Status](https://travis-ci.org/addityasingh/add-eventlistener-with-options.svg?branch=master)](https://travis-ci.org/addityasingh/add-eventlistener-with-options)\n[![coverage](https://codecov.io/github/addityasingh/add-eventlistener-with-options/coverage.svg?precision=0)](https://codecov.io/github/addityasingh/add-eventlistener-with-options)\n\n## npm status\n[![downloads](https://img.shields.io/npm/dt/add-eventlistener-with-options.svg)](https://npmjs.org/package/add-eventlistener-with-options?cacheSeconds=3600)\n[![version](https://img.shields.io/npm/v/add-eventlistener-with-options.svg)](https://npmjs.org/package/add-eventlistener-with-options?cacheSeconds=3600)\n\n# Story behind Passive event listeners \n\nPassive event listeners are a new feature [in the DOM spec](https://dom.spec.whatwg.org/#dom-eventlisteneroptions-passive) that enable developers to opt-in to better scroll performance by eliminating the need for scrolling to block on touch and wheel event listeners.  Developers can annotate touch and wheel listeners with `{passive: true}` to indicate that they will never invoke `preventDefault`.  This feature [shipped in Chrome 51](https://www.chromestatus.com/features/5745543795965952), [Firefox 49](https://bugzilla.mozilla.org/show_bug.cgi?id=1266066) and [landed in WebKit](https://bugs.webkit.org/show_bug.cgi?id=158601). \n\n\n### The problem\n\nSmooth scrolling performance is essential to a good experience on the web, especially on touch-based devices.\nAll modern browsers have a threaded scrolling feature to permit scrolling to run smoothly even when expensive\nJavaScript is running, but this optimization is partially defeated by the need to wait for the results of\nany `touchstart` and `touchmove` handlers, which may prevent the scroll entirely by calling [`preventDefault()`](http://www.w3.org/TR/touch-events/#the-touchstart-event) on the event. While there are particular scenarios where an author may indeed want to prevent scrolling, analysis indicates that the majority of touch event handlers on the web never actually\ncall `preventDefault()`, so browsers often block scrolling unneccesarily. For instance, in Chrome for Android 80% of the touch events that block scrolling never actually prevent it. 10% of these events add more than 100ms of delay to the start of scrolling, and a catastrophic delay of at least 500ms occurs in 1% of scrolls.\n\n### Solution: the 'passive' option\n\nNow that we have an extensible syntax for specifying options at event handler registration time, we can add a new `passive` option which declares up-front that the listener will never call `preventDefault()` on the event.  If it does, the user agent will just ignore the request (ideally generating at least a console warning). \n\nNow rather than having to block scrolling whenever there are any touch or wheel listener, the browser only needs to do this when there are *non-passive* listeners (see [TouchEvents spec](http://w3c.github.io/touch-events/#cancelability)).  `passive` listeners are free of performance side-effects.\n\nThis package provides a smooth fallback implementation to use the `{ passive: true }` option in newer browsers, while falling back to `false` value in older ones. \nAdditionally, you could also use the method to use the `capture` and `once` options.\n\n# Syntax\n```javascript\naddEventListenerWithOptions(target, \n  eventName, \n  listener, \n  options, \n  optionName);\n```\n\n - `target`: The [EventTarget](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget) element to use as the target of the event\n - `eventName`: Name of the event to be handled using the event listener. E.g. `touchstart`, `touchend`\n - `listener`: The event listener callback to be called on the event\n - `options`: Additional options\n - `optionName`: Defaults to `passive`. Use [`once`, `capture`] to override.\n\n# Installation\nUse it with `npm` as\n\n```\nnpm install add-event-listener-with-options\n```\n\n# Example\n- To add the `passive` event listeners as default\n\n## ES6 syntax\n```javascript\nimport addEventListenerWithOptions from 'add-eventlistener-with-options';\n\naddEventListenerWithOptions(window, 'touchstart', () =\u003e {\n    // Execute callback code\n});\n```\n\n- The default option is `passive`, but you can even add `capture` or `once` options by passing them as the last parameter\n\n```javascript\naddEventListenerWithOptions(window, 'touchstart', () =\u003e {\n    // Execute callback code\n}, {}, 'capture');\n```\n\n# Performance test\nThere is a video showing the comparison of performance on [CNN website](https://www.cnn.com) here\n\n\u003ca href=\"https://www.youtube.com/watch?v=NPM6172J22g\"\u003e\n![demo video](https://cloud.githubusercontent.com/assets/39191/16223871/cab9f508-379f-11e6-8154-1d0a005ad071.png)\n\u003c/a\u003e\n\nAdditionally, I tested the change with below code and the Devtools Timline data ***before*** and ***after*** the change are shown below for a sample **Redux** application. The number of frames in green (\u003c 16ms) is increased after adding the `passive` option as compared below:\n\n### Before\n\n\n```javascript\nwindow.addEventListener('touchstart', (e) =\u003e {\n  console.log('e.defaultPrevented', e.defaultPrevented);  // will be false \n  for (let i =0; i\u003c 100; i++) {\n    console.log(`i ${i}`);\n    e.preventDefault(); // prevents the scroll because the event handler is not passive \n  }\n\n  console.log('e.defaultPrevented', e.defaultPrevented);  // true \n});\n```\n\n![Before Passive ](https://raw.githubusercontent.com/addityasingh/add-eventlistener-with-options/master/assets/before-passive.png)\n\n### After\n\n```javascript\naddEventListenerWithOptions(window, 'touchstart', (e) =\u003e {\n  console.log('e.defaultPrevented', e.defaultPrevented);  // will be false \n  for (let i =0; i\u003c 100; i++) {\n    console.log(`i ${i}`);\n    e.preventDefault(); // does nothing since the listener is passive \n  }\n\n  console.log('e.defaultPrevented', e.defaultPrevented);  // still false \n});\n```\n\n![After Passive ](https://raw.githubusercontent.com/addityasingh/add-eventlistener-with-options/master/assets/after-passive.png)\n\n\n# Reference and Credits\nMost of the sources for implementing this comes from the [Web Platform Incubator Community Group](https://www.w3.org/blog/2015/07/wicg/) suggestion on [EventListenerOptions](https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faddityasingh%2Fadd-eventlistener-with-options","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faddityasingh%2Fadd-eventlistener-with-options","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faddityasingh%2Fadd-eventlistener-with-options/lists"}