How to Make Playwright Autonomous (Without Letting an AI Agent Run Wild) A developer published a tutorial showing how to make Playwright autonomous by pairing it with an OpenAI-compatible LLM in a simple inspectable loop, using a local checkout page as a fixture. The agent is given a goal — add one notebook and one pen, apply code SAVE5, and check out for a $10 total — rather than a hardcoded list of steps, with the author stressing that the agent should find a path through the UI but not get the final vote on whether the application passes. Playwright is very good at following instructions. Tell it to click a button, it clicks the button. Tell it to fill an input, it fills the input. Give it a test with 40 steps and, assuming the page behaves, it'll run all 40. The problem is that someone has to write those steps. What if you gave Playwright a goal instead? Add two items to a shopping cart, apply the discount code, and check that the total is correct. The browser would need to inspect the page, work out what to click, notice when something changes, and decide what to do next. That's a different kind of automation. And it's a fun engineering problem, provided you don't confuse the agent completed its plan with the application passed a test . Let's build a small version. No giant agent framework. Just Playwright, an LLM API, and a loop we can inspect. A normal Playwright script is a list of instructions: await page.getByRole 'button', { name: 'Add notebook' } .click ; await page.getByRole 'button', { name: 'Checkout' } .click ; Our agent will do something closer to this: The important word is separately . An agent is useful for finding a path through the interface. It shouldn't get the final vote on whether the system works. We'll use a local checkout page so this tutorial doesn't depend on somebody else's website or an account with real payment details. Create a directory and install the dependencies: mkdir autonomous-playwright cd autonomous-playwright npm init -y npm install playwright dotenv npx playwright install chromium You'll also need an API key for an OpenAI-compatible chat completions endpoint. The example below uses OpenAI's endpoint and defaults to gpt-4.1-mini . You can select a different compatible model with an environment variable. Create index.html : < doctype html