Skip to content

Commit

Permalink
Improve WebDriver BiDi key codes (#34286)
Browse files Browse the repository at this point in the history
  • Loading branch information
whimboo authored Jan 10, 2025
1 parent a2e2dfd commit 8917217
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/bidi/bidiInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class RawKeyboardImpl implements input.RawKeyboard {

async keyup(modifiers: Set<types.KeyboardModifier>, code: string, keyCode: number, keyCodeWithoutLocation: number, key: string, location: number): Promise<void> {
const actions: bidi.Input.KeySourceAction[] = [];
actions.push({ type: 'keyUp', value: getBidiKeyValue(key) });
actions.push({ type: 'keyUp', value: getBidiKeyValue(code) });
await this._performActions(actions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

/* eslint-disable curly */

export const getBidiKeyValue = (key: string) => {
switch (key) {
export const getBidiKeyValue = (code: string) => {
switch (code) {
case '\r':
case '\n':
key = 'Enter';
code = 'Enter';
break;
}
// Measures the number of code points rather than UTF-16 code units.
if ([...key].length === 1) {
return key;
if ([...code].length === 1) {
return code;
}
switch (key) {
switch (code) {
case 'Cancel':
return '\uE001';
case 'Help':
Expand Down Expand Up @@ -131,6 +131,8 @@ export const getBidiKeyValue = (key: string) => {
return '\uE052';
case 'MetaRight':
return '\uE053';
case 'Space':
return ' ';
case 'Digit0':
return '0';
case 'Digit1':
Expand Down Expand Up @@ -226,6 +228,6 @@ export const getBidiKeyValue = (key: string) => {
case 'Quote':
return '"';
default:
throw new Error(`Unknown key: "${key}"`);
throw new Error(`Unknown key: "${code}"`);
}
};

0 comments on commit 8917217

Please sign in to comment.