Repository navigation
fix(agent-monitor): do not call addEventListener where window has none - #430
Merged
omercnet merged 2 commits intoOct 29, 2026
Merged
Conversation
…e (Android) React Native defines a window object without addEventListener. useKeyDown assumed any window object could listen and threw 'undefined is not a function', which failed the whole plugin on Android. Use window only if it has addEventListener and removeEventListener. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Android the whole agent-monitor plugin failed to load. React Native defines a
windowobject, but it has noaddEventListener.useKeyDownonly checked thatglobalThis.windowwas an object, so it called a missing function and threwundefined is not a functionduring the contribution, which took the plugin down on Android.Change
Use the
windowobject only when it actually exposes bothaddEventListenerandremoveEventListener, so React Native's barewindowis skipped (the keyboard listener is a web and desktop feature anyway) and cleanup cannot throw either.Testing
tests/web-keys.test.ts: awindowobject with no listener methods does not throw, and one with onlyaddEventListeneris not used.bun run test: 117 green.bun run test:coverage: 96.53 lines / 93.33 functions.tscandbiomeclean.Note: this text was produced with AI assistance, and the fix was reproduced, applied and verified on the device by the author.
Summary by CodeRabbit