UNPKG

@auto-browse/auto-browse

Version:
37 lines (36 loc) 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.browser_navigate = void 0; const tools_1 = require("@langchain/core/tools"); const zod_1 = require("zod"); const test_1 = require("@playwright/test"); const utils_1 = require("./utils"); const context_1 = require("../browser/context"); const navigateSchema = zod_1.z.object({ url: zod_1.z.string().describe("The URL to navigate to"), }); exports.browser_navigate = (0, tools_1.tool)(async ({ url }) => { try { console.log(`[Navigate Tool] Starting operation:`, { url }); const result = await test_1.test.step(`Go to "${url}"`, async () => { return await (0, utils_1.runAndWait)(context_1.context, `Navigated to "${url}"`, async (page) => { await page.goto(url, { waitUntil: "domcontentloaded" }); // Cap load event to 5 seconds, the page is operational at this point await page .waitForLoadState("load", { timeout: 5000 }) .catch(() => { }); }, true); }); console.log(`[Navigate Tool] Operation completed`); return result; } catch (error) { const errorMessage = `Failed to navigate: ${error instanceof Error ? error.message : "Unknown error"}`; console.error(`[Navigate Tool] Error:`, errorMessage); return errorMessage; } }, { name: "goto", description: "Navigate to a URL using Playwright", schema: navigateSchema, });