Skip to content

fix(desktop): honor click coordinates at 0 and validate lone coordinates - #2120

Open
yjjnls wants to merge 2 commits into
e2b-dev:mainfrom
yjjnls:fix/desktop-click-coordinates
Open

yjjnls wants to merge 2 commits into
e2b-dev:mainfrom
yjjnls:fix/desktop-click-coordinates

Conversation

@yjjnls

@yjjnls yjjnls commented Nov 11, 2026 •

Copy link
Copy Markdown

Problem

The desktop SDKs' click helpers cannot click at any position on an axis origin, and treat a half-specified position inconsistently.

0 coordinates are dropped. The move guard tested truthiness — JS if (x && y), Python if x and y: — so leftClick(0, 100) / left_click(0, 100) clicked at the current position instead of moving first. xdotool mousemove --sync 0 100 is a legitimate move; coordinates like (0, y), (x, 0), (0, 0) were unreachable through the click helpers.

Repro without a sandbox (stub commands.run and record what is issued):

const sandbox = Object.create(Sandbox.prototype)
const ran = []
sandbox.commands = { run: async (cmd) => { ran.push(cmd); return { stdout: '', exitCode: 0 } } }
await sandbox.leftClick(0, 100)
console.log(ran) // before: ['xdotool click 1'] — the move is gone

A lone coordinate is handled three different ways. leftClick(5), doubleClick(undefined, 7) and middleClick(5) silently skipped the move (and still clicked), while Python's right_click raised ValueError("Both x and y must be provided together"). With neither coordinate the click at the current position stays correct.

Python-only: right_click.__doc__ was None. Its docstring sat after the validation raise — a dead string expression, not a docstring — so docs tooling and help() showed nothing for the method.

Fix

  • Every click method (leftClick/left_click, doubleClick/double_click, rightClick/right_click, middleClick/middle_click) now moves whenever both coordinates are given, 0 included, and clicks at the current position when neither is.
  • Passing exactly one coordinate now raises the same both-or-neither error on all four methods in both SDKs, via a small shared guard (assertClickPosition / _check_click_position).
  • The Python right_click docstring moved above the guard, so __doc__ is populated again.

Testing

New offline tests drive the click methods against a stubbed commands client and assert the issued xdotool commands — no sandbox required:

  • packages/desktop-js/tests/clickCoordinates.test.ts (7 tests): origin-side move, no-coordinate click, per-method (0, 0) moves, lone-coordinate rejection.
  • packages/desktop-python/tests/test_click_coordinates.py (8 tests): same coverage plus a __doc__ regression check.

Both suites pass locally; tsc --noEmit, oxlint, prettier (JS) and ruff format/check (Python) are clean. The existing integration tests (tests/mouse.test.ts, tests/test_controls.py) run unchanged.

A changeset patches @e2b/desktop and @e2b/desktop-python.


Devin Review

The click helpers' move guard tested truthiness (JS `if (x && y)`,
Python `if x and y:`), so a target like leftClick(0, 100) or
rightClick(0, 0) clicked at the current position instead of moving:
coordinates on either axis origin were unreachable through the click
helpers. The guard now checks for undefined/None, so every fully
specified position is moved to.

Passing exactly one of x/y is now rejected on every click method in both
SDKs with the same 'Both x and y must be provided together' error.
Previously three of the four methods silently skipped the move, while
Python's right_click validated the pair — with its docstring placed
after the raise, which turned it into a dead string expression and left
__doc__ as None. The docstring now sits first, as on every other method.

Offline tests drive the click methods against a stubbed commands client
in both SDKs, asserting the issued xdotool commands.
@yjjnls
yjjnls requested a review from mishushakov as a code owner November 11, 2026 00:55
@cla-bot

cla-bot Bot commented Nov 11, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @yjjnls on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check'

@changeset-bot

changeset-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fdf9772

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@e2b/desktop Minor
@e2b/desktop-python Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T05:28:30.299478Z fdf9772 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devin-ai-integration devin-ai-integration Bot left a comment

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.

