w3c / webdriver

Remote control interface that enables introspection and control of user agents.
https://w3c.github.io/webdriver/
Other
676 stars 190 forks source link

Keyboard Layouts in Webdriver #1743

Open jrandolf opened 1 year ago

jrandolf commented 1 year ago

This issues discusses several solutions to keyboard layouts in WebDriver.

Background

While working on keyboard inputs in Chromium, several reviewers brought up keyboard layout and questioned why webdriver assumes a US layout. For the most part, they were primarily concerned with shortcuts that certain keyboard combinations would trigger (although in webdriver, events are emitted on the page, not at the browser level), but nonetheless confused by the assumption.

Problem

With the current specification, the code property of KeyboardEvents only works for US users and developers cannot test for international keyboard layouts.

Requirements

When coming up with solutions, the following requirements were imagined:

Solutions

Native keyboard layouts

Within Chromium, we have code that can gather information about the current keyboard layout on the device it runs on. This can be used to get the current code. (I assume this is also the case with Firefox and Safari).

Pros

Cons

Keyboard layout registry

We can add another API that handles registering keyboard layouts with a default to US.

Pros

Cons

code value (recommended)

We can add an additional, optional code parameter to the key action object which is a KeyboardEvent code value specified in https://www.w3.org/TR/uievents-code/. It would default to the US layout.

This change would also require a slight modification of the dispatching mechanism; specifically, we should add the code and key to an input source's pressed state rather than just the key. Alternatively, we can store the code to mimic a real keyboard instead of key.

Pros

References

CC: @gsnedders, @jgraham, @whimboo