0

I'm trying to figure out a way to perform a trusted event programmatically in the browser. https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted

I know it says it's a readonly event but I figure there must be some sort of work around if the user really wants it. After all the browser/frontend is entirely client side so you should be able to manipulate it yourself if you so choose (via some option in the browser etc)

I came across this answer https://stackoverflow.com/a/53488689/3097821 but I can't figure out to to implement it.

It can either be a click or a keyboard event.

Can anybody help me out on this?

Trevor Wood
  • 2,347
  • 5
  • 31
  • 56
  • The answer you found is for a *chrome extension*. Alternatively, you can use any third-party tool to control your browser via [CDP](https://chromedevtools.github.io/devtools-protocol) and send the same command Input.dispatchMouseEvent. – wOxxOm Sep 09 '21 at 17:45
  • @wOxxOm doing this via extension would be an acceptable usecase. Thanks! I'll look into it. If you can provide a working example as an answer I'll accept it. – Trevor Wood Sep 10 '21 at 00:51
  • Try adapting [this official sample](https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/mv2-archive/api/debugger/pause-resume). – wOxxOm Sep 10 '21 at 05:52
  • @wOxxOm Oh man, thank you so much. Really appreciate it. Will give it a try – Trevor Wood Sep 10 '21 at 06:10

1 Answers1

1

Web content cannot generate a trusted event under any circumstances -- that is the whole point. Some actions don't care if an event is trusted or not (clicking a link, for example), but some do need to distinguish between a legitimate user-triggered event and a synthetic one create by untrusted web content.

Web Extensions are assumed to be working on the user's behalf, so they are allowed to create trusted events.

dveditz
  • 51
  • 3