Skip to content

Commit

Permalink
Merge branch 'main' into fix-adjust-rollup-error
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Nov 11, 2024
2 parents 891e469 + 07c19b8 commit 4a028e1
Show file tree
Hide file tree
Showing 24 changed files with 1,793 additions and 1,218 deletions.
23 changes: 19 additions & 4 deletions packages/browser/src/node/commands/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export const keyboardCleanup: UserEventCommand<(state: KeyboardState) => Promise
}
}

// fallback to insertText for non US key
// https://github.com/microsoft/playwright/blob/50775698ae13642742f2a1e8983d1d686d7f192d/packages/playwright-core/src/server/input.ts#L95
const VALID_KEYS = new Set(['Escape', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'Backquote', '`', '~', 'Digit1', '1', '!', 'Digit2', '2', '@', 'Digit3', '3', '#', 'Digit4', '4', '$', 'Digit5', '5', '%', 'Digit6', '6', '^', 'Digit7', '7', '&', 'Digit8', '8', '*', 'Digit9', '9', '(', 'Digit0', '0', ')', 'Minus', '-', '_', 'Equal', '=', '+', 'Backslash', '\\', '|', 'Backspace', 'Tab', 'KeyQ', 'q', 'Q', 'KeyW', 'w', 'W', 'KeyE', 'e', 'E', 'KeyR', 'r', 'R', 'KeyT', 't', 'T', 'KeyY', 'y', 'Y', 'KeyU', 'u', 'U', 'KeyI', 'i', 'I', 'KeyO', 'o', 'O', 'KeyP', 'p', 'P', 'BracketLeft', '[', '{', 'BracketRight', ']', '}', 'CapsLock', 'KeyA', 'a', 'A', 'KeyS', 's', 'S', 'KeyD', 'd', 'D', 'KeyF', 'f', 'F', 'KeyG', 'g', 'G', 'KeyH', 'h', 'H', 'KeyJ', 'j', 'J', 'KeyK', 'k', 'K', 'KeyL', 'l', 'L', 'Semicolon', ';', ':', 'Quote', '\'', '"', 'Enter', '\n', '\r', 'ShiftLeft', 'Shift', 'KeyZ', 'z', 'Z', 'KeyX', 'x', 'X', 'KeyC', 'c', 'C', 'KeyV', 'v', 'V', 'KeyB', 'b', 'B', 'KeyN', 'n', 'N', 'KeyM', 'm', 'M', 'Comma', ',', '<', 'Period', '.', '>', 'Slash', '/', '?', 'ShiftRight', 'ControlLeft', 'Control', 'MetaLeft', 'Meta', 'AltLeft', 'Alt', 'Space', ' ', 'AltRight', 'AltGraph', 'MetaRight', 'ContextMenu', 'ControlRight', 'PrintScreen', 'ScrollLock', 'Pause', 'PageUp', 'PageDown', 'Insert', 'Delete', 'Home', 'End', 'ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown', 'NumLock', 'NumpadDivide', 'NumpadMultiply', 'NumpadSubtract', 'Numpad7', 'Numpad8', 'Numpad9', 'Numpad4', 'Numpad5', 'Numpad6', 'NumpadAdd', 'Numpad1', 'Numpad2', 'Numpad3', 'Numpad0', 'NumpadDecimal', 'NumpadEnter'])

export async function keyboardImplementation(
pressed: Set<string>,
provider: BrowserProvider,
Expand All @@ -91,7 +95,9 @@ export async function keyboardImplementation(
// together, and call `type` once for all non special keys,
// and then `press` for special keys
if (pressed.has(key)) {
await page.keyboard.up(key)
if (VALID_KEYS.has(key)) {
await page.keyboard.up(key)
}
pressed.delete(key)
}

Expand All @@ -102,11 +108,18 @@ export async function keyboardImplementation(
}

for (let i = 1; i <= repeat; i++) {
await page.keyboard.down(key)
if (VALID_KEYS.has(key)) {
await page.keyboard.down(key)
}
else {
await page.keyboard.insertText(key)
}
}

if (releaseSelf) {
await page.keyboard.up(key)
if (VALID_KEYS.has(key)) {
await page.keyboard.up(key)
}
}
else {
pressed.add(key)
Expand All @@ -116,7 +129,9 @@ export async function keyboardImplementation(

if (!skipRelease && pressed.size) {
for (const key of pressed) {
await page.keyboard.up(key)
if (VALID_KEYS.has(key)) {
await page.keyboard.up(key)
}
}
}
}
Expand Down
Loading

0 comments on commit 4a028e1

Please sign in to comment.