Skip to content

updated the description of gamepad documentation#43760

Merged
chrisdavidmills merged 3 commits intomdn:mainfrom
narasimhan-lakshmi:fix/gamepad-api-docs
Apr 13, 2026
Merged

updated the description of gamepad documentation#43760
chrisdavidmills merged 3 commits intomdn:mainfrom
narasimhan-lakshmi:fix/gamepad-api-docs

Conversation

@narasimhan-lakshmi
Copy link
Copy Markdown
Contributor

Description

Removed wording that implied a Gamepad object from gamepadconnected can be safely held and continuously queried.
Updated guidance to use gamepad index as the stable identifier and call navigator.getGamepads() each frame for fresh state.
Adjusted the sample code to track connected controllers by index/state instead of storing the original event Gamepad object.

Motivation

Makes the reader to understand better.

Additional details

Related issues and pull requests

Fixes #14874

@narasimhan-lakshmi narasimhan-lakshmi requested a review from a team as a code owner April 13, 2026 07:06
@narasimhan-lakshmi narasimhan-lakshmi requested review from chrisdavidmills and removed request for a team April 13, 2026 07:06
@github-actions github-actions bot added Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed labels Apr 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Preview URLs (1 page)

(comment last updated: 2026-04-13 08:31:57)

Copy link
Copy Markdown
Contributor

@chrisdavidmills chrisdavidmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @narasimhan-lakshmi! I have a few comments for you to consider, but this is looking mostly good.

Comment thread files/en-us/web/api/gamepad_api/using_the_gamepad_api/index.md Outdated
Comment thread files/en-us/web/api/gamepad_api/using_the_gamepad_api/index.md Outdated

> [!NOTE]
> The Gamepad object is available on the {{ domxref("Window/gamepadconnected_event", "gamepadconnected") }} event rather than the {{ domxref("Window") }} object itself, for security reasons. Once we have a reference to it, we can query its properties for information about the current state of the gamepad. Behind the scenes, this object will be updated every time the gamepad's state changes.
> The Gamepad object is available on the {{ domxref("Window/gamepadconnected_event", "gamepadconnected") }} event rather than the {{ domxref("Window") }} object itself, for security reasons. You can also access gamepads through {{domxref("Navigator.getGamepads()")}}. In practice, poll {{domxref("Navigator.getGamepads()")}} and read the current object for a known `index` each frame, instead of relying on a long-lived reference from an earlier event.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> The Gamepad object is available on the {{ domxref("Window/gamepadconnected_event", "gamepadconnected") }} event rather than the {{ domxref("Window") }} object itself, for security reasons. You can also access gamepads through {{domxref("Navigator.getGamepads()")}}. In practice, poll {{domxref("Navigator.getGamepads()")}} and read the current object for a known `index` each frame, instead of relying on a long-lived reference from an earlier event.
> The Gamepad object is available on the {{ domxref("Window/gamepadconnected_event", "gamepadconnected") }} event rather than the {{ domxref("Window") }} object itself, for security reasons. You can also access gamepads through {{domxref("Navigator.getGamepads()")}}. In practice, you should poll {{domxref("Navigator.getGamepads()")}} and read the current object for a known `index` each frame, rather than relying on a long-lived reference from an earlier event.

Comment thread files/en-us/web/api/gamepad_api/using_the_gamepad_api/index.md Outdated
@narasimhan-lakshmi
Copy link
Copy Markdown
Contributor Author

Hello @chrisdavidmills, have made the suggested changes. Kindly review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@chrisdavidmills chrisdavidmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Thanks for the fix, @narasimhan-lakshmi!

@chrisdavidmills chrisdavidmills merged commit 7cd5816 into mdn:main Apr 13, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Double checking the gamepad docs are correct

3 participants