Skip to content

Keyboard input stops responding after browser window loses and regains focus mid-game #20

Description

@woydarko

Bug Description

When the browser window loses focus during gameplay (e.g., alt-tabbing to another app) and then regains focus, all keyboard input stops being registered by the game. The player can see the game running but typing does nothing — no characters appear in the input field and no pests are defeated.

Steps to Reproduce

  1. Start the game on any stage
  2. While actively playing, press Alt+Tab to switch to another application
  3. Wait 2-3 seconds
  4. Alt+Tab back to the browser
  5. Try typing any word

Expected Behavior

Keyboard input should work normally immediately after the window regains focus. The game should re-attach or maintain its keydown event listeners regardless of focus changes.

Actual Behavior

Typing produces no response. The game loop appears to continue (pests still move) but the input field no longer captures keystrokes. The only fix is refreshing the page, which loses all progress.

Root Cause (suspected)

The keydown event listener may be attached to a DOM element that loses focus when the window is blurred. Instead of attaching to a specific element, the listener should be on window or document level to persist across focus changes.

Environment

  • Chrome 122 / Firefox 124
  • Windows 10 / macOS
  • Reproducible 100% of the time

Wallet: 0x964739472C587d24934c37BEbB405CeE36D59B24

Metadata

Metadata

Assignees

No one assigned

    Labels

    bounty-invalidBug report rejected by Scarab AI

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions