Are events generated by Firefox extension 'trusted'?

后端 未结 1 683
暗喜
暗喜 2020-12-03 19:18

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 kic

相关标签:
1条回答
  • 2020-12-03 19:26

    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.

    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);
    
    0 讨论(0)
提交回复
热议问题