JavaScript Event isTrusted Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance property

What You’ll Learn

The isTrusted property is a read-only boolean on every Event: true when the user agent generated the event, and false when your script sent it with dispatchEvent(). Learn the HTMLElement.click() exception, MDN’s simple check, and practical patterns—with five examples and try-it labs.

01

Kind

Instance property

02

Type

boolean (read-only)

03

true

UA-generated

04

false

dispatchEvent / .click()

05

Forge?

Cannot set it

06

Status

Baseline widely

Introduction

Your click handler cannot tell “who” clicked just by looking at event.type. Real mouse/keyboard input and events you create in JavaScript can look the same—unless you read event.isTrusted.

When the browser (user agent) creates the event for a real interaction—or for some of its own programmatic methods such as HTMLElement.focus()—MDN documents isTrusted as true. When you call target.dispatchEvent(new Event(…)), it is false. Calling element.click() also produces a click with isTrusted === false.

💡
Beginner tip

You cannot assign event.isTrusted = true. The browser owns this flag. Scripts cannot fake a trusted event that way.

Understanding Event.isTrusted

An instance property that answers: “Did the user agent generate this event, or did script dispatch it?”

  • true — generated by the user agent (user actions and some UA methods such as focus()).
  • false — dispatched via EventTarget.dispatchEvent(), or a click from HTMLElement.click().
  • Read-only — cannot be forged by assignment.
  • Baseline Widely available on MDN (since September 2016); also in Web Workers.

📝 Syntax

JavaScript
event.isTrusted

Value

A boolean value.

MDN check

JavaScript
if (e.isTrusted) {
  /* The event is trusted */
} else {
  /* The event is not trusted */
}

⚡ Quick Reference

GoalCode / note
Readevent.isTrusted
Real user clickTypically true
dispatchEventfalse
el.click()false for that click
MDN statusBaseline Widely available (since September 2016)

🔍 At a Glance

Four facts to remember about Event.isTrusted.

Type
boolean

Read-only

true
UA

User agent

false
script

dispatch / .click()

Baseline
widely

Since Sep 2016

Examples Gallery

Examples follow MDN Event: isTrusted. Use View Output or Try It Yourself.

📚 Getting Started

MDN’s trust check and a real user click.

Example 1 — MDN Trusted Check

Branch on whether the event is trusted.

JavaScript
button.addEventListener("click", (e) => {
  if (e.isTrusted) {
    out.textContent = "The event is trusted";
  } else {
    out.textContent = "The event is not trusted";
  }
});
Try It Yourself

How It Works

This is MDN’s pattern: read the boolean and branch.

Example 2 — Log a Real User Click

Click the button yourself and print isTrusted.

JavaScript
button.addEventListener("click", (event) => {
  console.log("isTrusted =", event.isTrusted); // true for a real click
});
Try It Yourself

How It Works

User-agent input (mouse, keyboard, touch) typically produces trusted events.

📈 Scripted Events & Guards

dispatchEvent, click(), and trusted-only handlers.

Example 3 — dispatchEvent Is Untrusted

Create and dispatch a synthetic click; isTrusted is false.

JavaScript
button.addEventListener("click", (event) => {
  out.textContent = "isTrusted = " + event.isTrusted;
});

button.dispatchEvent(new MouseEvent("click", { bubbles: true }));
// logs: isTrusted = false
Try It Yourself

How It Works

Anything you send with dispatchEvent() is marked untrusted.

Example 4 — HTMLElement.click() Is Untrusted

MDN: programmatic .click() sets isTrusted to false.

JavaScript
button.addEventListener("click", (event) => {
  out.textContent = "isTrusted = " + event.isTrusted;
});

button.click(); // programmatic — isTrusted false
Try It Yourself

How It Works

Even though the browser fires the click for you, this path is not a trusted user gesture.

Example 5 — Run Logic Only for Trusted Events

