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);