1

I was wondering if its possible to trigger a click event with isTrusted being true, i found out how to trigger a click event but i couldn't find any answers on how to set isTrusted as true


function click(x, y)
{
    var ev = new MouseEvent('click', {
        'view': window,
        'bubbles': true,
        'cancelable': true,
        'screenX': x,
        'screenY': y
    });

    var el = document.elementFromPoint(x, y);
    console.log(el); //print element to console
    el.dispatchEvent(ev);
}
click(255, 600);

Here is the code that i used to trigger a normal click with isTrusted being false

asumew
  • 11
  • 2
  • 2
    MDN -> `The isTrusted read-only property of the Event interface is a boolean value that is true when the event was generated by a user action, ` In other words, you can't, and if you could would take away the whole point of the flag.. :) – Keith Dec 07 '22 at 15:20
  • [^](https://stackoverflow.com/questions/74718923/javascript-trigger-a-mouseevent-with-istrusted-being-true#comment131874505_74718923) This is correct in browsers, but in some automation environments (e.g. [Puppeteer](https://pptr.dev/)), it is possible to configure this property to `true`. – jsejcksn Dec 07 '22 at 15:21
  • 1
    @jsejcksn Yes, automation is a different story.. – Keith Dec 07 '22 at 15:23

0 Answers0