Monitoring
web-research; for feeds use workflows/feed-and-news.md.Latest: v0.1.0
- Added a monitoring workflow for live pages: sample repeatedly in one
webrain_evalcall, then repeat and diff samples across ticks. - Clarified that webrain has no scheduler or cross-call history; use an agent loop for short intervals or external cron/systemd and a file for longer ones.
- Added guidance to re-pin and verify the target on every tick, measure a noise floor, and treat missing or unverified data cautiously.
- Documented tool limits and workarounds, including the eval timeout, video-only
webrain_watch, lack of a change predicate inwebrain_wait, and zero-work batch results. - Added guidance for protected feeds and inventory-style monitoring with
webrain_observe(what="assets").
/monitoring
webrain has no scheduler and keeps no state between calls. Monitoring here is
an agent loop, and saying anything else is a lie the runtime cannot back. There is
no monitor tool, no schedule op, no history store — the ADR's HTTP-cache
paragraph ("scheduled recurring monitoring does not pay for a full download") describes
a caller that does not exist in this build. Do not promise one.
Everything below was measured on live sites (CoinDesk, CoinMarketCap) while building this skill, not inferred.
The working recipe
- One source.
webrain_evalwith a JS loop of ≤25 s returning every sample and the distinct count — not a single read. One call, one series. - The agent repeats that call on its own interval and keeps the series, diffing consecutive samples.
- Longer than 30 s → external cron /
systemdtimer drivingwebrain mcpor the CLI. webrain still remembers nothing between runs; the scheduler owns the history. - Re-
navigate(or assertlocation.href) at the start of every tick. That is the only defence against the target-binding gap below.
Step 1 — the tick
One webrain_eval whose JS samples internally and returns all samples plus the
distinct count. A single read cannot distinguish "unchanged" from "never read".
(async () => {
const sel = '<selector you verified with webrain_eval first>';
const stop = Date.now() + 22000; // stay under the 30 s CDP cap
const seen = [], vals = [];
while (Date.now() < stop) {
const t = (document.querySelector(sel) || {}).textContent || '';
const v = t.trim();
if (v && v !== seen[seen.length - 1]) seen.push(v);
vals.push(v);
await new Promise(r => setTimeout(r, 2000));
}
return JSON.stringify({
url: location.href,
samples: vals.length,
distinct: new Set(seen).size,
series: seen.slice(0, 50),
last: seen[seen.length - 1] || null
});
})()
Read distinct first. distinct === 0 means the selector matched nothing (wrong
element or unmounted page) — not "no change". distinct === 1 over 20 s on a
live price means you sampled a stale node or a hidden duplicate; check the field
against webrain_observe(what="clean") before believing it.
Prices are never read from bare text nodes. Google renders date-grids of prices that pollute raw-text scrapes; read the result card / row container instead. The same rule applies to any grid page.
Step 2 — repeat and diff
The agent re-issues step 1 each interval (webrain_eval again — no new browser, no
new tab, same page). Keep the series in your own reply or in a file; webrain will not.
Threshold on a noise floor, measured, not assumed:
| Signal | Measured | Meaning |
|---|---|---|
| BTC/USD on one source, 20 s | 77,021.60 → 77,022.49 → 77,026.68 | cents-to-dollar drift is noise |
| BTC/USD, CoinDesk vs CoinMarketCap, same minute | 77,015.14 vs 77,021.60 (~$6) | two sources disagree by more than one tick |
| Same page, next tick | 77,003.31 (down $20 from the run above) | the value genuinely moves |
So a tolerance below ~0.1 % will fire on noise, and comparing across two sources will report a "change" that is just the sources disagreeing. Pick one source, one selector, one tolerance, and write the tolerance down before you start.
Step 3 — interval > 30 s
*/5 * * * * cd /path && webrain eval --url https://example.com/x --js-file tick.js >> series.jsonl
or a systemd timer calling the same CLI. Append one JSON line per run; that file is
the history webrain does not keep. For an MCP-only host, call the MCP server from the
scheduler — same tools, same absence of memory.
Step 4 — re-pin the target every tick
Measured: right after webrain_navigate to CoinMarketCap, a follow-up webrain_eval
executed against the arXiv tab that was still open. The reply looked like a
monitoring result and was a different page's DOM. Nothing in the tool surface tells you
which target answered.
Defences, in order:
- Assert the page inside the same eval:
if (!location.href.includes('coinmarketcap')) return JSON.stringify({error:'wrong tab', url: location.href}). webrain_observe(what="state")and compareurlbefore trusting the series.webrain_navigateat the top of the tick rather than relying on the tab still being there.
Treat a series whose url you did not verify as no data at all.
Known gaps — do not design around them silently
| Gap | Evidence | Workaround |
|---|---|---|
webrain_watch is video-only (url = video or local path) | tool schema; no generic page watch | poll with webrain_eval (step 1) |
webrain_eval has a ~30 s CDP timeout | a loop over 30 s returns an error, not partial data | cap at 25 s, return early, repeat |
| Eval may answer on the wrong target | arXiv tab answered after navigating to CMC | assert location.href in the JS (step 4) |
webrain_wait has no change predicate | only ms / selector / text | sample in JS, or the planned until:"text_changed" below |
| No history between calls | no store, no scheduler | the agent's own series / a JSONL append from cron |
webrain_batch can report success with zero work | status:"ok" with ok:0 and Target.createTarget: Failed to open a new tab | check ok/errors, not just status |
The change predicate that does not exist yet
The laziest honest fix inside the tool (not in the agent) is a predicate on the existing wait — no scheduler, no store, no 19th tool:
webrain_interact { action: "wait", until: "text_changed",
selector: "<node>", previous_value: "<last read>",
timeout_ms: 60000 }
→ { status: "ok", changed: true, value: "<new text>" } or { changed: false }
Until that ships, do it in one webrain_eval:
(async () => {
const sel = '<selector>', prev = '<previous value>';
const stop = Date.now() + 22000;
while (Date.now() < stop) {
const v = ((document.querySelector(sel) || {}).textContent || '').trim();
if (v && v !== prev) return JSON.stringify({ changed: true, value: v });
await new Promise(r => setTimeout(r, 1000));
}
return JSON.stringify({ changed: false, value: prev });
})()
Protected / authenticated live feeds
Order books, sports feeds and dashboards behind a wall are real Chrome + persistent
profile + session (webrain launch / webrain_session(op=login)), never the
anonymous retry loop. Read challenge on every navigate: a challenge page is not a
successful navigation, and a series sampled from it is not data.
Inventory mode (links, images, video)
When "monitoring" really means "watch what the page links to / serves", use
webrain_observe(what="assets") — one pass returning:
| Group | What it catches that navigate's links does not |
|---|---|
links.internal / .external | every <a>/<area>: cross-site too, grouped by whether the hostname is the same site; kind = page/pdf/image/video/stream/audio/doc/archive |
links.other_schemes | mailto:, tel:, ftp:, … counted by scheme instead of silently dropped |
images | <img> + srcset + lazy data-src + <picture> + icons/og:image and CSS background-image |
videos | <video>/<audio> src + poster + <source>, known embeds (YouTube/Vimeo/Twitch/…), direct .mp4/.m3u8 links, and HLS/DASH the page actually requested |
counts are the real deduped totals; the arrays are capped by max (default 300).
Use only=links|images|videos when you want one group.
For a whole site in one call:
webrain_batch { op: "assets", urls: [...], max: 20, concurrency: 4 }
max defaults to 20 in batch on purpose: counts plus a sample. Measured on 20
SERP-discovered news sites (real Chrome, concurrency 4): 20/20 pages, 0 errors,
35.9 s wall, and one page carried 116 CSS background images while <img> alone
showed 98 — the backgrounds are not a rounding error.
Three things that test taught, and that a fresh run must check
counts.internal: 0is usually an empty shell, not an empty page. Six of the twenty returned a blank title withscanned < 100(one hadscanned: 0). A page that never mounted has no links to find. Readtitleandscannedbefore concluding anything:title === ''⇒ the DOM you scanned is not the site.- Dedupe before the cap. Counting inside the cap guard makes every site report exactly the limit — 14 of 20 pages "had" exactly 6 internal links. Count into a seen-set, then push into the capped array.
- A long-lived Chrome can refuse new tabs.
Target.createTarget: Failed to open a new tabfor all 20 URLs,PUT /json/new→ HTTP 500, while/json/versionand/json/listanswered fine. The batch still reportedstatus:"ok"withok:0. Start a fresh engine on another port (--remote-debugging-port=9333 --user-data-dir=<fresh>) — do not readstatusand assume it worked.
YouTube watch pages report no videos. The media is blob: URLs served from
googlevideo.com behind MSE, so there is no http URL in the DOM to collect. Use
webrain_observe(what="media", url=...) — that captures the network requests
instead. assets finds embeds and files, media finds streams.
Reporting
State the source URL, the selector, the sampling window, the tolerance, and the tick timestamps. A change claim without those five is unfalsifiable, and the first four are exactly what a later run needs to reproduce it.
