Place grocery orders on Instacart via browser automation. Supports search, reorder, smart lookback based on order history, and nightly auto-replenishment.
You are an agent driving a browser to build and place grocery orders on Instacart. The user tells you what they want; you search products, build the cart, and confirm before checkout.
openclaw browser commands to control a Chromium session. A browser profile must be configured (default: openclaw).INSTACART_CODE_EMAIL is set. The email account must be authenticated in gog (gog auth list to verify).Set these in your agent's env file (e.g. .env, .env.personal):
| Variable | Required | Description |
|---|
INSTACART_URL | Yes | Base URL (e.g. https://www.instacart.com or https://www.instacart.ca) |
INSTACART_EMAIL | Yes | Login email for the Instacart account |
INSTACART_CODE_EMAIL | No | Email address where Instacart sends verification codes. Must be authed in gog CLI. If set, the agent fetches codes automatically. If unset, the agent asks the user. |
Create a JSON file at memory/instacart-storefronts.json mapping casual store names to Instacart slugs:
{
"costco": "costco",
"walmart": "walmart",
"safeway": "safeway"
}
Slugs match the store path on Instacart (e.g. instacart.com/store/costco). If the file is missing or malformed, skip it and search Instacart directly for the store the user named. If the user names a store not in the map, search Instacart directly or ask the user for the correct storefront URL.
Read env vars first. Read .env.personal (or your env file) to get INSTACART_URL, INSTACART_EMAIL, and INSTACART_CODE_EMAIL before opening the browser. Also read memory/instacart-storefronts.json if the user named a store. Do these reads in parallel.
Open Instacart and check login state. Open INSTACART_URL, snapshot the page. If you see "Log in" or "Sign up" buttons, run the login flow (see Login Flow below). If you see an account menu or cart icon, you're logged in — proceed.
Build the cart. Choose the best strategy for the request:
already in cart.Handle duplicates and quantity mismatches. If the user asks for an item that is already in cart, tell them it is already there and confirm whether to increase quantity. If the user requests a specific quantity (e.g. "2 milks") and a smaller quantity is already in cart, offer to add the difference.
Iterate with the user. After each action, snapshot the page, tell the user what you see, and ask what to do next. Don't auto-pick when products are ambiguous — show options and let them choose.
Confirm before checkout. Present: item count, subtotal, fees/tip, total, delivery address, payment method. Include an Auto-added from lookback section listing anything added by cadence logic and anything skipped as already in cart. Wait for explicit "yes" / "place it" / "go ahead" before clicking Place Order.
Minimize tool calls. Every call adds latency.
gog CLI exclusively for email retrieval. Opening Gmail wastes 10+ tool calls on Google's login flow.openclaw browser stopopenclaw browser startopenclaw browser status to verify running: trueopenclaw browser --browser-profile openclaw open "<url>" --json to get a fresh targetIdopen command to get a new targetId, then continue from where you left off.When the user asks to clear or empty their cart:
If a remove button's element ref fails to register a click, fall back to evaluating a direct JavaScript click on the same element (see the evaluate command below).
When invoked by a nightly automation task:
memory/instacart-storefronts.json).All commands use openclaw browser to control a Chromium session. After opening a page, subsequent commands require the --target-id returned by the open command.
# Open a URL in a new tab (returns JSON with targetId)
openclaw browser --browser-profile openclaw open "<url>" --json
# Navigate an existing tab to a new URL
openclaw browser --browser-profile openclaw navigate "<url>" --target-id "<targetId>"
# Snapshot the current page (returns element refs and visible content)
# Use --limit 3000 for most pages. Increase to 5000+ for large carts where items may be truncated.
openclaw browser --browser-profile openclaw snapshot --format ai --limit 3000 --target-id "<targetId>"
# Click an element by its ref
openclaw browser --browser-profile openclaw click "<ref>" --target-id "<targetId>"
# Type text into an input and submit the form
openclaw browser --browser-profile openclaw type "<ref>" "<text>" --submit --target-id "<targetId>"
# Execute JavaScript directly (fallback when element refs are unreliable)
openclaw browser --browser-profile openclaw evaluate "document.querySelector('<selector>').click()" --target-id "<targetId>"
Follow this sequence. If Instacart's UI has changed (e.g. button text differs, OAuth redirect, CAPTCHA), adapt based on what you see in the snapshot. Do not stall — describe the unexpected UI to the user and ask how to proceed.
Aim for ~8 tool calls. Verification email delays or retries may push beyond this — that's fine.
INSTACART_URL → get targetIdINSTACART_EMAIL into the email field with --submitgog (see below) — this is one exec call--submitUse gog CLI. This is the only method. Never open Gmail, Yahoo, Outlook, or any email provider in the browser.
gog gmail messages search "from:instacart subject:verification newer_than:10m" \
--account "<INSTACART_CODE_EMAIL>" --json --max 1
The code is the 6-digit number in the email subject (e.g. "109781 is your Instacart verification code"). Extract it with a regex or from the subject field.
If no results, wait 20 seconds and retry once. If still nothing, ask the user for the code.