# .isTrusted

> The `.isTrusted` JS browser API property of an `Event` object indicates whether the event was generated by a user action.

## How do I check if an event came from a real user in JavaScript?

The browser API property that returns `true` if the event was generated by the browser, for example from a real user click, and `false` if it was created and dispatched by a script with `dispatchEvent()`.

- Topic: Event
- Type: property
- Browser support: Chrome 46+, Chrome Android 46+, Edge 12+, Firefox 1.5+, Firefox Android 4+, Safari 10+, Safari iOS 10+

## Example

Wrong:

```js
payButton.addEventListener('click', () => {
  submitPayment();
});
```

Right:

```js
payButton.addEventListener('click', (e) => {
  if (!e.isTrusted) return;
  submitPayment();
});
```

Ignoring untrusted events blocks synthetic clicks from `dispatchEvent()`, though page scripts can still call the function directly.

## Common mistakes

- Expecting `dispatchEvent(new MouseEvent('click'))` to count as a user gesture.

## Key points

- Sensitive actions check `event.isTrusted` instead of accepting any dispatched event.
- Tests that need trusted events use browser automation input, since `dispatchEvent()` events have `isTrusted` false.
- Code does not treat `isTrusted` as bot protection; automation tools can produce trusted input.

## Interview questions

### Is element.click() a trusted event?

No, `element.click()` dispatches an event with `isTrusted` set to false, though it still runs the element's activation behavior.

### Can I set isTrusted to true on my own event?

No, `isTrusted` is read-only, and only the browser sets it to true for real user or browser actions.

## Related cards

- [Event](https://wonderium.dev/js/event.md)
- [.addEventListener()](https://wonderium.dev/js/add-event-listener.md)
- [navigator.userActivation](https://wonderium.dev/js/navigator-user-activation.md)
- [Clickjacking](https://wonderium.dev/web/clickjacking.md)

---

- Level: [JavaScript](https://wonderium.dev/js.md)
- HTML version: https://wonderium.dev/js/event-is-trusted
- Last updated: 2026-11-25
