donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
40 lines • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GoToWebpageTool = void 0;
const Tool_1 = require("./Tool");
const PlaywrightUtils_1 = require("../utils/PlaywrightUtils");
/** Directly navigate to the specified URL. */
class GoToWebpageTool extends Tool_1.Tool {
constructor() {
super(GoToWebpageTool.NAME, 'Go directly to the specified URL.', 'GoToWebpageToolCoreParameters', 'GoToWebpageToolGptParameters');
}
async call(context, parameters) {
const page = context.page;
const url = parameters.url.trim();
if (GoToWebpageTool.VALID_PROTOCOLS.some((protocol) => url.startsWith(protocol))) {
await page.goto(url, {
waitUntil: 'domcontentloaded',
});
await PlaywrightUtils_1.PlaywrightUtils.waitForPageStability(page);
return {
isSuccessful: true,
forLlm: `Successfully navigated to ${url}`,
metadata: null,
};
}
else {
return {
isSuccessful: false,
forLlm: `Will not navigate a URL not using the following prefixes: ${GoToWebpageTool.VALID_PROTOCOLS}`,
metadata: null,
};
}
}
async callFromGpt(context, parameters) {
return this.call(context, parameters);
}
}
exports.GoToWebpageTool = GoToWebpageTool;
GoToWebpageTool.NAME = 'goToWebpage';
GoToWebpageTool.VALID_PROTOCOLS = ['https://', 'http://', 'file://'];
//# sourceMappingURL=GoToWebpageTool.js.map