Skip to content

feat: detect unfocused element before type() and pressKey()#5500

Merged
DavertMik merged 3 commits into4.xfrom
feat/focus-check-type
Mar 31, 2026
Merged

feat: detect unfocused element before type() and pressKey()#5500
DavertMik merged 3 commits into4.xfrom
feat/focus-check-type

Conversation

@DavertMik
Copy link
Copy Markdown
Contributor

@DavertMik DavertMik commented Mar 31, 2026

Summary

  • type() and pressKey() use page.keyboard which silently drops keystrokes when no element has focus. This adds shared focus checks in lib/helper/extras/focusCheck.js:
    • type(): always checks focus before typing
    • pressKey(): checks focus only for editing combos: Ctrl/Meta + A, C, X, V, Z, Y (handles CommandOrControlMeta on macOS)
    • Debug mode: logs a warning via debugSection
    • Strict mode (strict: true): throws NonFocusedType error with actionable message
  • Applied to all three helpers: Playwright, Puppeteer, WebDriver
  • Handles <body contenteditable> (full-page editors) — no false positive
  • Navigation keys (Escape, Tab, Enter, arrows) are never flagged

Test plan

  • Strict mode throws NonFocusedType when typing without focus
  • Strict mode allows typing when element is focused
  • Strict mode throws NonFocusedType for Ctrl+A without focus
  • Escape without focus does not throw
  • Ctrl+A with focused element does not throw
  • Existing acceptance tests pass (61 passed)

🤖 Generated with Claude Code

DavertMik and others added 2 commits March 31, 2026 12:01
…ent is focused

type() sends keystrokes via page.keyboard which silently drops input when no
element has focus. Add a shared checkFocusBeforeType() that warns in debug mode
and throws NonFocusedType in strict mode. Applied to Playwright, Puppeteer, and
WebDriver helpers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
NonFocusedType now accepts message from caller. checkFocusBeforePressKey()
warns/throws only for editing key combos (Ctrl/Meta + A/C/X/V/Z/Y), not
for navigation keys like Escape or Tab.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DavertMik DavertMik changed the title feat: detect unfocused element before type() feat: detect unfocused element before type() and pressKey() Mar 31, 2026
WebDriver's getNormalizedKey converts key names to Unicode code points,
so checking after normalization misses the modifier. Now check the
original user-provided key array before any normalization happens.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@DavertMik DavertMik merged commit c5572aa into 4.x Mar 31, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant