Skip to content
← Insights
Nov 14, 20265 min read

A browser event flag tells you who dispatched the event

A scripted click can lead to a trusted submit event. Read isTrusted per event and test the exact browser path before using the flag in a product decision.

A blank browser window with an event card under a magnifying glass, beside a computer mouse and a small inspection dial

A button can produce an untrusted click event, then cause a trusted submit event on its form. Both values can be correct because the flag belongs to each event, with its own dispatch path.

That behavior makes event.isTrusted useful for tracing browser interactions. The useful question is which mechanism dispatched this particular event. Deciding whether an action was authorised requires evidence about the action and the user who requested it.

Read the flag at the event level

The DOM standard defines isTrusted in terms of dispatch by the user agent. Script-created events start with the value false. The standard also specifies the legacy behavior of the click() method, whose click event has the value false.

MDN's current description includes programmatic focus as an example of browser-generated behavior that can produce a trusted event. A script can therefore be involved in an interaction whose resulting event has isTrusted set to true.

Record the event type beside the value in the diagnostic log. That allows a focus event to be distinguished from a click. The same interaction can involve several event types in sequence.

It also helps to record which code path initiated the test. A controlled call to a DOM method gives a developer an explanation for the observation. An isolated production event usually supplies less information about what preceded it.

A small Chromium test exposes the distinction

A local check on 14 November 2026 used Chromium 157.0.8103.78 with a simple form and submit button. The test prevented navigation. Its records identified the event type for every observed interaction. It produced these values:

Initiating action Event observed isTrusted
dispatchEvent() on the button click false
button.click() click false
The same button.click() activation submit true
input.focus() focus true
form.requestSubmit() submit true
Playwright locator.click() click true
The same Playwright click submit true

The check concerns that browser and setup. It is a reproducible observation, with no claim that every browser or automation library produces every row identically.

The form result is particularly useful when debugging a guard. A condition attached to the button's click handler can see false, while another condition attached to the form's submit handler sees true. The two handlers are examining different events.

If a product depends on the distinction, keep a browser-level test for the exact handler and interaction. That will show what the product is actually reading when its implementation changes.

Submission methods choose different paths

MDN's requestSubmit() reference explains that the method follows the form-submission process with validation and a submit event. The direct submit() method skips those steps.

That difference affects where a check can run. A listener for the submit event can observe the requestSubmit() route. A call that bypasses that event leaves the listener with nothing to inspect. The application's server still receives a request according to the submission path being used.

Choose the form API for the behavior the application needs. If validation belongs in the interaction, use the path that invokes it. Keep the server's validation independent so it can assess the request it actually receives.

A test should include the keyboard route as well as the visible button. A person can submit a form without clicking the button with a pointer. Testing only that click handler can leave the actual form behavior outside the check.

Automation can produce browser-dispatched events

Playwright's input documentation describes interactions through locators, including clicks and keyboard input. In the local check, a locator click produced a trusted click event. The browser handled an input action initiated by test software.

That observation limits what a true value can say about a visitor. The value describes the event's dispatch status. It leaves the identity and intent of the process controlling the browser to be established through other evidence.

For analytics, record the flag as an event property if it helps investigate a known interaction. Define the population that uses that property before comparing counts. Labelling every trusted event as a verified human visit would introduce an unsupported classification into the report.

A scripted product tour can produce a different case. If it calls element.click(), its click handler can receive false. The tour's own implementation explains the value. A product decision to reject the event should account for the supported interaction being rejected.

Put the check beside the behavior it controls

A diagnostic listener can simply record an event. A listener that cancels an action changes what the interface permits. Decide which effect is intended before adding an early return based on the flag.

If an action needs explicit confirmation, define that confirmation in the interaction itself. If it needs permission to change a server record, evaluate that permission on the server for the requested record. The browser's event flag can remain useful in the diagnostic trail without carrying those separate responsibilities.

Accessibility testing belongs to the actual interaction too. Exercise the supported keyboard behavior and assistive-technology paths instead of assuming their event sequence from a mouse-only test. Preserve the result of each check with the browser version used.

When a handler appears to reject a legitimate action, log the event type and the route that produced it in a controlled reproduction. Inspect the surrounding sequence before changing the condition. The next event may already explain why the first flag looked surprising.

JavaScriptBrowser APIsTesting