Skip to content

The fastest browser for AI agents to run browser automation, built for sharing your logged-in browser state with your AI agents, like Codex or Claude Code, without disturbing you. Zero cost, zero config.

fix: accept case-insensitive keyboard modifiers

Aute5858735f6a9f
diff --git a/docs/runtime-v2-architecture.md b/docs/runtime-v2-architecture.md
index b1591ed..bce6a95 100644
--- a/docs/runtime-v2-architecture.md
+++ b/docs/runtime-v2-architecture.md
@@ -388,6 +388,10 @@ popup 回执:
这些方法在输入完成后 resolve `undefined`。它们产生的延迟 popup 仍可由统一
盘点收编。
+键盘 modifier 名称 `Alt`、`Control`、`Meta`、`Shift` 和 `ControlOrMeta` 不区分
+大小写;普通键名仍使用 Playwright 的大小写约定。跨平台快捷键优先使用
+`ControlOrMeta`。
+
### 7.3 Snapshot
原生 snapshot 只能观察当前激活页,因此 `page.snapshot()` 在 gate 内先激活
diff --git a/package/ego-browser/scripts/real-browser-e2e/cases/page-keyboard.mjs b/package/ego-browser/scripts/real-browser-e2e/cases/page-keyboard.mjs
index 7823ee2..b7000c0 100644
--- a/package/ego-browser/scripts/real-browser-e2e/cases/page-keyboard.mjs
+++ b/package/ego-browser/scripts/real-browser-e2e/cases/page-keyboard.mjs
@@ -18,6 +18,9 @@ export function pageKeyboardInterfaceCase() {
code: event.code ?? null,
location: event.location ?? null,
repeat: event.repeat ?? false,
+ altKey: event.altKey ?? false,
+ ctrlKey: event.ctrlKey ?? false,
+ metaKey: event.metaKey ?? false,
shiftKey: event.shiftKey ?? false,
data: event.data ?? null,
trusted: event.isTrusted,
@@ -86,6 +89,36 @@ export function pageKeyboardInterfaceCase() {
assertEqual(repeatedA[1].repeat, true, "a second down without up is a repeat");
assertEqual(repeatedA[0].shiftKey, true, "held Shift modifies following keys");
+ await page.evaluate(() => {
+ const input = document.querySelector("#text-area");
+ input.value = "abcdef";
+ input.focus();
+ input.setSelectionRange(input.value.length, input.value.length);
+ window.__pageKeyboardContractEvents = [];
+ });
+ await page.keyboard.press(process.platform === "darwin" ? "META+A" : "CONTROL+A");
+ const uppercaseModifierState = await page.evaluate(() => ({
+ start: document.querySelector("#text-area").selectionStart,
+ end: document.querySelector("#text-area").selectionEnd,
+ keyA: window.__pageKeyboardContractEvents.find(
+ (event) => event.type === "keydown" && event.code === "KeyA",
+ ),
+ }));
+ assertEqual(uppercaseModifierState.start, 0, "uppercase modifier selects from the start");
+ assertEqual(uppercaseModifierState.end, 6, "uppercase modifier selects through the end");
+ assertEqual(
+ process.platform === "darwin"
+ ? uppercaseModifierState.keyA.metaKey
+ : uppercaseModifierState.keyA.ctrlKey,
+ true,
+ "uppercase modifier produces the native platform shortcut",
+ );
+ assertEqual(
+ uppercaseModifierState.keyA.trusted,
+ true,
+ "uppercase modifier keeps the shortcut trusted",
+ );
+
await page.keyboard.press("ControlOrMeta+A");
await page.keyboard.type("replaced");
await page.keyboard.press("ArrowLeft");
diff --git a/package/ego-browser/src/driver/page-keyboard.ts b/package/ego-browser/src/driver/page-keyboard.ts
index ff46d04..27c8ab1 100644
--- a/package/ego-browser/src/driver/page-keyboard.ts
+++ b/package/ego-browser/src/driver/page-keyboard.ts
@@ -39,6 +39,13 @@ type LayoutEntry = {
const KEYPAD_LOCATION = 3;
const MODIFIER_NAMES = ["Alt", "Control", "Meta", "Shift"] as const;
+const MODIFIER_ALIASES = new Map<string, string>([
+ ["alt", "Alt"],
+ ["control", "Control"],
+ ["meta", "Meta"],
+ ["shift", "Shift"],
+ ["controlormeta", "ControlOrMeta"],
+]);
const MODIFIER_MASKS: Record<(typeof MODIFIER_NAMES)[number], number> = {
Alt: 1,
Control: 2,
@@ -225,10 +232,13 @@ function resolveSmartModifier(
key: string,
platform: string = process.platform,
): string {
- if (key === "ControlOrMeta") {
+ // Modifier names are forgiving because agents often use protocol-style
+ // uppercase constants. Ordinary key names remain case-sensitive.
+ const normalized = MODIFIER_ALIASES.get(key.toLowerCase()) ?? key;
+ if (normalized === "ControlOrMeta") {
return platform === "darwin" ? "Meta" : "Control";
}
- return key;
+ return normalized;
}
function keyDefinitionForString(input: string, shift: boolean): KeyDefinition {
diff --git a/package/ego-browser/src/page-model.test.mjs b/package/ego-browser/src/page-model.test.mjs
index 0e5e0ea..c5fcea6 100644
--- a/package/ego-browser/src/page-model.test.mjs
+++ b/package/ego-browser/src/page-model.test.mjs
@@ -1559,6 +1559,29 @@ test("Page keyboard maps portable editing shortcuts on macOS", async () => {
});
});
+test("Page keyboard accepts case-insensitive modifier names", async () => {
+ await withFixture(async (fixture) => {
+ const task = taskForRound(fixture, "round-a", { platform: "darwin" });
+ const page = await task.openPage("https://example.test/first");
+
+ await page.keyboard.press("ALT+CONTROL+META+SHIFT+A");
+ await page.keyboard.press("CONTROLORMETA+A");
+
+ const aDowns = fixture.calls
+ .filter(
+ ([kind, method, params]) =>
+ kind === "cdp" &&
+ method === "Input.dispatchKeyEvent" &&
+ params.type === "rawKeyDown" &&
+ params.code === "KeyA",
+ )
+ .map(([, , params]) => params);
+ assert.equal(aDowns[0].modifiers, 15);
+ assert.equal(aDowns[1].modifiers, 4);
+ assert.deepEqual(aDowns[1].commands, ["selectAll"]);
+ });
+});
+
test("Page keyboard maps portable editing shortcuts on Windows", async () => {
await withFixture(async (fixture) => {
const task = taskForRound(fixture, "round-a", { platform: "win32" });
diff --git a/skills/ego-browser/SKILL.md b/skills/ego-browser/SKILL.md
index 7311609..49c5dcc 100644
--- a/skills/ego-browser/SKILL.md
+++ b/skills/ego-browser/SKILL.md
@@ -300,7 +300,10 @@ await page.keyboard.type(text, { delay });
await page.keyboard.insertText(text);
```
-Keyboard key names and `+`-separated chords follow Playwright syntax. Use `ControlOrMeta` for portable shortcuts.
+Keyboard key names and `+`-separated chords follow Playwright syntax. Modifier
+names (`Alt`, `Control`, `Meta`, `Shift`, and `ControlOrMeta`) are
+case-insensitive; other key names remain case-sensitive. Use `ControlOrMeta`
+for portable shortcuts.
Low-level `mouse.move/down/up/wheel`, `keyboard.down/up/type/insertText`, and `scrollBy()` do not return an action receipt; verify their effect explicitly.