Skip to main content
Glama
pvinis
by pvinis

playwright_drag

Use this tool to drag and drop web elements to a target location using CSS selectors for precise interaction within a browser environment.

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 and its execute method implement the core logic for the 'playwright_drag' tool, using Playwright to locate elements by selectors, get their bounding boxes, and perform a mouse drag operation from source to target.
    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 input schema for 'playwright_drag'.
    {
      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"],
      },
    },
  • Switch case in handleToolCall that registers and dispatches the 'playwright_drag' tool call to dragTool.execute.
    case "playwright_drag":
      return await dragTool.execute(args, context);
  • Instantiation of the DragTool instance during tool initialization.
    if (!dragTool) dragTool = new DragTool(server);
  • src/tools.ts:422-422 (registration)
    Inclusion of 'playwright_drag' in the BROWSER_TOOLS array for conditional browser launching.
    "playwright_drag",

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/pvinis/mcp-playwright-stealth'

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