This project automates weekly lunch ordering on Forkable using Stagehand, an SDK for browser automation built on top of Playwright.
- Automatic Login: Multi-step authentication with environment variables
- Smart Meal Selection: Analyzes and scores meals based on healthiness
- Health Scoring System: Rates each meal from 1-10 based on nutritional value
- Automated Ordering: Processes each weekday systematically
- Order Summary: Provides a detailed summary with health indicators
- Live Browser Session: Watch the automation in real-time via Browserbase
The script uses a health scoring system (1-10 scale):
- 10: Salads with lots of vegetables
- 8-9: Grilled proteins with vegetables, kabobs
- 6-7: Bowls with balanced ingredients
- 4-5: Sandwiches, wraps
- 1-3: Fried foods, heavy pastas, burgers
For each day, the script:
- Clicks "Choose Another Meal" for that day
- Extracts all available meal options
- Assigns health scores to each meal
- Selects the highest-scoring (healthiest) option
- Adds it to the cart
npm installCopy .env.example to .env and add your API keys:
cp .env.example .env && nano .envRequired environment variables:
BROWSERBASE_PROJECT_ID: Your Browserbase project IDBROWSERBASE_API_KEY: Your Browserbase API keyOPENAI_API_KEY: Your OpenAI API key (for AI-powered element detection)FORKABLE_EMAIL: Your Forkable login emailFORKABLE_PASSWORD: Your Forkable password
Run the lunch ordering automation:
npm startThe script will:
- Open a browser session (watch live via the Browserbase URL)
- Navigate to https://forkable.com/mc/
- Log in with your credentials
- Navigate to the current week's lunch order
- Select healthy meals for each weekday
- Save the week's orders
- Display a summary of selected meals
npm run buildTo run on a local browser instead of Browserbase, change env: "BROWSERBASE" to env: "LOCAL" in the index.ts file.
Stagehand is an SDK for automating browsers with AI capabilities. It's built on top of Playwright and provides a higher-level API for better debugging and AI fail-safes.
Key features used in this project:
page.act(): Perform natural language actions on web pagespage.observe(): Discover and plan actions on web pagespage.extract(): Extract structured data from web pages
- Schedule Daily Runs: Set up a cron job to run this script weekly
- Meal Preferences: Add configuration for personal meal preferences
- Diet Restrictions: Support for dietary restrictions (vegetarian, vegan, gluten-free)
- Slack Notifications: Send meal selection summaries to Slack
- Node.js 16+
- Browserbase account
- OpenAI API key
- Forkable account with access to lunch ordering
If you encounter issues:
- Ensure all environment variables are set correctly
- Check that your Forkable credentials are valid
- Verify your Browserbase and OpenAI API keys are active
- Watch the live browser session for debugging