Skip to main content
Glama

drag

Automate drag-and-drop actions in Firefox using Playwright by specifying coordinates, offsets, and duration. Ideal for browser testing and debugging multi-tab workflows.

Instructions

Perform drag operation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
durationNo
fromCoordinatesNo
offsetXNo
offsetYNo
selectorNo
stepsNo
tabIdNo
toCoordinatesNo

Implementation Reference

  • The handler function for the 'drag' tool. It supports dragging from an element selector or coordinates to a target selector, coordinates, or offset. Uses Playwright's mouse API for precise control, with optional smooth animation over duration with steps.
    async drag(args) {
      this.ensureBrowserRunning();
      const { 
        selector, 
        fromCoordinates, 
        toSelector, 
        toCoordinates, 
        offsetX, 
        offsetY, 
        duration = 0, 
        steps = 1, 
        tabId 
      } = args;
      const page = this.getPage(tabId);
      
      // Validate inputs
      if (!selector && !fromCoordinates) {
        throw new Error('Either selector or fromCoordinates must be provided');
      }
      
      if (!toSelector && !toCoordinates && offsetX === undefined && offsetY === undefined) {
        throw new Error('Either toSelector, toCoordinates, or offset values must be provided');
      }
      
      // Get starting position
      let startX, startY;
      if (selector) {
        const element = await page.$(selector);
        if (!element) {
          throw new Error(`Element not found: ${selector}`);
        }
        const box = await element.boundingBox();
        if (!box) {
          throw new Error(`Cannot get bounding box for element: ${selector}`);
        }
        startX = box.x + box.width / 2;
        startY = box.y + box.height / 2;
      } else {
        startX = fromCoordinates.x;
        startY = fromCoordinates.y;
      }
      
      // Get ending position
      let endX, endY;
      if (toSelector) {
        const element = await page.$(toSelector);
        if (!element) {
          throw new Error(`Target element not found: ${toSelector}`);
        }
        const box = await element.boundingBox();
        if (!box) {
          throw new Error(`Cannot get bounding box for target element: ${toSelector}`);
        }
        endX = box.x + box.width / 2;
        endY = box.y + box.height / 2;
      } else if (toCoordinates) {
        endX = toCoordinates.x;
        endY = toCoordinates.y;
      } else {
        // Use offset from start position
        endX = startX + (offsetX || 0);
        endY = startY + (offsetY || 0);
      }
      
      // Perform the drag
      await page.mouse.move(startX, startY);
      await page.mouse.down();
      
      if (duration > 0 && steps > 1) {
        // Smooth drag with intermediate steps
        const stepDelay = duration / steps;
        for (let i = 1; i <= steps; i++) {
          const progress = i / steps;
          const currentX = startX + (endX - startX) * progress;
          const currentY = startY + (endY - startY) * progress;
          await page.mouse.move(currentX, currentY);
          if (i < steps) {
            await new Promise(resolve => setTimeout(resolve, stepDelay));
          }
        }
      } else {
        // Direct drag
        await page.mouse.move(endX, endY);
      }
      
      await page.mouse.up();
      
      return {
        content: [{
          type: 'text',
          text: `Dragged from (${Math.round(startX)}, ${Math.round(startY)}) to (${Math.round(endX)}, ${Math.round(endY)}) in tab '${tabId || this.activeTabId}'${duration > 0 ? ` over ${duration}ms` : ''}`
        }]
      };
    }
  • Input schema for the 'drag' tool defining parameters like selector, from/to coordinates, offsets, duration, steps, and tabId.
    inputSchema: {
      type: 'object',
      properties: {
        selector: { type: 'string' },
        fromCoordinates: {
          type: 'object',
          properties: { x: { type: 'number' }, y: { type: 'number' } }
        },
        toCoordinates: {
          type: 'object',
          properties: { x: { type: 'number' }, y: { type: 'number' } }
        },
        offsetX: { type: 'number' },
        offsetY: { type: 'number' },
        duration: { type: 'number', default: 0 },
        steps: { type: 'number', default: 1 },
        tabId: { type: 'string' }
      }
    }
  • Registration of the 'drag' tool in the tools list returned by the ListToolsRequest handler.
    {
      name: 'drag',
      description: 'Perform drag operation',
      inputSchema: {
        type: 'object',
        properties: {
          selector: { type: 'string' },
          fromCoordinates: {
            type: 'object',
            properties: { x: { type: 'number' }, y: { type: 'number' } }
          },
          toCoordinates: {
            type: 'object',
            properties: { x: { type: 'number' }, y: { type: 'number' } }
          },
          offsetX: { type: 'number' },
          offsetY: { type: 'number' },
          duration: { type: 'number', default: 0 },
          steps: { type: 'number', default: 1 },
          tabId: { type: 'string' }
        }
      }
    },
  • Dispatch registration in the CallToolRequest switch statement that routes calls to the drag handler.
    case 'drag':
      return await this.drag(args);
Behavior1/5

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

With no annotations provided, the description carries full burden for behavioral disclosure but offers none. It doesn't indicate whether this is a read or write operation, what visual feedback occurs, whether it requires specific page states, what errors might occur, or any performance characteristics. The agent must infer everything from the parameter names alone.

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

Conciseness2/5

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

While technically concise with just three words, this is under-specification rather than effective brevity. The description fails to provide any meaningful information that would help an agent understand or use the tool correctly, making it inefficient despite its short length.

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

Completeness1/5

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

For a complex 8-parameter UI interaction tool with no annotations, no output schema, and rich sibling tools, the description is completely inadequate. It provides no information about what the tool does, how to use it, what parameters mean, what behavior to expect, or what results might be returned.

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

Parameters1/5

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

With 8 parameters and 0% schema description coverage, the description provides zero information about what any parameter means or how they interact. Critical parameters like 'selector', 'fromCoordinates', 'toCoordinates', 'offsetX/Y', 'duration', 'steps', and 'tabId' are completely unexplained, leaving the agent to guess their purposes and relationships.

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

Purpose2/5

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

The description 'Perform drag operation' is a tautology that merely restates the tool name 'drag' without specifying what resource is being dragged or in what context. It doesn't distinguish this tool from other UI interaction siblings like 'click' or 'send_key', leaving the agent to guess what exactly gets dragged and where.

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

Usage Guidelines1/5

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

No guidance is provided about when to use this tool versus alternatives. With 28 sibling tools including various UI interactions like 'click', 'type_text', and 'send_key', the description offers no context about appropriate use cases, prerequisites, or when other tools might be more suitable for different interaction needs.

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/JediLuke/firefox-mcp-server'

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