Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a new DOM concept for user-driven events rather than using isTrusted #105

Open
sefeng211 opened this issue Aug 2, 2022 · 11 comments
Open

Comments

@sefeng211
Copy link

We have been using the isTrusted attribute to check if the event comes from a user interaction, however this attribute only indicates that the event was dispatched by user agents.

For instance, user agents fire a scroll event with isTrusted=true for scrollLeft, and apparently we don't want to stop creating LCP when we see this scroll event.

So we need a new concept that we can use in the spec.

@yoavweiss
Copy link
Contributor

Thanks for filing this, @sefeng211!

/cc @noamr @domenic for thoughts on the above. Any objections to adding such a concept?

@yoavweiss
Copy link
Contributor

@domenic The navigation API seems to have a user initiated concept that may be close in spirit to what we want here. Do you think it'd make sense to pull that into DOM and generalize it beyond navigations?

@domenic
Copy link

domenic commented Aug 3, 2022

I don't think that concept (defined more fully here) is really related to what you're looking for here.

@noamr
Copy link
Contributor

noamr commented Aug 3, 2022

Looking at the definition of the scroll event, I'm not sure a new concept is needed. Perhaps that spec can be modified to preserve in the list of pending scroll event targets whether the event was user-initiated or programmatic, and LCP can refer to that.

Are there other places where this is needed?

@yoavweiss
Copy link
Contributor

yoavweiss commented Aug 3, 2022

The same concept is something we need for has dispatched input event, for "click", "mousedown" and "keydown".

We could create something specific for each one of these events (or two concepts, one for scroll and one for input).

@noamr
Copy link
Contributor

noamr commented Aug 3, 2022

Seems like isTrusted would be the right mechanism, except it doesn't send the right value for click. Doesn't say in the spec whether isTrusted is supported for scrolle vents. So I guess you could use isTrusted where it's supported and special-case click.

@noamr
Copy link
Contributor

noamr commented Aug 3, 2022

... using isTrusted in this way seems similar to how it's used for activation.

@domenic
Copy link

domenic commented Aug 3, 2022

The special behavior of isTrusted for click(), although theoretically impure, is probably still what you want for cases like this. That is, we set isTrusted to false for both click() and dispatchEvent(), reserving isTrusted true for "actual" clicks.

@noamr
Copy link
Contributor

noamr commented Aug 3, 2022

The special behavior of isTrusted for click(), although theoretically impure, is probably still what you want for cases like this. That is, we set isTrusted to false for both click() and dispatchEvent(), reserving isTrusted true for "actual" clicks.

Ah got it, thanks for the clarification. So isTrusted sounds perfect but you'd want to make sure it applies to scroll events or special-case it in the wording. Perhaps if it doesn't it would be valuable to propose to change that in CSSWG

@yoavweiss
Copy link
Contributor

At least for scrolling, isTrusted is not good enough, as e.g. setting scrollLeft triggers a trusted event, but shouldn't stop LCP entries from being emitted. I'm not sure if there are ways to trigger input events (beyond click()) that are UA trusted, but not user initiated.

@noamr
Copy link
Contributor

noamr commented Mar 28, 2023

At least for scrolling, isTrusted is not good enough, as e.g. setting scrollLeft triggers a trusted event, but shouldn't stop LCP entries from being emitted. I'm not sure if there are ways to trigger input events (beyond click()) that are UA trusted, but not user initiated.

So perhaps we can add a boolean to scroll events in particular (an isACTUALLYTrusted sort of thing, perhaps isScriptInitiated), and use isTrusted for everything else?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants