Skip to main content
Glama

playwright_drag

Drag an element to a specified target location on a webpage using CSS selectors for both the source element and destination, enabling precise browser automation.

Instructions

Drag an element to a target location

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceSelectorYesCSS selector for the element to drag
targetSelectorYesCSS selector for the target location

Implementation Reference

  • The DragTool class containing the execute method that implements the playwright_drag tool logic. It waits for source and target elements, gets their bounding boxes, performs mouse down at source center, moves to target center, and mouse up.
    export class DragTool extends BrowserToolBase {
      /**
       * Execute the drag tool
       */
      async execute(args: any, context: ToolContext): Promise<ToolResponse> {
        return this.safeExecute(context, async (page) => {
          const sourceElement = await page.waitForSelector(args.sourceSelector);
          const targetElement = await page.waitForSelector(args.targetSelector);
          
          const sourceBound = await sourceElement.boundingBox();
          const targetBound = await targetElement.boundingBox();
          
          if (!sourceBound || !targetBound) {
            return createErrorResponse("Could not get element positions for drag operation");
          }
    
          await page.mouse.move(
            sourceBound.x + sourceBound.width / 2,
            sourceBound.y + sourceBound.height / 2
          );
          await page.mouse.down();
          await page.mouse.move(
            targetBound.x + targetBound.width / 2,
            targetBound.y + targetBound.height / 2
          );
          await page.mouse.up();
          
          return createSuccessResponse(`Dragged element from ${args.sourceSelector} to ${args.targetSelector}`);
        });
      }
    }
  • The tool definition object including name, description, and inputSchema for validation of parameters sourceSelector and targetSelector.
    {
      name: "playwright_drag",
      description: "Drag an element to a target location",
      inputSchema: {
        type: "object",
        properties: {
          sourceSelector: { type: "string", description: "CSS selector for the element to drag" },
          targetSelector: { type: "string", description: "CSS selector for the target location" }
        },
        required: ["sourceSelector", "targetSelector"],
      },
    },
  • Dispatch registration in the handleToolCall switch statement that routes playwright_drag calls to the dragTool instance's execute method.
    case "playwright_drag":
      return await dragTool.execute(args, context);
  • Instantiation of the DragTool instance in the initializeTools function, making it available for execution.
    if (!dragTool) dragTool = new DragTool(server);
  • src/tools.ts:469-469 (registration)
    Inclusion of "playwright_drag" in the BROWSER_TOOLS array, used for conditional browser launch and tool categorization.
    "playwright_drag",
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('drag') but doesn't describe what happens during or after the drag (e.g., whether it simulates mouse events, waits for animations, or handles errors). For a mutation tool with zero annotation coverage, this lacks critical behavioral context like side effects or failure modes.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core action ('drag an element to a target location') with zero wasted words. It's appropriately sized for a straightforward tool, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (a mutation action with no annotations and no output schema), the description is incomplete. It doesn't cover behavioral aspects like what the drag entails, potential errors, or return values. For a tool that likely involves UI interaction and state changes, more context is needed to ensure safe and effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with clear descriptions for both parameters (sourceSelector and targetSelector as CSS selectors). The description adds no additional meaning beyond what the schema provides, such as explaining how selectors are resolved or what constitutes a valid target. Baseline 3 is appropriate since the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('drag') and the resource ('an element to a target location'), making the purpose immediately understandable. It distinguishes from sibling tools like playwright_click or playwright_hover by specifying the drag interaction, though it doesn't explicitly differentiate from potential similar tools like playwright_upload_file which might involve dragging.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a page loaded), exclusions (e.g., not for non-draggable elements), or sibling tools for related actions like playwright_click for simpler interactions. Usage is implied by the action name but not explicitly defined.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/executeautomation/mcp-playwright'

If you have feedback or need assistance with the MCP directory API, please join our Discord server