Skip to main content
Send a small Floral Embrace bouquet from 1-800-Flowers on the next available delivery date, within a $100 total budget. Stagehand handles the website. Link asks the user to approve the order and supplies the payment card.

1. Set up

You need Node.js 22.18 or newer and pnpm 10 or newer. Set BROWSERBASE_API_KEY in your environment to your Browserbase API key:
Create the project and install the dependencies:
For checkout, you need a Link wallet with an eligible payment method and a user-authorized access token. Follow Stripe’s OAuth setup, which requires contacting Stripe to register a hosted app, then supply the token as LINK_ACCESS_TOKEN through your secret manager. The SDK accepts the token; your application handles login and refresh. For a local agent with built-in login, use the Browse CLI guide.

2. Run the example

Copy the complete file into index.ts. Start with recipient: null to inspect the cart. To continue to checkout, add the recipient’s details, the buyer’s email and phone, and a billing address, then give the order a unique orderId. Link may return only part of the billing address, so the example uses yours when needed.
Node.js
The script chooses the flowers and delivery date, skips paid extras, and adds a complimentary message. With delivery and contact details, it checks the final total and prints a Link approval URL. The example starts in Link test mode. Test credentials don’t charge your payment method, but the merchant can reject them before the final order step. Set testMode: false and use a new orderId when you’re ready to place a real order. The sections below explain parts of the complete file.

3. Prepare the order

Update flowerDelivery with the bouquet, destination, budget, and message. Stagehand chooses the delivery date, skips paid extras, and fills the recipient form. It opens Payment to calculate fees, then returns to the shipment summary to read the complete order:
Node.js
The script checks the selected flowers and delivery details, then rejects an incomplete total or an order over the budget. DOM settling gives the merchant time to update before each natural-language act() call.

4. Request approval

Send Link the merchant, order, and verified total. The request uses the same saved ID when you rerun the script:
Node.js
After saving the request, the script prints its approval URL and checks for approval every two seconds, for up to five minutes. If approval times out, rerun with the same order ID to resume. A changed order needs fresh approval.

5. Fill checkout

Use observe() to find the empty payment controls. Once the user approves, retrieve the card and fill those controls through native locators:
Node.js
The complete file also fills the buyer’s contact details and uses your billing address if Link doesn’t return a complete one. Card values stay out of model calls, screenshots, and logs.

6. Confirm the order

Before continuing, record that checkout has started. Check the review total against the approved amount, then submit once:
Node.js
A merchant confirmation and order number produce ORDER_CONFIRMED. If the result is unclear, inspect the order before retrying. Link approval confirms permission to pay; the merchant’s receipt confirms the order.

Browse CLI quickstart

Set up Browse CLI and give your coding agent a browser.

Stagehand docs

Build browser interactions with act(), observe(), and extract().