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?
When a developer submits an extension to addons.mozilla.org, it's scanned for a set of common issues. It may also be subject to human review. But neither of these processes guarantee that an extension is absolutely 100% safe.
Mozilla Firefox addons or extensions are programs that can be installed into Firefox in order to change the browser's functionality. This includes adding new features or modifying existing behavior in Firefox in order to fix bugs, add extra functionality, or increase the browser's security.
Extensions add new features to Firefox or modify existing ones. There are extensions that allow you to block advertisements, download videos from websites, integrate Firefox with websites like Facebook or Twitter, and add features included in other browsers, such as translators.
Add-ons allow developers to extend and modify the functionality of Firefox. They are written using standard Web technologies - JavaScript, HTML, and CSS - plus some dedicated JavaScript APIs.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With