TASTE.md review. I checked the changed lines against parity (T-1, T-1c, T-2), API shape (T-3, T-3a), errors (T-59, T-62, T-63) and docstrings (T-69, T-70, T-71).

3 violations, 4 inline comments:

  • T-59 / T-63 (JS + Python): the new both-or-neither guard throws a bare Error / ValueError. It should use InvalidArgumentError / InvalidArgumentException with a message that shows the correct call.
  • T-62 / T-69 / T-70 (JS): the click methods' JSDoc doesn't document x/y or the new throw.
  • T-62 / T-69 (Python): the new docstrings don't say when the methods raise.

Not tied to a line:

  • The Python unit test asserts pytest.raises(ValueError). It needs updating if the exception class changes.
  • Parity is good: JS and Python now behave the same, and the desktop package has no async Python mirror to update (T-2 doesn't apply).
  • I didn't flag the existing x?, y? optional positionals (T-3 / T-3a) because this PR doesn't introduce them.

Written by Devin

Comment thread packages/desktop-js/src/sandbox.ts Outdated
*/
private assertClickPosition(x?: number, y?: number): void {
if ((x === undefined) !== (y === undefined)) {
throw new Error('Both x and y must be provided together')

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.

T-59 — argument validation that runs before any operation starts throws InvalidArgumentError, not a bare Error (also keeps the error class in parity with Python per T-1c). T-63 — a misuse error should show the correct call rather than only restate the constraint.

InvalidArgumentError is exported from e2b; add it to the import block at the top of the file (outside this diff).

Suggested change
throw new Error('Both x and y must be provided together')
throw new InvalidArgumentError(
'Pass both `x` and `y` to click at a position, or neither to click at the current cursor position.'
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in fdf9772 — all four click methods now throw InvalidArgumentError imported from e2b, using the suggested message that shows the correct call; the JS/Python tests assert the new error class and message.

@@ -281,7 +281,9 @@ export class Sandbox extends SandboxBase {
* Left click on the mouse position.

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.

T-69 / T-70 / T-62 — public methods document their parameters and failure modes with JSDoc @param / @throws. This PR adds a new throw path to all four click methods and documents the params on the Python side, but the JS JSDoc still says nothing about x/y or when it throws. Same fix applies to doubleClick, rightClick, and middleClick.

Suggested change
* Left click on the mouse position.
* Left click on the mouse position.
*
* @param x - The x coordinate to click at. Must be passed together with `y`.
* @param y - The y coordinate to click at. Must be passed together with `x`.
* @throws {InvalidArgumentError} If only one of `x` and `y` is passed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in fdf9772 — all four JS click methods now document @param x / @param y and @throws {InvalidArgumentError} for the both-or-neither validation.

position to move to, and silently skipping the move hides the mistake.
"""
if (x is None) != (y is None):
raise ValueError("Both x and y must be provided together")

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.

T-59 — argument validation that runs before any operation starts raises InvalidArgumentException, not a bare ValueError (parity with JS InvalidArgumentError, T-1c). T-63 — a misuse error should show the correct call.

Import InvalidArgumentException from e2b in the existing import block (outside this diff), and update test_single_coordinate_is_rejected to pytest.raises(InvalidArgumentException) — it is not a ValueError subclass.

Suggested change
raise ValueError("Both x and y must be provided together")
raise InvalidArgumentException(
"Pass both `x` and `y` to click at a position, or neither to click at the current cursor position."
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in fdf9772 — the click methods now raise InvalidArgumentException imported from e2b, and test_single_coordinate_is_rejected asserts pytest.raises(InvalidArgumentException).

Left click on the mouse position.

:param x: The x coordinate to click at, together with `y`
:param y: The y coordinate to click at, together with `x`

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.

T-62 / T-69 — document when an error is thrown. The new both-or-neither raise is a failure mode of every click method, but the docstrings only list :param: fields. Same fix applies to double_click, right_click, and middle_click.

Suggested change
:param y: The y coordinate to click at, together with `x`
:param y: The y coordinate to click at, together with `x`
:raises InvalidArgumentException: If only one of `x` and `y` is passed

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in fdf9772 — all four Python click methods now document :raises InvalidArgumentException: for the both-or-neither validation.

devin-ai-integration[bot]

This comment was marked as resolved.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aeba132cf6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread .changeset/desktop-click-coordinates.md Outdated
Comment on lines +2 to +3
'@e2b/desktop': patch
'@e2b/desktop-python': patch

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Mark the coordinate-validation releases as minor

When an existing caller supplies only x or only y, these methods previously still performed the click (for every JS method and Python left/double/middle) but now reject the promise or raise, even though the public signatures permit either optional argument. Publishing both packages as a patch therefore exposes consumers to a new runtime failure on a patch upgrade; mark these changesets as minor as required for breaking changes.

AGENTS.md reference: AGENTS.md:L7-L7

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in fdf9772 — both changesets now declare minor releases with the breaking-change rationale (single-coordinate calls previously performed the click and now reject), so consumers are not exposed to the new failure on a patch upgrade.

@yjjnls

yjjnls commented Nov 11, 2026

Copy link
Copy Markdown
Author

Tracked in #2122.

…DK validation errors

Review findings:

- The changesets move from patch to minor: rejecting a lone coordinate
  turns calls that previously clicked (three of the four methods) into
  errors, which is a breaking change.
- The both-or-neither guard now throws InvalidArgumentError (JS) /
  InvalidArgumentException (Python) — the SDKs' argument-validation
  errors — instead of a bare Error / ValueError, with a message that
  states the correct call.
- All four click methods document the x/y parameters and the raise via
  JSDoc / :raises:, and the Python test asserts the new exception class.
@cla-bot

cla-bot Bot commented Nov 11, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @yjjnls on file. You can sign our CLA at https://e2b.dev/docs/cla . Once you've signed, post a comment here that says '@cla-bot check'

@yjjnls

yjjnls commented Nov 11, 2026

Copy link
Copy Markdown
Author

All findings addressed in fdf9772:

  • Changeset → minor (both packages) — agreed: callers passing a lone coordinate previously got a click (three of the four methods silently skipped the move) and now get an error, which is a breaking change. It ships as minor and is called out in the changeset text.
  • InvalidArgumentError / InvalidArgumentException — the both-or-neither guard now throws the SDKs' argument-validation errors (imported from e2b), with a message that states the correct call: "Pass both x and y to click at a position, or neither to click at the current cursor position."
  • Docs — all four click methods document x/y and the throw (@param + @throws {InvalidArgumentError} in JS, :param: + :raises InvalidArgumentException: in Python).
  • Test — test_single_coordinate_is_rejected now asserts InvalidArgumentException, and the JS test asserts the new message.

Desktop JS and Python remain in parity; offline suites pass in both packages.

@yjjnls

yjjnls commented Nov 11, 2026

Copy link
Copy Markdown
Author

@cla-bot check

@cla-bot cla-bot Bot added the cla-signed label Nov 11, 2026
@cla-bot

cla-bot Bot commented Nov 11, 2026

Copy link
Copy Markdown

The cla-bot has been summoned, and re-checked this pull request!

@yjjnls

yjjnls commented Nov 11, 2026

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: fdf977222c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@yjjnls

yjjnls commented Nov 20, 2026

Copy link
Copy Markdown
Author

Friendly nudge — this PR is still open and awaiting review. All review feedback is addressed in fdf9772 (codex's latest pass on that commit came back clean), including the minor-level changesets and the InvalidArgumentError handling. Happy to provide more context or make any further adjustments if useful.

@yjjnls

yjjnls commented Nov 27, 2026

Copy link
Copy Markdown
Author

Just a gentle follow-up on the click-coordinate fix — still open and happy to iterate on any feedback. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant