# is-trusted

> Listen to events that are only originating from user

Latest version **1.0.6** (published 2023-11-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install is-trusted
pnpm add is-trusted
yarn add is-trusted
bun add is-trusted
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2023-11-15 |
| First published | 2023-10-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | thepicture |
| Maintainers | thepicture |
| Keywords | is, trusted, onclick, event, security |

## Links

- npm: https://www.npmjs.com/package/is-trusted
- Homepage: http://thepicture/is-trusted
- npm.io page: https://npm.io/package/is-trusted

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2023-11-15
- 1.0.5 — 2023-10-20
- 1.0.4 — 2023-10-19
- 1.0.3 — 2023-10-18
- 1.0.2 — 2023-10-17
- 1.0.0 — 2023-10-17

## README

# is-trusted

Intercepts `addEventListener`, `attachEvent` and `on` events by checking origin of event

## Usage

Append `index.js` script tag before all scripts in `head`

## API

```js
window.addEventListener("addlistenerwrap", (event: CustomEvent<Function>)); // fires on addEventListener/attachEvent
window.addEventListener("oneventwrap", (event: CustomEvent<Function>)); // fires when wrapping the original function for additional middleware
window.addEventListener("addlistenerviolation", (event: CustomEvent<Args>)); // fires on addEventListener/attachEvent non-trusted event origin
window.addEventListener("oneventviolation", (event: CustomEvent<Args>)); // fires on "on" event non-trusted origin
```

## Test

```js
(() => {
  const b = document.createElement("b");

  b.addEventListener("click", () => console.log("trusted"));
  b.textContent = "click";

  document.body.prepend(b);
})();

document.querySelector("b").click(); // event does not fire
document.querySelector("b").dispatchEvent(new MouseEvent("click")); // event does not fire

// Event fires on manual click
```

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