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

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

问题描述

我的 Firefox 扩展生成事件,例如点击.作为响应,Web 应用程序尝试打开一个新窗口.但是,它在弹出窗口阻止程序启动时被 Firefox 阻止.但是,如果我手动单击一个按钮并在 Web 应用程序尝试打开窗口时响应该按钮,它会通过.

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?

推荐答案

编辑:这个答案已经过时了.它指的是自 Firefox 57 起不再支持的经典扩展.基于 Web 扩展 API 的扩展具有 无法生成可信事件.

Edit: This answer is badly outdated. It refers to classic extensions that are no longer supported as of Firefox 57. Extensions based on the Web Extensions API have no way of generating trusted events.

是的,扩展程序生成的事件始终受信任.这意味着 event.isTrusted 将为 true 并且事件将能够触发需要受信任事件的操作(例如 Ctrl-Tab keypress 事件切换浏览器标签).但是,它们保持合成事件,这意味着没有与它们关联的本机(操作系统级)事件.而且由于弹出窗口阻止程序与本机事件一起使用,因此它不会看到您的扩展程序生成的事件.

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.

您可以使用 nsIDOMWindowUtils.sendMouseEventToWindow() 代替document.createEvent().此方法用于测试并将生成本机事件.这对于弹出窗口阻止程序来说应该足够了.

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天全站免登陆