Open Bug 1942669 Opened 1 year ago Updated 7 months ago

Firefox file dialog not opening via JavaScript when triggered by keyboard shortcut with CTRL or ALT modifiers

Categories

(Core :: DOM: Core & HTML, defect)

Firefox 134
Desktop
Unspecified
defect

Tracking

()

Tracking Status
firefox135 --- affected
firefox136 --- affected
firefox137 --- affected

People

(Reporter: dswitzer, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:134.0) Gecko/20100101 Firefox/134.0

Steps to reproduce:

When triggering the file dialog to open via a JavaScript keyboard shortcut, Firefox will not always open the dialog when either the Control or Alt modifiers are being held. When the modifiers are not held, it always works as expected.

I've attached an example (file_input_keyboard_issue.html) which illustrates the behavior, but the behavior can be seen with the following code:

HTML:

<input type="file" id="fileInput" />

JavaScript:

document.addEventListener('keydown', function(event){
	if(	(event.key.toLowerCase() == "a") ){
		event.preventDefault();

		console.log("Open dialog!", (new Date()).getTime());
		document.getElementById('fileInput').click();
	}
});

Using the above code, pressing the letter "A" will always trigger the file upload dialog, but if you press and hold any combination of CTRL or ALT then it will not always work.

You can see this by opening the dialog, then clicking the "Cancel" button and pressing CTRL+A. When you do this, the dialog will not open unless you click somewhere on the page, but if you just press "A" it will work as expected.

I've tried many different keycodes besides "A" and they all exhibit the same behavior.

Actual results:

If you do not click somewhere in the DOM (after canceling the file dialog via the "Cancel" button or pressing [ESC] key), then pressing CTRL+A, ALT+A or CTRL+ALT+A wire dispatch the events as expected, but the file dialog will not open. If this happens, you can click anywhere in the DOM and then repeat the keyboard command it will open.

then nothing will happen if the file dialog was canceled, but the events are fired as expected

Expected results:

A keyboard modifier should not prevent the file dialog from opening. It should always open just as it does when neither the CTRL nor ALT modifiers are pressed.

I'm not sure when this problem started, but I suspect it's been around a while.

The Bugbug bot thinks this bug should belong to the 'Firefox::Keyboard Navigation' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Keyboard Navigation

The severity field is not set for this bug.
:dao, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(dao+bmo)

Hello! Thank you for submitting this issue.

I have managed to reproduce the issue with firefox 137.0a1(2025) and 135.0 on Ubuntu 22.04 with the steps provided in the description.
I will mark this issue as NEW in order to get our developers involved and provide a solution for this issue.

Have a nice day!

Status: UNCONFIRMED → NEW
Ever confirmed: true
Hardware: Unspecified → Desktop

I'm glad the example repo was sufficient to demonstrate the problem. Seems like a minor issue, but I thought it might be hiding a bigger issue w/keyboard events.

Yes, I think this is expected based on our code CanUserGestureActivateTarget not allowing most combinations with special keys.

Blocks: 1577516
See Also: → 1940664

Since nightly and release are affected, beta will likely be affected too.
For more information, please visit BugBot documentation.

(In reply to Tom Schuster from comment #6)

Yes, I think this is expected based on our code CanUserGestureActivateTarget not allowing most combinations with special keys.

Just to be clear, pressing the keyboard modifier usually does work the first time, but will stop working until you interact with the page again (by like clicking somewhere in the page).

It's like the opening of the file dialog puts the "focus" of the window in some kind of weird state, but if you click in the DOM to force focus back, then the pressing the modifiers works again.

NOTE - Doing something like window.focus() does not fix the problem.

See Also: → 1944580
Severity: -- → S3
Component: Keyboard Navigation → DOM: Core & HTML
Depends on: 1641171
Product: Firefox → Core
Flags: needinfo?(dao+bmo)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: