Firefox扩展生成的事件是否可信? [英] Are events generated by Firefox extension 'trusted'?

查看:150
本文介绍了Firefox扩展生成的事件是否可信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Firefox扩展产生了一些事件,例如单击。作为响应,Web应用程序尝试打开一个新窗口。但是,当Popup阻止程序启动时,它会被Firefox阻止。但是,如果我手动单击一个按钮,并在Web应用程序试图打开窗口时响应该消息,它就会通过。



我的问题是为什么不把我的扩展生成的事件视为可信,并在用户单击时以相同的方式处理?是否有一些后门来实现这种行为?


解决方案

是的,扩展生成的事件总是可信的。这意味着 event.isTrusted 将会是 true ,事件将能够触发需要可信事件的动作Ctrl-Tab 按键事件来切换浏览器标签)。但是,它们保留合成事件,这意味着不存在与它们相关联的本机(OS级别)事件。由于弹出式窗口拦截器可以处理本地事件,因此它不会看到您的扩展所产生的事件。



您可以使用 nsIDOMWindowUtils.sendMouseEventToWindow()而不是 document.createEvent()。这个方法是用来测试的,并且会生成一个本地事件。这应该是足够好的弹出窗口阻止程序。

var utils = window.QueryInterface Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
utils.sendMouseEventToWindow(click,10,20,0,1,0);


My Firefox extension generates events, e.g. click. In response, the web application tries to open a new window. However it's getting blocked by Firefox as Popup blocker kicks in. However, if I manually click a button and in response to that when the web app tries to open window, it goes through.

My question is why aren't events generated by my extension treated as 'trusted', and treated the same way at user click? Is there some backdoor to achieve that behavior?

解决方案

Yes, events generated by extensions are always trusted. That means that event.isTrusted will be true and the events will be able to trigger actions that require trusted events (e.g. Ctrl-Tab keypress event to switch browser tabs). However, they stay synthesized events meaning that there is no native (OS-level) event associated with them. And since the pop-up blocker works with native events it will not see the events generated by your extension.

You can use nsIDOMWindowUtils.sendMouseEventToWindow() instead of document.createEvent(). This method is meant for testing and will generate a native event as well. This should be good enough for the pop-up blocker.

var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                  .getInterface(Components.interfaces.nsIDOMWindowUtils);
utils.sendMouseEventToWindow("click", 10, 20, 0, 1, 0);

这篇关于Firefox扩展生成的事件是否可信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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