Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are events generated by Firefox extension 'trusted'?

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?

like image 206
Sunil Agrawal Avatar asked Jul 12 '12 16:07

Sunil Agrawal


People also ask

How safe are Firefox extensions?

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.

What is Firefox browser extension?

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.

Does Firefox have browser extensions?

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.

What language are Firefox extensions written in?

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.


1 Answers

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);
like image 173
Wladimir Palant Avatar answered Oct 06 '22 22:10

Wladimir Palant