Browser automation means having a program do what you would otherwise do by hand: open a page, click, type, wait, read what appears. It is how teams test web apps before a release, and how individuals stop doing the same twenty clicks every Monday. There are several ways to drive a browser from code, and they suit different jobs. This article walks through them in plain terms and then looks at one more: an API built into the browser you already use.
What people automate a browser for
- Testing. A script signs in to your web app, adds an item to the cart and checks that the total is right. Run it on every change and you catch breakage before your users do.
- Repetitive tasks. Downloading the same monthly report, filling in the same form, or checking a dashboard and noting one number.
- Screenshots and PDFs. Capturing how a page looks, on a schedule or across many pages.
- Watching for a change. Loading a page now and then and telling you when something on it is different.
What these have in common is a real page. Many sites build their content with JavaScript after loading, so fetching the raw HTML is not enough. You need something that behaves like a browser, and the simplest such thing is a browser.
The usual ways to drive a browser
WebDriver-style drivers
WebDriver is a web standard for remote control of browsers. Your script sends commands such as "find this button" and "click it" to a small driver program, and the driver passes them to the browser. Because it is a standard, the same test can run against several browsers, and there are libraries for most programming languages.
This approach is the backbone of cross-browser test suites. It usually starts a fresh browser with a clean profile for each run, which is what a test wants. The moving parts are the cost: a driver for each browser, kept in step with the browser's version.
DevTools-protocol libraries
Browsers have a debugging interface, the one their built-in developer tools use. A second family of libraries talks to the browser through that interface. This gives fine control: you can watch network requests, change responses and record detailed traces.
These libraries are fast and pleasant to script, and they commonly download their own copy of a browser to drive. That makes results repeatable. It also means the browser being automated is usually not the one you use every day.
Extension and user scripts
A script can also run inside the page itself, installed through a browser extension. This is the lightest option and is good for small adjustments to sites you visit. It is limited to what a page is allowed to do. It cannot open windows freely, manage tabs across sites or run while the browser is closed.
A fourth option: a local API in the browser itself
The fourth approach puts the control surface inside the browser. The browser listens on an address on your own computer and accepts ordinary web requests: open this address in a tab, click this element, give me the text of that page. Anything that can send an HTTP request can drive it, from a shell script to a spreadsheet macro.
The difference is what is on the other end. It is your browser, with your profiles, your sign-ins and your settings. A script can work in a session where you are already signed in, without storing your password in the script. There is no separate driver to install or keep in step.
It has trade-offs too. It is specific to one browser, so it is not a way to test your site in every browser. And because it can act as you, the API must stay private: listening on your own machine only, behind a key.
How the approaches compare
| Approach | Strongest at | Keep in mind |
|---|---|---|
| WebDriver-style driver | Testing one site in several browsers | A driver per browser to install and update |
| DevTools-protocol library | Fast, detailed scripting and tracing | Usually drives its own copy of a browser |
| Extension or user script | Small changes to pages you visit | Limited to what a page may do |
| Local API in the browser | Automating the browser and sessions you already use | Tied to that browser, and must be kept private |
These are not rivals so much as tools for different jobs. A team may run a cross-browser suite before releases and still use a local API for the weekly chores.
Automating responsibly
A script can make a thousand requests in the time you make one, so a few habits matter.
- Read the terms. Automating your own site and your own accounts is ordinary. Collecting content from someone else's site may not be allowed.
- Respect robots.txt. It is where a site says which parts automated visitors should leave alone.
- Go slowly. Add pauses. A person does not load fifty pages a second.
- Keep the door closed. Leave a control API on your own machine, and treat its key like a password.
How Vela does it
Vela for Mac includes an Automation API. You turn it on in Settings → Automation with Enable Automation API. By default it listens on 127.0.0.1, port 1306, which means only programs on your own Mac can reach it. Every request must carry your API key, in an X-API-Key header.
Opening a page in a new tab is one request:
curl -X POST http://127.0.0.1:1306/api/tabs \
-H "X-API-Key: $VELA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com"}'
From there the API covers the things a script needs: navigate, click, fill in and type into fields, wait for an element, extract text, take a screenshot or a PDF, and read or set cookies. A WebSocket connection at /api/events reports what happens in the browser as it happens. Tabs can be opened in a chosen profile, so a script can work inside the right set of sign-ins.
There are three ways to run it. In the normal, headed mode you watch the browser work. Hidden mode runs the full browser with its windows invisible, and sessions persist. Headless mode is lighter, and its sessions do not persist. Hidden and headless instances use port 1307 by default, so they can run next to the browser you are using.
To try it, start with the Automation API quick start, then read about headless and hidden mode. Every endpoint is listed in the API docs.