如何使用JavaScript触发'isTrusted = true'点击事件? [英] How to trigger an ‘isTrusted=true’ click event using JavaScript?

查看:7911
本文介绍了如何使用JavaScript触发'isTrusted = true'点击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如:
在我的内容脚本中,有一个按钮单击。


$ b

document.querySelector(SOME_SELECTOR)。click();

此行触发一个包含以下属性的点击事件:

  MouseEvent {isTrusted:false} 

触发一个MouseEvent,其中isTrusted属性将为true?

解决方案

我不确定这是否可能,因为它是一个只读属性,表示您正在尝试伪造的内容,即事件是否源自最终用户或来自脚本。
曾经存在基于浏览器的差异,(IE曾经将所有事件都视为可信),但我不知道这是否仍然存在。



https://developer.mozilla.org/en-US/docs / Web / API / Event

在这个主题中,firefox中提到的方法可能仍然有解决方法: Firefox扩展生成的可信任事件?



<但是你必须看看chrome文档来检查它们是否有类似的方法将事件委托给窗口,因为它提到了扩展事件在某些情况下可以被信任。


I'm trying to impersonate user clicks and mouse movements using a Chrome extension.

For example: In my content script there is a button click.

document.querySelector("SOME_SELECTOR").click();

This line triggers a click event with the following property:

MouseEvent {isTrusted: false}

How to trigger a MouseEvent where the isTrusted property will be true?

解决方案

I'm not sure if this is possible, since it's a read-only property that signifies exactly what you're trying to fake, namely if the event originated from the end user or from a script. There used to be browser-based differences, (IE used to have all events as trusted) but I don't know if this is still the case.

https://developer.mozilla.org/en-US/docs/Web/API/Event

There may still be ways around this, as mentioned for firefox in this topic:Are events generated by Firefox extension 'trusted'?

But you'll have to have a look at the chrome documentation to check if they have similar methods of delegating an event back to the window, since it does mention extension events are/can become trusted in some cases.

这篇关于如何使用JavaScript触发'isTrusted = true'点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