Spider IR
The format of spider.json, the file a spider is. Every field, generated from its JSON Schema.
A spider is one JSON file, spider.json. graphdom build writes it to spiders/<task>/v<n>/, beside the Playwright script it compiles to. The runtime, the compiler and Studio all read this file, and the model that repairs a spider edits this file and nothing else. You can edit it by hand too; check the result with graphdom runtime test.
The format is graphdom-ir@1.0. Its JSON Schema is at /schema/spider.json, and the reference below is generated from it.
Example
A spider that searches a quotes site and returns every quote on the results page.
{
"format": "graphdom-ir@1.0",
"spider": "search_quotes",
"version": 1,
"origins": { "site": "https://quotes.example.com" },
"inputs": { "query": { "type": "string", "example": "love" } },
"outputs": { "quotes": { "type": "list", "of": { "text": "string", "author": "string" } } },
"targets": {
"search": { "is": { "role": "searchbox" }, "by": [{ "role": "searchbox", "name": "Search" }, { "css": "#q" }] },
"results": { "many": true, "by": [{ "css": ".quote" }] }
},
"start": "home",
"states": {
"home": {
"recognise": { "url": "{site}/", "present": ["search"] },
"edges": [
{
"id": "search",
"steps": [
{ "id": "s1", "do": "fill", "target": "search", "value": { "input": "query" }, "effect": "read" },
{ "id": "s2", "do": "press", "target": "search", "keys": ["Enter"], "effect": "read",
"until": [{ "navigation": "GET {site}/search" }], "timeoutMs": 5000 }
],
"to": ["results"]
}
]
},
"results": {
"recognise": { "url": "{site}/search?q=*" },
"edges": [
{
"id": "read",
"steps": [
{ "id": "s3", "do": "extract", "target": "results", "into": "quotes",
"fields": { "text": { "css": ".text" }, "author": { "css": ".author" } } }
],
"to": []
}
]
}
}
}
How a run reads it
A spider is a graph. Its nodes are the states the site can be in, and its edges are blocks of steps.
- The run opens
entry, or the URL of the start state’srecognisewhen there is noentry. - In each state it takes the first edge whose
whenholds, runs its steps in order, and checks that the page arrived in one of the edge’stostates. An edge with an emptytoends the run. - Each step acts, then waits for everything in its
until: a response, a navigation or a condition. A spider never sleeps for a fixed time. - Interrupts can fire in any state: a cookie banner to dismiss, or a CAPTCHA that stops the run.
- A page that matches no state is drift. The run stops and reports where.
Every action step says whether it only reads or submits something (effect). graphdom runtime run asks before each submit step unless you pass --yes.
Steps act on targets, which are named in one place and described by several locators, best first. URLs start with an origin name such as {site}, a role the spider acts on, so the same spider runs against the real site, a staging copy (--origin site=https://staging.example.com) and the offline sandbox. Origins a page only touches, such as a CDN, are listed apart as incidental. Inputs and secrets come in as { "input": "query" } and { "secret": "password" }; a secret’s value is never in the file.
Validate a spider
To check spider.json in your editor, map it to the schema. In VS Code, add this to your settings:
"json.schemas": [
{ "fileMatch": ["spiders/**/spider.json"], "url": "https://docs.graphdom.dev/schema/spider.json" }
]
The schema checks the shape. Graphdom checks the rest before every run and compile, and names the path of each error:
- every name a spider refers to exists: targets, states, inputs, outputs, origins and pages;
- ids and names use letters, digits,
_and-, and step and edge ids are unique; - every URL starts with an origin the spider defines;
- a
selecthas exactly one oflabelandvalue; - a list target (
many) is read only byextract, which then needsfieldsand a list output; - a secret is only the value of
fillortype, or the answer to a prompt dialog; - an interrupt never submits.
Spider
A spider: a graph of the states a site can be in, whose edges are blocks of steps.
formatstringrequiredThe IR version, "graphdom-ir@1.<minor>".
spiderstringrequiredThe id of the task the spider does.
versionintegerrequiredThe spider's version, from 1, never changed once approved.
originsmap of stringrequiredThe roles: the sites the task acts on, by name; a URL starts with "{role}", and a run binds each role to an origin.
incidentalmap of stringOrigins the pages only touch (a CDN, analytics), by name; they appear in request patterns and are not assigned at run time.
inputsmap of objectrequiredThe values a run takes, by name.
secretsmap of objectThe secrets a run takes, such as a password, by name; only their labels are in the spider.
1 child field
labelstringrequiredWhat the secret is, as a person is asked for it.
outputsmap of objectrequiredThe values a run returns, by name.
2 child fields
type"string" | "number" | "file" | "list"requiredThe type of the value returned.
ofmap of "string" | "number" | "string[]"The fields of each item of the list, by name, with their types.
targetsmap of objectrequiredThe elements the steps act on, by name.
6 child fields
framesLocator[][]The frames the element is in, outermost first; each hop is the ranked locators of an iframe or frame.
hostsobject[]The shadow hosts the element is in, outermost first.
2 child fields
cssstringrequiredA CSS selector for the shadow host.
closedtruePresent when the shadow root is closed.
withinstringAnother target the element is looked for in, such as a table row or a dialog.
isobjectThe role or tag the element found must have.
2 child fields
rolestringThe ARIA role the element must have.
tagstringThe HTML tag name the element must have.
manytruePresent when the target is a list of elements, which only extract reads.
The locators that find the element, best first, at least one.
startstringrequiredThe state the run begins in.
entrystringThe URL the run goes to first; by default the URL of the start state's recogniser.
statesmap of objectrequiredThe states the site can be in, by name.
3 child fields
recogniseobjectrequiredWhat tells this state from the others: every rule given must hold.
5 child fields
urlstringThe URL pattern the page's main frame must match.
presentstring[]Targets that must be found.
absentstring[]Targets that must not be found.
whenCondAny other condition, read at once and never waited for.
pagestringThe page recognised; by default "main".
edgesobject[]requiredThe ways out of the state, in order: the first whose condition holds is taken; none ends the run here.
5 child fields
idstringrequiredThe edge's id, unique in the spider.
whenCondThe condition under which the edge is taken; by default always.
maxintegerHow many times a run may take the edge; by default 1.
The steps the edge runs, in order.
tostring[]requiredThe states the run may arrive in; none ends the run after the steps.
notestringA note for the people reading the spider.
interruptsobject[]Detours that may leave from any state, such as a cookie banner, or end the run, such as a CAPTCHA.
5 child fields
idstringrequiredThe interrupt's id, unique in the spider.
The condition that sets it off, in any state.
stepsBlockStep[]The steps it runs, none of them a submit; then the run goes on from the state it was in.
stopstringThe reason the run ends instead, such as a CAPTCHA or new terms.
maxintegerHow many times a run may take it.
Step
One step of a block: an action on the page, an extract, or closing a page.
Shared fields
idstringrequiredThe step's id, unique in the spider.
notestringA note for the people reading the spider.
effect"read" | "submit"requiredWhether the step only reads or submits something; required, never defaulted.
untilUntil[]What the step waits for after acting, every one of them.
timeoutMsintegerHow long the step waits, in milliseconds.
opensobjectThe page or the download the step opens.
2 child fields
pagestringThe name the page opened goes by in later steps.
downloadstringThe file output the download is saved as.
dialogobjectThe dialog the step opens, and how it is answered.
4 child fields
kind"alert" | "confirm" | "prompt" | "beforeunload"requiredThe kind of dialog.
messagestringThe message the dialog shows.
answer"accept" | "dismiss"requiredWhether the dialog is accepted or dismissed.
textExprThe text typed into a prompt before accepting it.
cadenceMsnumberrequiredThe time between keys, in milliseconds.
One of
do: "goto"urlstringrequiredThe URL to go to.
pagestringThe page the step acts on; by default "main".
Also takes
id,note,effect,until,timeoutMs,opens,dialog.do: "click"targetstringrequiredThe target the step acts on.
offsetobjectWhere to click in the element; by default its centre.
2 child fields
xnumberrequiredPixels from the left edge.
ynumberrequiredPixels from the top edge.
button"left" | "middle" | "right"The mouse button; by default left.
modifiers("Alt" | "Control" | "Meta" | "Shift")[]The keys held down while clicking.
count1 | 2One click or a double click.
pagestringThe page the step acts on; by default "main".
Also takes
id,note,effect,until,timeoutMs,opens,dialog.do: "hover"targetstringrequiredThe target the step acts on.
pagestringThe page the step acts on; by default "main".
Also takes
id,note,effect,until,timeoutMs,opens,dialog.do: "fill"targetstringrequiredThe target the step acts on.
The value put in the field.
pagestringThe page the step acts on; by default "main".
Also takes
id,note,effect,until,timeoutMs,opens,dialog.do: "type"targetstringrequiredThe target the step acts on.
The value put in the field.
pagestringThe page the step acts on; by default "main".
Also takes
id,cadenceMs,note,effect,until,timeoutMs,opens,dialog.do: "press"targetstringThe target focused before pressing; by default the element in focus.
keysstring[]requiredThe keys pressed in turn, such as "Enter" or "Control+a".
pagestringThe page the step acts on; by default "main".
Also takes
id,note,effect,until,timeoutMs,opens,dialog.do: "select"targetstringrequiredThe target the step acts on.
labelExprThe label of the option selected.
valueExprThe value of the option selected.
pagestringThe page the step acts on; by default "main".
Also takes
id,note,effect,until,timeoutMs,opens,dialog.do: "check"targetstringrequiredThe target the step acts on.
Whether the box ends up checked.
pagestringThe page the step acts on; by default "main".
Also takes
id,note,effect,until,timeoutMs,opens,dialog.do: "choose"targetstringrequiredThe target the step acts on.
The text typed into the field to show the suggestions.
optionstringrequiredThe target of the option to commit.
commit"click" | "keys"requiredHow the option is committed: a click, or arrow keys then Enter.
matchobjectHow the option is picked among the suggestions shown.
3 child fields
The value the option chosen must match.
rule"text" | "address-it" | "comune-it"requiredHow texts are compared: as text, an Italian address, or an Italian comune.
checkstringThe target whose value must match too after the commit; by default the field.
pagestringThe page the step acts on; by default "main".
Also takes
id,cadenceMs,note,effect,until,timeoutMs,opens,dialog.do: "upload"targetstringrequiredThe target the step acts on.
The files uploaded.
pagestringThe page the step acts on; by default "main".
Also takes
id,note,effect,until,timeoutMs,opens,dialog.do: "scroll"targetstringThe target to scroll to, or to scroll within to its end.
to"end" | "target"requiredWhere to scroll: to the end of the page or to the target.
pagestringThe page the step acts on; by default "main".
Also takes
id,note,effect,until,timeoutMs,opens,dialog.do: "extract"targetstringrequiredThe target the step acts on.
intostringrequiredThe output the value read goes into.
pagestringThe page read; by default "main".
readReadHow the element is read; by default its text.
fieldsmap of objectThe fields read from each element of a list target, by output field name.
3 child fields
cssstringrequiredA CSS selector for the field within each element.
readReadHow the field is read; by default its text.
alltruePresent when the field is a list of every match.
Also takes
id,note.do: "close"pagestringrequiredThe page closed.
Also takes
id,note.
Locator
One way to find an element; a target ranks several, best first.
One of
testIdtestIdstringrequiredThe element's test id attribute.
fieldfieldstringrequiredThe name of the form field.
rolerolestringrequiredThe element's ARIA role.
nameExprIts accessible name, exact after collapsing whitespace.
labelThe text of the form field's label.
ididstringrequiredThe element's id attribute.
csstextThe element's visible text.
attrAttribute values the element must have, by attribute name.
frameUrlframeUrlstringrequiredThe URL of the document a frame committed, only in a frame hop.
Cond
A condition on the page or the inputs, read when it is checked.
Shared fields
eqExprHolds when the value equals this one.
neExprHolds when the value differs from this one.
ltnumberHolds when the value is a number less than this one.
lenumberHolds when the value is a number at most this one.
gtnumberHolds when the value is a number greater than this one.
genumberHolds when the value is a number at least this one.
inExpr[]Holds when the value is one of these.
containsExprHolds when the value contains this text.
matchesstringHolds when the value matches this regular expression.
nonEmptytrueHolds when the value is not empty.
One of
inputinputstringrequiredThe name of the input compared.
Also takes
eq,ne,lt,le,gt,ge,in,contains,matches,nonEmpty.valuevaluestringrequiredThe target whose form value is compared.
Also takes
eq,ne,lt,le,gt,ge,in,contains,matches,nonEmpty.texttextstringrequiredThe target whose text is compared.
Also takes
eq,ne,lt,le,gt,ge,in,contains,matches,nonEmpty.urlurlstringrequiredHolds when the main frame's URL matches this pattern.
presentpresentstringrequiredHolds when this target is found on the page.
visiblevisiblestringrequiredHolds when this target is found and visible.
allHolds when every one of these conditions holds.
anyHolds when at least one of these conditions holds.
notHolds when this condition does not.
Until
What a step waits for after acting: a condition, a response, or a navigation.
One of
CondresponseresponsestringrequiredA request, "METHOD {origin}/path", whose response arrives.
statusintegerThe HTTP status the response must have.
navigationnavigationstringrequiredA request, "METHOD {origin}/path", whose document the main frame commits and loads.
Expr
A value: a literal, or the value of an input or a secret in this run.
One of
stringnumberbooleaninputinputstringrequiredThe name of an input: its value in this run.
secretsecretstringrequiredThe name of a secret: its value in this run, only where a secret may go.
Read
How an element is read: its text, its form value, or one of its attributes.
One of
"text" | "value"attrattrstringrequiredThe name of the attribute to read.