Open Bug 1402266 Opened 3 years ago Updated 3 years ago

sendKeyEvent and sendMouseEventToWindow will not deliver the event when the Firefox lost focus in xpcom extensions

Categories

(Core :: DOM: Events, defect, P5)

55 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: shangerxin, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36

Steps to reproduce:

We have use an experimental extension to simulate the keyboard mouse event by nsIDDOMWindowUtils interface. The relative code is 

let utils = activeWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);

The activeWindow is get from the Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator), with method getZOrderDOMWindowEnumerator().

The keyboard and mouse event are send with the methods
utils.sendMouseEventToWindow()
utils.sendKeyEvent()

OS: Window 10 64bit
Firefox version: 55.0.3 64-bit
The code is executed in Firefox Experimental extension, so we could call the XPCOM APIs


Actual results:

When Firefox process get focus, everything works fine, the code also works when multiple windows in Firefox.

If the Firefox process not get focus, such as the focus switch to Explorer the keyboard and mouse event will not be delivered


Expected results:

The keyboard and mouse event should be always delivered
Component: Untriaged → XPCOM
Product: Firefox → Core
I'm pretty sure not delivering synthetic events from nsIDOMWindowUtils when the window doesn't have focus is intentional behavior; is that correct, smaug?

It probably doesn't make much difference anyway, since access to XPCOM from extensions is going away in Firefox 57.
Flags: needinfo?(bugs)
At least for key events it is very much intentional. And both these methods are anyway for testing only.
Focus-less keyboard events are used in some testing setups by having focusmanager.testmode=true.
Flags: needinfo?(bugs)
The root cause is found. The method send* method of Utils are works find, but the property gBrowser is not null for the windows returned by getZOrderDOMWindowEnumerator when Firefox process do not have focus.
Correct a typo. The gBrowser property is null for the windows returned by getZOrderDOMWindowEnumerator
Component: XPCOM → DOM: Events
Very low priority as access to XPCOM from extensions is going away in Firefox 57
Priority: -- → P5
Summary: sendKeyEvent and sendMouseEventToWindow will not deliver the event when the Firefox lost focus → sendKeyEvent and sendMouseEventToWindow will not deliver the event when the Firefox lost focus in xpcom extensions
You need to log in before you can comment on or make changes to this bug.