Skip to content

Conversation

@RohitR311
Copy link
Contributor

@RohitR311 RohitR311 commented Sep 2, 2025

What this PR does?

Fixes the issue wherein the user cursor clicks between characters were not being registered when performing keyboard actions. This was leading to wrong data being input.

2025-09-03.00-28-46.mov

Summary by CodeRabbit

  • New Features

    • Adds precise, coordinate-based clicking inside input and textarea fields for more accurate interactions and recording.
    • Extends recorder to handle textarea elements the same way as inputs.
  • Bug Fixes

    • Improves click targeting within form fields, reducing misclicks and focusing issues, especially in embedded views.
  • Performance

    • Skips unnecessary DOM snapshots after clicking into inputs/textareas, resulting in smoother, faster typing during playback and recording.

@coderabbitai
Copy link

coderabbitai bot commented Sep 2, 2025

Walkthrough

Adds element-relative click handling for INPUT/TEXTAREA: the renderer emits relative coordinates, and the server clicks at element-local offsets using bounding boxes. On successful input/textarea clicks, the server skips DOM snapshot generation. Non-input clicks and general behavior remain unchanged; SELECT handling is unaffected in this branch.

Changes

Cohort / File(s) Summary
Server: Coordinate-aware input clicks
server/src/browser-management/inputHandlers.ts
Adds click path for INPUT/TEXTAREA using element boundingBox plus relative coordinates; falls back to page.click on errors or missing data; early-returns to skip DOM snapshot after input/textarea click.
Recorder UI: Emit relative coords for inputs
src/components/recorder/DOMBrowserRenderer.tsx
Computes element-relative coordinates for INPUT/TEXTAREA and emits dom:click with isSPA=false; retains absolute-coords path for other elements; excludes SELECT in this branch (handled elsewhere).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant R as DOMBrowserRenderer
  participant S as Server inputHandlers
  participant P as Page/Browser

  U->>R: Click in iframe
  alt Target is INPUT/TEXTAREA
    R->>S: dom:click(target=INPUT/TEXTAREA, coords=relative)
    S->>P: locate element by selector/handle
    alt boundingBox available
      S->>P: mouse.click(bbox.x + rel.x, bbox.y + rel.y)
      Note right of S: Skip DOM snapshot (early return)
    else Fallback
      S->>P: page.click(selector)
      Note over S,P: Warning logged on error path
    end
  else Other elements (non-SELECT)
    R->>S: dom:click(coords=absolute)
    S->>P: page.click(selector or coords)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Type: Bug, Scope: Recorder

Suggested reviewers

  • amhsirak

Poem

A tap on keys, a hop of light,
I click just so—precise and right.
Bounding boxes, coords in tow,
I nudge the form and swiftly go.
No snapshot pause, I’m on my way—
A happy hare, recording play. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/components/recorder/DOMBrowserRenderer.tsx (1)

575-589: Element-relative clicks for inputs/textareas look good; clamp and fallback for robustness

Great fix. To harden against fractional/negative offsets and degenerate rects, clamp to the element box and fallback to absolute coords if bbox is 0×0.

-            const element = target as HTMLElement;
-            const elementRect = element.getBoundingClientRect();
-            const relativeX = iframeX - elementRect.left;
-            const relativeY = iframeY - elementRect.top;
+            const element = target as HTMLElement;
+            const { left, top, width, height } = element.getBoundingClientRect();
+            let relativeX = iframeX - left;
+            let relativeY = iframeY - top;
+            if (width > 0 && height > 0) {
+              relativeX = Math.max(0, Math.min(relativeX, width - 1));
+              relativeY = Math.max(0, Math.min(relativeY, height - 1));
+            } else {
+              // Fallback to iframe coordinates if the rect is not usable
+              socket.emit("dom:click", {
+                selector,
+                url: snapshot.baseUrl,
+                userId: user?.id || "unknown",
+                elementInfo,
+                coordinates: { x: iframeX, y: iframeY },
+                isSPA: false,
+              });
+              return;
+            }
server/src/browser-management/inputHandlers.ts (2)

639-661: Prefer elementHandle.click({ position }) to honor element-local offsets and auto-scroll

Current approach works, but using ElementHandle.click with a position lets Playwright handle scrolling/occlusion and avoids manual page.mouse math. Optionally clamp when bbox is available.

-      try {
-        const elementHandle = await page.$(selector);
-        if (elementHandle) {
-          const boundingBox = await elementHandle.boundingBox();
-          if (boundingBox) {
-            await page.mouse.click(
-              boundingBox.x + coordinates.x, 
-              boundingBox.y + coordinates.y
-            );
-          } else {
-            await page.click(selector);
-          }
-        } else {
-          await page.click(selector);
-        }
-      } catch (error: any) {
+      try {
+        const elementHandle = await page.$(selector);
+        if (elementHandle) {
+          const bbox = await elementHandle.boundingBox();
+          const pos = bbox
+            ? {
+                x: Math.max(0, Math.min(coordinates.x, Math.max(0, bbox.width - 1))),
+                y: Math.max(0, Math.min(coordinates.y, Math.max(0, bbox.height - 1))),
+              }
+            : { x: Math.max(0, coordinates.x), y: Math.max(0, coordinates.y) };
+          await elementHandle.click({ position: pos });
+        } else {
+          await page.click(selector);
+        }
+      } catch (error: any) {
         logger.log("warn", `Failed to click at coordinates: ${error.message}`);
         await page.click(selector);
       }

709-716: Align type to include isSPA in onDOMClickAction

The renderer can send isSPA; include it in this type for consistency and editor tooling.

   data: {
     selector: string;
     url: string;
     userId: string;
     elementInfo?: any;
     coordinates?: { x: number; y: number };
+    isSPA?: boolean;
   },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4b68efb and bfa941d.

📒 Files selected for processing (2)
  • server/src/browser-management/inputHandlers.ts (1 hunks)
  • src/components/recorder/DOMBrowserRenderer.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
server/src/browser-management/inputHandlers.ts (1)
maxun-core/src/browserSide/scraper.js (1)
  • selector (28-28)
🔇 Additional comments (1)
server/src/browser-management/inputHandlers.ts (1)

668-672: Early-return to skip DOM snapshot for inputs is sensible

This avoids snapshot thrash while typing. Ensure a later, debounced snapshot (e.g., after key idle) exists so the UI eventually reflects caret/value changes.

@amhsirak amhsirak merged commit 0112660 into getmaxun:develop Sep 10, 2025
1 check 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.

2 participants