Ignore scripted clicks; react only to real user (trusted) input.

JavaScript
button.addEventListener("click", (event) => {
  if (!event.isTrusted) {
    out.textContent = "Ignored untrusted click";
    return;
  }
  out.textContent = "Handled trusted click";
});

// Scripted paths are ignored:
button.click();
button.dispatchEvent(new Event("click", { bubbles: true }));
Try It Yourself

How It Works

Click the button yourself in the try-it lab to see the trusted branch.

🚀 Common Use Cases

  • Separating analytics for real user clicks vs test harness events.
  • Avoiding double work when both UI code and .click() fire handlers.
  • Debugging: confirm whether a handler saw a synthetic event.
  • Teaching dispatchEvent vs genuine user input.
  • Guarding sensitive UI actions that should require a real gesture (with other checks too).

🔧 How It Works

1

Something creates an event

User input, a UA method, dispatchEvent, or .click().

Source
2

Browser sets the flag

Trusted for UA-generated paths; untrusted for script dispatch / .click().

Flag
3

Listeners read it

Your handler inspects event.isTrusted (read-only).

Read
4

You branch safely

Treat trusted and untrusted paths differently when your app needs that.

📝 Notes

Universal Browser Support

Event.isTrusted is marked Baseline Widely available on MDN (since September 2016). Logos use the shared browser-image-sprite.png sprite from this project. It is also available in Web Workers.

Baseline · Widely available

Event.isTrusted

Read-only boolean: true for user-agent-generated events, false for dispatchEvent() and HTMLElement.click().

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer Supported in modern IE versions (legacy)
Full support
Event.isTrusted Excellent

Bottom line: Use isTrusted to tell real UA events from scripted ones—never try to assign the flag yourself.

Conclusion

Event.isTrusted tells you whether the user agent generated the event or your script dispatched it. Remember that element.click() is untrusted, and that you cannot forge the flag yourself.

Continue with originalTarget, dispatchEvent(), defaultPrevented, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Read isTrusted when synthetic vs real matters
  • Expect false from dispatchEvent and .click()
  • Pair with clear logging in tests and demos
  • Keep trusted-only guards explicit and documented
  • Combine with other checks for sensitive actions

❌ Don’t

  • Assign event.isTrusted = true
  • Assume every browser method produces untrusted events
  • Confuse isTrusted with defaultPrevented
  • Treat it as the only security control for critical actions
  • Forget that automated .click() is untrusted

Key Takeaways

Knowledge Unlocked

Five things to remember about isTrusted

The UA vs script flag on every Event.

5
Core concepts
02

true

UA-generated

Trusted
🚫03

false

dispatch / .click()

Script
🛡️04

Cannot forge

no assignment

Rule
🎯05

Baseline

since Sep 2016

Status

❓ Frequently Asked Questions

It is a read-only boolean on an Event. It is true when the event was generated by the user agent (including many user actions and some programmatic UA methods), and false when the event was dispatched via EventTarget.dispatchEvent().
No. MDN marks Event.isTrusted as Baseline Widely available (since September 2016). It is not Deprecated, Experimental, or Non-standard. It is also available in Web Workers.
No. MDN states that the click event fired through HTMLElement.click() sets isTrusted to false.
MDN notes that events generated by the user agent—including via programmatic methods such as HTMLElement.focus()—can be trusted (isTrusted true), unlike events you create and send with dispatchEvent().
No. It is read-only. Scripts cannot forge a trusted event by assigning event.isTrusted = true.
When you want to treat real user (or UA) interactions differently from synthetic events you dispatched—for example logging, analytics, or avoiding accidental double-handling of scripted clicks.
Did you know?

isTrusted is about who created the event, not about whether the default action was blocked. An untrusted event can still bubble, and a trusted event can still have defaultPrevented === true.

Next: originalTarget

Learn Firefox’s non-standard original target (may include anonymous content).

originalTarget →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful