Scenarios without code
A scenario is a list of steps that Mirage runs in a profile for you: open a page, fill a field, click a button, read a value, repeat for every row of a table. Mouse paths and typing look like a person’s. A scenario has no code in it, so you can share one and run one you received without risk to your computer.
Run your first scenario
- Open Automation and find Scenarios.
- Choose New scenario. The editor opens with an example in blocks (see below); change it and choose Save. To use a file someone sent you, choose Import and pick the
.jsonfile. - Choose Run (▶) next to the scenario, pick a profile and fill in its variables. Without a window (headless) runs a stopped profile in the background.
- The run appears under Recent runs. Click it to see its log, its error if it failed, and the variables at the end. Stop (■) ends a run after the current step.
A stopped profile starts first and keeps running after the scenario. One scenario runs on a profile at a time. Scenarios go through the same Gateway as scripts, so a profile locked for agents or scripts is locked for scenarios too.
Build it from blocks
The editor opens on Blocks: each step is a block with its number, its kind and a short line about it. Click a block to open its fields. Add step under a list offers every kind of step by group: pages and tabs, actions, waiting, data and logic. An If block holds two lists, Then and Otherwise; Repeat and For each hold the steps they repeat. Each list has its own Add step.
To change the order, drag a block by its handle (⠿), also into or out of a branch, or use Move up and Move down; with the keyboard, Alt+↑ and Alt+↓ on a block do the same. Duplicate and Delete step are next to them. More options holds what every step has: a title for the log, a timeout and Go on if this step fails.
A step that acts on an element asks how to find it: Find by a role and name, a label, a placeholder, text, a test id or a CSS selector (see Finding elements). Insert a variable next to a field puts {{name}} of a variable the scenario has into it. A block with a problem has a red border and says what is wrong; Save shows the first problem too.
Variables sets the starting values, and Data table holds rows for For each over data: add columns and rows by hand or Import CSV (the first row names the columns). The JSON tab shows the same scenario as text: a change on either tab is there on the other.
Many profiles and schedules
In the Run dialog, tick several profiles (the search box and Select all help with long lists). At a time sets how many of them work together, 1 to 20; the rest wait their turn. The run button (it reads, say, “Run on 3 profiles”) starts them: Runs on several profiles shows how many are done and which failed, and each profile’s run appears under Recent runs with its log. Stop (■) on the batch starts no more profiles and stops the ones running. A profile where another scenario is running counts as failed.
Repeat turns the run into a schedule: Every N minutes (5 or more) or On days, at a time with the weekdays to run on (none means every day). Save schedule keeps it under Schedules, with when it runs next. The switch turns a schedule off and on; the calendar button changes it. The time is this computer’s clock, and Mirage must be running: a time missed while the app was closed is skipped, and a time that comes while the last run of the same schedule still goes on is skipped too.
Warm up profiles
A new profile has no history and no cookies, and sites treat it with more suspicion. Warm up on the Scenarios page makes a scenario that opens a list of sites in the profile and reads each one like a person: it scrolls by varied amounts with pauses, sometimes scrolls back, moves the mouse, follows a few links of the same site and accepts cookie banners.
In Warm up profiles, pick a Set of sites by niche (news, shopping, tech, Europe, Ukraine and others) or type My list, one site per line; editing the list makes it your own. Set how long to stay on a site (a random time between the two numbers), Links per site and Accept cookie banners. The dialog shows how long one run takes on a profile. Create and choose profiles saves the scenario and opens the Run dialog: tick the profiles, how many at a time, and a schedule if the warm-up should repeat, say, every day.
Links that sign out, unsubscribe or delete something, open a new tab or download a file are never followed. A site that fails to open is skipped, and the run goes on with the next one. The scenario is an ordinary one: open it with the pencil to change sites or timing. Its main step is browse, which works in any scenario too.
The file
{ "format": "mirage.scenario", "version": 1, "name": "Sign in", "variables": { "email": "anna@shop.test" }, "steps": [ { "type": "open", "url": "https://shop.test/login" }, { "type": "fill", "target": { "label": "Email" }, "value": "{{email}}" }, { "type": "click", "target": { "role": "button", "name": "Sign in" } }, { "type": "extract", "target": { "css": "h1" }, "into": "title" }, { "type": "log", "message": "signed in: {{title}}" } ]}variablesare starting values; you can change them for each run.datais a table:{ "columns": ["email", "code"], "rows": [["a@x.test", "1"]] }. Walk it withforEachand"in": "data".humanizeis on unless you set it tofalse.{{name}}in any text puts a variable there.{{row.email}}reads a column of a row,{{items.0}}an item of a list. An unknown name fails the step, so typos show up at once.
Finding elements
A target says which element a step works with. Use the way a person would describe it:
| Field | Finds |
|---|---|
role + name |
A button, link, checkbox, heading by its role and visible name: { "role": "button", "name": "Buy" } |
label |
A field by its label: { "label": "Email" } |
placeholder |
A field by its grey hint text |
text |
An element with this text |
testId |
data-testid |
css |
A CSS selector, when nothing else fits |
exact: true matches the whole text only. nth picks the n-th match from 0; without it the first one is used.
Steps
| Step | Does |
|---|---|
open url |
Opens a page in the current tab |
newTab url?, switchTab index, closeTab |
Works with tabs |
back, reload |
Goes back, reloads |
browse seconds maxSeconds? links? acceptCookies? |
Reads the page like a person for this many seconds (or a random time up to maxSeconds): scrolls, pauses, follows up to links links of the same site, accepts a cookie banner |
click target button? double? |
Clicks |
fill target value |
Types into a field, replacing its text |
press key target? |
Presses a key: Enter, Tab, Control+A |
select target value |
Picks an option by its text or value |
check target checked? |
Ticks or clears a checkbox |
hover target, scroll deltaY? target? |
Moves the mouse, scrolls |
wait ms maxMs? |
Waits, or a random time between ms and maxMs |
waitFor target state? |
Waits until an element is visible, hidden, attached or gone |
waitUrl contains |
Waits until the address contains this text |
extract target into attribute? all? |
Puts an element’s text (or attribute, or every match as a list) into a variable |
set name value |
Sets a variable |
http method url headers? body? into? direct? |
Sends a request from the app, not the page, through the profile’s proxy. A JSON reply becomes an object or list. direct: true sends it from this device’s real IP instead |
log message |
Writes a line to the log |
stop failed? message? |
Ends the run here |
if when then else? |
Runs steps if a condition holds |
repeat times index? steps |
Runs steps several times |
forEach in as steps |
Runs steps for every item of a list or row of data |
Every step can have title (shown in the log), timeoutMs (30 s by default) and optional: true: a failure of an optional step is logged and the run goes on.
Conditions for if: exists and visible with a target, urlContains, equals and contains with two texts, and not, all, any to combine them.
{ "type": "if", "when": { "all": [{ "exists": { "role": "button", "name": "Buy" } }, { "not": { "urlContains": "/sold-out" } }] }, "then": [{ "type": "click", "target": { "role": "button", "name": "Buy" } }], "else": [{ "type": "stop", "failed": true, "message": "out of stock" }] }Record a scenario
Record on the Scenarios card records what you do in a profile and turns it into steps. Pick a profile and press Start recording: a stopped profile opens in a window. Do the task in it, then press Done on the card. Mirage shows the scenario: pages as open and waitUrl, clicks, ticks and choices as click, check and select, and the text you typed as fill steps whose values are variables. Check it, fix the JSON if needed, and Save scenario. The TypeScript and Python tabs show the same steps as Playwright code.
Passwords and other hidden fields are not recorded: their variables stay empty. If the Blackbox already records the profile, the scenario is taken from its recording, starting when you pressed Start recording; without its DOM recording typed text is not available and fields become empty variables. Cancel stops recording without a scenario.
From a recording
Instead of writing steps by hand, record yourself doing the task in a profile with the Blackbox on, then press Make a scenario in the recording’s player. See Turn a recording into a scenario.
Export: a file or Playwright code
Export (</>) next to a scenario has three tabs:
- JSON is the scenario file. Send it to someone, keep it in git, import it in another Mirage.
- TypeScript and Python turn the scenario into Playwright code on the SDK. Use it when the scenario needs something steps cannot do, or to run it from your own scripts and servers.
The code does what the scenario does, step by step: the same ways of finding elements, human-like input when humanize is on, and {{templates}} as variables in a v object. Its run(context) function works on any Playwright browser context; the end of the file connects to a profile by name:
MIRAGE_API_KEY=mrg_... npx tsx sign-in.ts "Shop 1" # needs @mirage-browser/sdk and playwright-coreMIRAGE_API_KEY=mrg_... python sign_in.py "Shop 1" # needs mirage-browser-sdk and playwrightChanges to the code do not go back to the scenario.
Limits
- A run takes at most 100,000 steps, counting every pass of a loop.
httponly goes tohttp://andhttps://addresses and reads at most 5 MB of a reply. It leaves the way the profile’s browser does: through its proxy, and not at all while the proxy is down. It shares the profile’s cookies for the address. A step withdirect: truegoes from this device’s own IP and sends no cookies: use it only for your own services, such as a webhook on your network. Nohttpstep goes to this computer (localhost,127.0.0.1,[::1]) or to link-local addresses such as169.254.169.254, and every redirect is checked the same way: a page cannot use a scenario to reach the services on your computer. Addresses on your local network stay allowed.- The log keeps the first 100 and the last 300 lines of a run; the app keeps the last 200 runs.
- A scenario has at most 1,000 steps at each level and the app keeps up to 500 scenarios.