form.js 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. "use strict";
  2. var __create = Object.create;
  3. var __defProp = Object.defineProperty;
  4. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5. var __getOwnPropNames = Object.getOwnPropertyNames;
  6. var __getProtoOf = Object.getPrototypeOf;
  7. var __hasOwnProp = Object.prototype.hasOwnProperty;
  8. var __export = (target, all) => {
  9. for (var name in all)
  10. __defProp(target, name, { get: all[name], enumerable: true });
  11. };
  12. var __copyProps = (to, from, except, desc) => {
  13. if (from && typeof from === "object" || typeof from === "function") {
  14. for (let key of __getOwnPropNames(from))
  15. if (!__hasOwnProp.call(to, key) && key !== except)
  16. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  17. }
  18. return to;
  19. };
  20. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  21. // If the importer is in node compatibility mode or this is not an ESM
  22. // file that has been converted to a CommonJS file using a Babel-
  23. // compatible transform (i.e. "__esModule" has not been set), then set
  24. // "default" to the CommonJS "module.exports" for node compatibility.
  25. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  26. mod
  27. ));
  28. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  29. var form_exports = {};
  30. __export(form_exports, {
  31. default: () => form_default
  32. });
  33. module.exports = __toCommonJS(form_exports);
  34. var import_bundle = require("../../sdk/bundle");
  35. var import_tool = require("./tool");
  36. var codegen = __toESM(require("../codegen"));
  37. const fillForm = (0, import_tool.defineTabTool)({
  38. capability: "core",
  39. schema: {
  40. name: "browser_fill_form",
  41. title: "Fill form",
  42. description: "Fill multiple form fields",
  43. inputSchema: import_bundle.z.object({
  44. fields: import_bundle.z.array(import_bundle.z.object({
  45. name: import_bundle.z.string().describe("Human-readable field name"),
  46. type: import_bundle.z.enum(["textbox", "checkbox", "radio", "combobox", "slider"]).describe("Type of the field"),
  47. ref: import_bundle.z.string().describe("Exact target field reference from the page snapshot"),
  48. value: import_bundle.z.string().describe("Value to fill in the field. If the field is a checkbox, the value should be `true` or `false`. If the field is a combobox, the value should be the text of the option.")
  49. })).describe("Fields to fill in")
  50. }),
  51. type: "input"
  52. },
  53. handle: async (tab, params, response) => {
  54. for (const field of params.fields) {
  55. const { locator, resolved } = await tab.refLocator({ element: field.name, ref: field.ref });
  56. const locatorSource = `await page.${resolved}`;
  57. if (field.type === "textbox" || field.type === "slider") {
  58. const secret = tab.context.lookupSecret(field.value);
  59. await locator.fill(secret.value);
  60. response.addCode(`${locatorSource}.fill(${secret.code});`);
  61. } else if (field.type === "checkbox" || field.type === "radio") {
  62. await locator.setChecked(field.value === "true");
  63. response.addCode(`${locatorSource}.setChecked(${field.value});`);
  64. } else if (field.type === "combobox") {
  65. await locator.selectOption({ label: field.value });
  66. response.addCode(`${locatorSource}.selectOption(${codegen.quote(field.value)});`);
  67. }
  68. }
  69. }
  70. });
  71. var form_default = [
  72. fillForm
  73. ];