UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

50 lines 2.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DoubleClickTool = void 0; const ToolSchema_1 = require("../models/ToolSchema"); const Logger_1 = require("../utils/Logger"); const MiscUtils_1 = require("../utils/MiscUtils"); const TargetUtils_1 = require("../utils/TargetUtils"); const ReplayableInteraction_1 = require("./ReplayableInteraction"); class DoubleClickTool extends ReplayableInteraction_1.ReplayableInteraction { constructor() { super(DoubleClickTool.NAME, 'Double-click an element on a webpage.', ToolSchema_1.NoArgsSchema, ReplayableInteraction_1.SelectorBasedSchema, ReplayableInteraction_1.AnnotationBasedSchema); } async invoke(context, _parameters, handles) { const element = handles.label ?? handles.target; const page = (0, TargetUtils_1.webPage)(context); const box = await element.boundingBox(); if (!box) { throw new Error(`Failed to retrieve element bounding box for '${element}'; element may be offscreen or detached.`); } const clickDuration = MiscUtils_1.MiscUtils.generateHumanLikeClickDurationInMs(); try { try { await element.hover({ timeout: 1000 }); await page.waitForTimeout(50); } catch { // This is best-effort, just move on. } await context.interactionVisualizer.pointAt(page, element); await element.dblclick({ delay: clickDuration, timeout: 1000, }); return 'Double-clicked on: '; } catch (error) { (0, Logger_1.logErrorWithoutStack)('Failed to directly double-click element, failing over to position based double-click...', error, 'warn'); const x = box.x + box.width / 2; const y = box.y + box.height / 2; await page.mouse.move(x, y); await page.mouse.dblclick(x, y, { delay: clickDuration, }); return `Double-clicked at ${x}px by ${y}px on: `; } } } exports.DoubleClickTool = DoubleClickTool; DoubleClickTool.NAME = 'doubleClick'; //# sourceMappingURL=DoubleClickTool.js.map