Skip to content

Commit

Permalink
chalk and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelg719 committed Jan 30, 2025
1 parent 6e981d4 commit 23938b2
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions examples/form_filling_sensible.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { Stagehand } from "@/dist";
import StagehandConfig from "@/stagehand.config";
import chalk from "chalk";

async function formFillingSensible() {
const stagehand = new Stagehand({
...StagehandConfig,
// Uncomment the following lines to run locally or use a different model
// env: "LOCAL",
// modelName: "gpt-4o-mini",
env: "LOCAL",
modelName: "gpt-4o-mini",
});
await stagehand.init();

// Block manifest worker to prevent PWA installation popup
// Block manifest worker to prevent PWA installation popup.
// This is necessary because the website prompts the user to install the PWA and prevents form filling.
await stagehand.page.route("**/manifest.json", (route) => route.abort());

// Go to the website and wait for it to load
Expand All @@ -26,8 +28,12 @@ async function formFillingSensible() {
returnAction: true,
});

// Uncomment the following line to see the stagehand candidate suggestions (initial)
// console.log(observed);
// Uncomment the following snippet to see the stagehand candidate suggestions (initial)
console.log(
`${chalk.green("Observe:")} Form fields found:\n${observed
.map((r) => `${chalk.yellow(r.description)} -> ${chalk.gray(r.selector)}`)
.join("\n")}`,
);

// Create a mapping of 1+ keywords in the form fields to standardize field names
const mapping = (description: string): string | null => {
Expand Down Expand Up @@ -65,7 +71,14 @@ async function formFillingSensible() {
return candidate;
});
// List of sensible-data candidates
console.log(updatedFields);
console.log(
`\n${chalk.green("Sensible Data form inputs:")} Form fields to be filled:\n${updatedFields
.map(
(r) =>
`${chalk.yellow(r.description)} -> ${chalk.blue(r.arguments?.[0] || "no value")}`,
)
.join("\n")}`,
);

// Fill all the form fields with the sensible candidates
for (const candidate of updatedFields) {
Expand Down

0 comments on commit 23938b2

Please sign in to comment.