Detection Rules
Every page in your script has a detect object that tells the engine when that page is active. The engine continuously checks all your pages against the current browser state — URL, visible elements, and on-screen text. When a page's detection rules match, its actions run.
Getting detection right is the most important part of writing a script. If detection is too loose, the wrong page matches and actions run on the wrong screen. If detection is too strict, the page never matches and the script gets stuck. This guide shows you how to write precise, reliable detection rules.
Detection Fields
| Field | Type | Description |
|---|---|---|
url_contains | string | Matches when the browser URL includes this substring. |
selector | string | string[] | CSS selector or XPath that must be visible on the page. |
text | string | string[] | Text that must be visible on the page (substring match). |
mode | "all" | "any" | Whether all rules must match (default) or just one. |
absent | string | string[] | Selector(s) that must NOT be visible for this page to match. |
url_contains
The simplest detection rule. It checks whether the current browser URL includes the string you specify. Open the target website in your browser and look at the address bar — copy the part of the URL that is unique to each step.
For example, if the URL on step 1 is https://example.com/apply/step-1 and step 2 is https://example.com/apply/step-2, you can use /step-1 and /step-2 as your url_contains values.
{
"name": "Step 1 - Zip Code",
"detect": {
"url_contains": "/step-1"
},
"actions": [...]
}You can also match the full domain when the URL doesn't change between steps — in that case, combine it with selector or text to distinguish pages:
{
"name": "Landing Page",
"detect": {
"url_contains": "example-loan-site.com",
"selector": "#zipcode",
"text": "Get Your Free Quote"
},
"actions": [...]
}Common URL Patterns
| URL Pattern | url_contains Value | When to Use |
|---|---|---|
example.com/apply/step-1 | "/step-1" | Multi-step forms with unique paths per step. |
example.com/thank-you | "/thank-you" | Confirmation or success pages. |
example.com/apply?step=2 | "step=2" | Query-string based steps. |
example.com/form (doesn't change) | "example.com/form" | SPA — combine with selector or text to distinguish steps. |
selector
Matches when a CSS selector or XPath expression points to a visible element on the page. This is the most powerful detection rule because it checks exactly what the user sees — if the element is hidden, loading, or removed, it won't match.
CSS Selectors
The easiest selectors use an element's id attribute. Right-click any form field or button in Chrome, choose Inspect, and look for id="..." in the HTML. Prefix it with #:
{
"detect": {
"selector": "#email"
}
}If the element has no id, use a class name (prefix with .) or any valid CSS selector:
{
"detect": {
"selector": "form.contact-form"
}
}XPath Selectors
XPath is useful when you need to match elements by their visible text — something CSS selectors can't do. Prefix XPath expressions with xpath=:
{
"detect": {
"selector": "xpath=//button[contains(normalize-space(),'Next')]"
}
}This matches any <button> whose visible text contains "Next". The normalize-space() function trims whitespace so it matches even if the button has extra spaces.
More XPath examples:
// Match a heading with specific text
"selector": "xpath=//h2[contains(text(),'Contact Information')]"
104
"selector": "xpath=//input[@name='firstName']"
192
"selector": "xpath=//div[normalize-space()='Are You a Home Owner?']"Text Selectors
You can also match elements by their visible text using the text= prefix:
{
"detect": {
"selector": "text=Get Started"
}
}Array of Selectors
When you pass an array of selectors, all of them must be visible for the page to match. Use this to ensure you're on the right page by requiring multiple elements:
{
"detect": {
"selector": [
"xpath=//*[@id='firstName']",
"xpath=//*[@id='lastName']",
"xpath=//*[@id='email']"
]
}
}This page only matches when all three fields — first name, last name, and email — are visible at the same time. If only one or two are showing, it won't match.
text
Matches when the specified text is visible anywhere on the page. The match is a substring check — if the text appears inside any visible element, the rule passes.
{
"detect": {
"text": "What Is Your Email Address?"
}
}Use text for page headings, questions, or instructions that are unique to that step. It's the fastest way to detect a page when you don't want to hunt for selectors.
Array of Text
When you pass an array, all text strings must be visible for the page to match. This makes detection more precise:
{
"detect": {
"text": [
"What Is Your Name?",
"Please enter your full legal name as it appears on your government-issued ID."
]
}
}Both the heading and the subtitle must be visible. This prevents false matches on other pages that might share the same heading but have different body text.
mode
Controls how multiple detection rules are combined. There are two modes:
mode: "all" (default)
Every rule must match. This is the default — you don't need to specify it, but you can for clarity. Use this when you want precise, specific detection:
{
"detect": {
"url_contains": "example.com",
"mode": "all",
"selector": "#email",
"text": "What Is Your Email Address?"
}
}This page matches only when ALL three conditions are true: the URL contains "example.com", the #email element is visible, AND the text "What Is Your Email Address?" is on screen.
mode: "any"
At least one rule must match. Use this when a page might appear in different states — for example, a confirmation page that could show different messages:
{
"name": "Thank You",
"detect": {
"mode": "any",
"text": [
"Thank you for your submission",
"Your request has been received",
"Congratulations"
]
},
"actions": [
{ "type": "sheet_status", "value": "lead" }
]
}This matches if ANY of those three texts appear. This is useful for thank-you pages that vary their message.
absent
A selector that must NOT be visible for the page to match. This is a negative gate — it blocks the match even if all other rules pass.
The most common use case is waiting for a loading state to finish:
{
"name": "Form Step 2",
"detect": {
"url_contains": "/step-2",
"selector": "#name-field",
"absent": ".loading-spinner"
},
"actions": [...]
}This page matches only when the URL contains "/step-2", the name field is visible, AND the loading spinner is gone. Without absent, the page might match while the form is still loading, and actions would fail because the fields aren't ready yet.
Other use cases for absent:
// Wait for a modal overlay to close before interacting
"absent": ".modal-overlay"
84
"absent": ".error-banner"
153
"absent": "[class*='skeleton']"Combining Rules
In real scripts, you almost always combine multiple detection rules. Here is a real-world example from a loan application form with 20+ steps. Each step has the same domain in the URL, so url_contains alone can't distinguish them:
{
"name": "Step 3 - Name",
"detect": {
"url_contains": "example-loan-site.com",
"mode": "all",
"text": [
"What Is Your Name?",
"Please enter your full legal name"
],
"selector": [
"xpath=//*[@id='firstName']",
"xpath=//*[@id='lastName']"
]
},
"actions": [...]
}This detection requires all four conditions to be true simultaneously:
- URL contains "example-loan-site.com"
- The heading "What Is Your Name?" is visible
- The subtitle text is visible
- Both the first name and last name fields are on screen
This level of specificity prevents the page from matching on step 2 (which also has the same domain) or on a different step that might reuse similar field IDs.
Common Detection Patterns
Multi-Step Form (URL Changes Each Step)
The easiest scenario — each step has a unique URL path. Use url_contains as the primary detection rule:
{
"name": "Step 1 - Contact Info",
"detect": {
"url_contains": "/apply/step-1",
"selector": "#first-name"
},
"actions": [...]
},
{
"name": "Step 2 - Address",
"detect": {
"url_contains": "/apply/step-2",
"selector": "#address"
},
"actions": [...]
},
{
"name": "Confirmation",
"detect": {
"url_contains": "/apply/confirmation"
},
"actions": [
{ "type": "sheet_status", "value": "lead" }
]
}Single-Page App (URL Doesn't Change)
Many modern forms are SPAs — the URL stays the same while content changes dynamically. Use selector and text to distinguish steps:
{
"name": "Step 1 - Loan Amount",
"detect": {
"url_contains": "example-loan-site.com",
"mode": "all",
"selector": "xpath=//button[contains(normalize-space(),'$500')]",
"text": "How Much Do You Need?"
},
"actions": [...]
},
{
"name": "Step 2 - Email",
"detect": {
"url_contains": "example-loan-site.com",
"mode": "all",
"selector": "xpath=//*[@id='email']",
"text": "What Is Your Email Address?"
},
"actions": [...]
}Thank You / Confirmation Page
Confirmation pages often show different messages depending on the outcome. Use mode: "any" with multiple text options or url_contains for the thank-you path:
{
"name": "Thank You",
"detect": {
"mode": "any",
"url_contains": "/thank-you",
"text": "Your request has been submitted"
},
"actions": [
{ "type": "sheet_status", "value": "lead" }
]
}Popup / Cookie Banner
Popups can appear on any page at any time. Define them with their own selector and use the popups array at the top level, or add them as a separate page with optional actions:
{
"name": "Cookie Banner",
"detect": {
"selector": ".cookie-consent-banner"
},
"actions": [
{
"type": "click",
"selector": ".cookie-consent-banner .accept-btn",
"optional": true
}
]
}How to Find Selectors
Finding the right selector is a core skill for writing scripts. Here is the step-by-step process:
Step 1 — Open DevTools
Open the target website in Chrome. Press F12 (or right-click anywhere → Inspect) to open Chrome DevTools. Click the Elements tab.
Step 2 — Inspect the Element
Right-click the specific field, button, or element you want to target and choose Inspect. DevTools will highlight the element in the HTML tree.
Step 3 — Find the Selector
Look at the highlighted HTML and check for these attributes in order of preference:
| Priority | Attribute | Selector Format | Example |
|---|---|---|---|
| 1st | id | #id-value | #email from <input id="email"> |
| 2nd | name | [name="value"] | [name="firstName"] |
| 3rd | unique class | .class-name | .submit-button |
| 4th | visible text | XPath | xpath=//button[contains(normalize-space(),'Submit')] |
Always prefer id when available — it's unique and rarely changes. If the element has no id, use name or a distinctive class. As a last resort, use XPath to match by visible text.
Step 4 — Test the Selector
In Chrome DevTools, switch to the Console tab and type:
// Test a CSS selector — returns the element or null
document.querySelector("#email")
87
document.evaluate("//button[contains(normalize-space(),'Next')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValueIf the command returns an element (not null), your selector is correct. If it returns null, the element either doesn't exist or your selector is wrong — double-check the HTML.
Fallback Selectors
You can provide multiple selectors as an array. For detection, all must match. For actions (covered in the next section), the engine tries each one and uses the first that works — useful when elements have different selectors across visits:
{
"detect": {
"selector": [
"xpath=//*[@id='firstName']",
"xpath=//*[@id='lastName']"
]
}
}Tips for Reliable Detection
- Use at least two detection signals per page. A single text match can break if the site changes a heading. Combining
url_containswithselectorortextmakes detection much more reliable. - Copy text exactly. The
textfield does a substring match, but it's case-sensitive. Copy the text directly from the page to avoid typos. - Prefer IDs over classes. CSS classes can change between deployments. An
idis almost always stable. - Watch out for shared elements. Headers, footers, and navigation bars appear on every page. Don't use them as selectors unless combined with another signal that's unique.
- Use
absentfor loading states. If a page shows a spinner before the form loads, addabsent: ".spinner"so the page only matches after the spinner disappears. - Test detection before adding actions. Run your script with just the detection rules first. Watch the logs to see which pages match — fix detection before worrying about actions.