UNPKG

donobu

Version:

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

36 lines 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ClickTool = void 0; const ReplayableInteraction_1 = require("./ReplayableInteraction"); const MiscUtils_1 = require("../utils/MiscUtils"); class ClickTool extends ReplayableInteraction_1.ReplayableInteraction { constructor() { super(ClickTool.NAME, 'Click an element on a webpage.', 'SelectorBasedClickToolParameters', 'AnnotationBasedClickToolParameters'); } async invoke(context, _parameters, element) { const page = context.page; const box = await element.boundingBox(); if (!box) { throw new Error(`Failed to retrieve element bounding box for '${element}'; element may be offscreen or detached.`); } try { await element.click({ delay: MiscUtils_1.MiscUtils.generateHumanLikeClickDurationInMs(), timeout: 1000, }); return 'Clicked the element.'; } catch (_error) { const x = box.x + box.width / 2; const y = box.y + box.height / 2; await page.mouse.move(x, y); await page.mouse.click(x, y, { delay: MiscUtils_1.MiscUtils.generateHumanLikeClickDurationInMs(), }); return 'Clicked on the element.'; } } } exports.ClickTool = ClickTool; ClickTool.NAME = 'click'; //# sourceMappingURL=ClickTool.js.map