Mintplex-Labs/anything-llm · error

key requires argument (e.g. Enter, Tab, Escape)

Error message

key requires <key> argument (e.g. Enter, Tab, Escape)

What it means

cdp-input argument validation for action 'key': argv[3] must be a non-empty key name; it is looked up in the specialKeys table (Enter, Tab, Escape, etc.) and otherwise synthesized as key `Key${uppercase}` with code for Input.dispatchKeyEvent keyDown/keyUp. Missing/empty key aborts before dispatch.

Solutions

  1. Pass a recognized key name: node cdp-input.js key Enter [tabFilter] (Enter, Tab, Escape, Backspace, etc.)
  2. Quote arguments from variables in calling scripts and default sensibly: "${KEY:-Enter}"
  3. For single printable characters use the type action instead of key

Example fix

# before
node cdp-input.js key            # missing key name
# after
node cdp-input.js key Enter
# scripted:
node cdp-input.js key "${KEY_NAME:-Enter}"
Defensive patterns

Strategy: validation

Validate before calling

const KEY = process.argv[3];
const KNOWN = new Set(['Enter','Tab','Escape','Backspace','Delete','ArrowUp','ArrowDown','ArrowLeft','ArrowRight','Home','End','PageUp','PageDown']);
if (!KEY || KEY.length === 0) { console.error('usage: cdp-input.js key <key> [tabFilter]'); process.exit(2); }
if (!KNOWN.has(KEY)) console.warn(`unrecognized key '${KEY}' — synthesized as Key${KEY.toUpperCase()}`);

Type guard

function isSpecialKey(k: unknown): k is 'Enter'|'Tab'|'Escape'|'Backspace' { return ['Enter','Tab','Escape','Backspace'].includes(k as string); }

Try / catch

try { await sendInput('key', keyName); } catch (e) { if (/key requires <key> argument/.test(e.message)) { /* caller bug: supply the key name */ } else throw e; }

Prevention

When it happens

Trigger: Running `node cdp-input.js key` with no argument; passing an unquoted empty shell variable; passing the tab filter but forgetting the key itself.

Common situations: Automated presses built from variables that are undefined; users assuming 'key' with no arg presses Enter; casing/spacing mistakes that still pass validation but produce a wrong code (e.g. 'KeyENTER' -> 'KeyKEYENTER').

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/e1a32eae646143c1. Report an issue: GitHub.

Appendix: source

Thrown at open-computer/services/interface-service/utils/cdp-input.js:175

          key: char,
          code: charToCode(char),
          unmodifiedText: char,
        }, sessionId);

        await cdpSend(ws, "Input.dispatchKeyEvent", {
          type: "keyUp",
          key: char,
          code: charToCode(char),
        }, sessionId);

        await sleep(keystrokeDelay());
      }

      process.stdout.write(`typed ${text.length} chars`);

    } else if (action === "key") {
      const key = process.argv[3];
      if (!key) throw new Error("key requires <key> argument (e.g. Enter, Tab, Escape)");

      const keyDef = specialKeys[key] || { key, code: `Key${key.toUpperCase()}` };

      await cdpSend(ws, "Input.dispatchKeyEvent", {
        type: "keyDown",
        key: keyDef.key,
        code: keyDef.code,
        windowsVirtualKeyCode: keyDef.keyCode || 0,
        nativeVirtualKeyCode: keyDef.keyCode || 0,
      }, sessionId);
      await sleep(50);

      await cdpSend(ws, "Input.dispatchKeyEvent", {
        type: "keyUp",
        key: keyDef.key,
        code: keyDef.code,
        windowsVirtualKeyCode: keyDef.keyCode || 0,
        nativeVirtualKeyCode: keyDef.keyCode || 0,

View on GitHub (pinned to 3aec848f28)