Why faking real browser events doesn't work

Published: (February 3, 2026 at 02:23 AM EST)
1 min read
Source: Dev.to

Source: Dev.to

Problem

I tried to programmatically trigger a typeahead dropdown with JavaScript.
Although dispatching the input events made the value appear in the input box, the UI didn’t react: the dropdown never opened and the component’s state wasn’t updated.

Why the events are ignored

The browser protects against synthetic events through the read‑only isTrusted property on the Event interface.

  • isTrusted: true – generated by the User Agent (real human clicks or physical key presses).
  • isTrusted: false – dispatched via EventTarget.dispatchEvent().

Because isTrusted cannot be set to true manually, the dropdown’s security logic ignored the “fake” events.

Solution

Instead of trying to fake a trusted event, I leveraged Vue’s reactive system:

  1. Update the data model directly.
  2. Programmatically set the typeahead option based on the new state.

By manipulating the component’s state rather than the DOM event, the dropdown behaved as expected.

Testing alternatives

When automated testing requires truly trusted events, you need to go beyond the standard sandbox:

  • Chrome DevTools Protocol (CDP) – injects events into the browser’s hardware pipeline, resulting in isTrusted: true.
  • Playwright, Cypress, or similar automation tools – handle user‑like interactions correctly.

If you can’t fake user authority, avoid forcing the DOM and use these tools or your framework’s native bindings and lifecycle methods to achieve the desired behavior.

Back to Blog

Related posts

Read more »

Replace Turbo confirm with native dialog

Rails, when using turbo‑links, ships with a built‑in confirmation dialog for destructive actions. You've probably used it countless times: erb The default turbo...