# Watches

> How watches work - freshness targets and scheduling, comparisons and ignore rules, confirmation re-reads, reversals, health states and retention.

A watch is a standing order: keep this page fresh to within a time you choose,
and tell me when it changes or stops being readable. Each read is an ordinary
[job](https://netscrapehq.com/docs/jobs.md), so everything a job does (render modes, robots.txt, pacing,
retries, quotas and result storage) applies to watches too.

## Creating and updating

Create a watch with `POST /v1/watches`:

```http
POST /v1/watches
Authorization: Bearer <key>
Content-Type: application/json

{
  "external_id": "source-123",
  "labels": ["catalogue", "region:north"],
  "request": {
    "url": "https://example.com/catalogue",
    "render": "auto",
    "output": "document",
    "policy": {"robots": true}
  },
  "compare": {
    "on": "text",
    "confirm_changes": true,
    "ignore_selectors": [".rotating-banner"],
    "ignore": [{"pattern": "(?i)updated.*", "unless": "important"}]
  },
  "freshness": {"max_age": "1d", "min_interval": "1h"},
  "lifecycle": {"gone_after": 2, "on_gone": "keep_checking", "follow_moves": "same_site"},
  "schedule": "auto",
  "emit_checks": false
}
```

- **`external_id`** and **`labels`** are your own strings. Netscrape doesn't
  interpret them. Sending an `external_id` you've used before updates that
  watch instead of creating another, so enrolment is safe to repeat.
- **`PATCH /v1/watches/:id`** takes the same fields. Fields you leave out keep
  their values. `request` replaces the whole request; `compare` and `lifecycle`
  merge with what's there.
- Changing the request or the comparison starts a new baseline: the next read
  becomes the current version without a comparison against the old rules.
- Creating a watch again with the `external_id` of a retired watch brings that
  watch back, with its history, as `active` and `pending`.

## The request

`request` is the body a one-off job takes; see [Jobs](https://netscrapehq.com/docs/jobs.md#parameters).
A watch keeps reading the whole page, so a few things are refused with
`400 invalid_watch_request`:

- `type` other than `scrape` (discovery watches are coming later);
- a `deadline`, which belongs to a single job;
- `fetch.method: "HEAD"`, and `range`, `if-none-match` or `if-modified-since`
  headers.

Render options a worker can't run are refused with `400 unsupported_option`,
as they are for jobs.

## Freshness and scheduling

| Field | Meaning |
| --- | --- |
| `freshness.max_age` | Required. How stale the page may get: Netscrape reads it at least this often while it's active and readable. From 1 hour to 90 days. |
| `freshness.min_interval` | The most often Netscrape may read it, including when you ask. At least 1 hour and no more than `max_age`. Defaults to `max_age`. |
| `schedule` | `auto` (default): Netscrape schedules reads. `manual`: you do; see [manual watches](#manual-watches). |

Durations are whole seconds or strings such as `"6h"` or `"14d"` (hours or days).
Responses give them in seconds.

- A new watch's first read is spread across its first interval, so watches
  created together aren't read together.
- Later reads land between 80% and 100% of `max_age`, never sooner than
  `min_interval`.
- Waiting for a site's turn, a full queue and failure backoffs can push a read
  later than `max_age`. `next_check_at`, `health` and the pending job say why.
- The scheduler runs every minute and takes due watches from each account in
  turn, so one account's backlog can't hold back another's.
- Watch reads use at most half of each site's hourly and daily budget, so your
  one-off jobs on the same site still get through. See
  [Politeness](https://netscrapehq.com/docs/politeness.md#per-site-pacing).

You can also ask for a read now with `POST /v1/watches/:id/check`. It's refused
with `429 check_rate_limited` within `min_interval` of the last read, and with
`409 check_pending` while a read is still in flight.

## Comparisons

`compare.on` chooses what a read is compared on:

| Mode | Compares | Good for |
| --- | --- | --- |
| `text` (default) | The page's visible body text, normalised and masked | Most HTML pages |
| `bytes` | The raw response bytes | PDFs, images, feeds, exact copies |
| `extract` | The values your request's `extract` rules read | Pages where only certain fields matter |

`text` and `extract` need `output` to be `body` or `document`; `extract` also
needs `extract` rules in the request. In `extract` mode, a selector that stops
matching becomes `null` and the version is flagged `extract_empty`, and each
`watch.changed` event lists the `fields` that changed with their before and
after values.

### Masks and ignore rules

In `text` mode Netscrape compares body text, not titles, JSON-LD or contact
links, and first removes common noise from each line:

- relative times such as "3 days ago";
- "last updated …" lines;
- copyright years such as "© 2025–2026";
- long hex or base64 tokens (32 characters or more);
- query strings on stylesheet, script, image and font URLs.

Add your own rules for anything else:

- **`ignore`**: up to 20 rules, each a regular expression `pattern` (up to
  1,000 bytes) removed from every line. An optional `unless` pattern protects
  lines that match it from that rule and from the built-in masks, so you can
  mask timestamps everywhere except on lines that carry the value you watch.
  A pattern may backtrack only so far on one line. One that backtracks without
  end, such as the nested repeat in `(a+)+$`, is stopped there, and the check
  fails with `evaluation_error` rather than being compared without the rule.
- **`ignore_selectors`**: up to 20 CSS selectors whose elements are removed
  before the text is built, such as a reviews widget or a rotating banner.

A read whose compared text comes out empty counts as a failed read
(`empty_document`), not as a change.

## Confirmation re-reads

Some pages change on every read: carousels, A/B tests, "featured" blocks. A
confirmation re-read stops those from reaching you.

- With `compare.confirm_changes: true`, every change is read again ten minutes
  later. `watch.changed` is sent only if the second read agrees.
- Without it, a first-time change is sent at once; only
  [reversals](#reversals) are confirmed.
- With `compare.confirm_changes: false`, nothing is confirmed and Netscrape makes
  no confirmation re-reads: every change, reversals included, is sent at once.
- Every `watch.changed` carries `confirmed`: `true` only when a second read
  agreed before it was sent.
- A confirmation re-read uses no credits. It's the only read that may come
  sooner than `min_interval`.
- A [manual watch](#manual-watches) gets no confirmation re-reads: your next
  attached job confirms the change, or drops it as `flapping`. That read is
  yours, so it's charged like any other.
- A read you ask for is charged even when it confirms a change. That includes
  the read that answers a resync, on an `auto` watch too.
- If the re-read disagrees, the check is recorded as `flapping`, no event is
  sent, and the watch keeps its last confirmed version. The next scheduled read
  tries again, so a state that settles later is still reported.
- After three unconfirmed flips in the last ten checks, the watch is marked
  `noisy: true` and you get a `watch.noisy` event, so you can add ignore rules.
  Netscrape never widens your rules on its own.

## Reversals

A page that goes 50 → 60 → 50 has changed twice, and anyone holding 60 needs to
hear about the return to 50. Netscrape keeps the fingerprints of a watch's last
eight versions. A read that returns to one of them is always confirmed by a
re-read unless `confirm_changes` is `false`. If it holds, `watch.changed` is sent
with `reversal: true` and the `earlier_version` it matches.

A state that holds across a confirmation is never hidden.

## Health states

Health is what Netscrape last saw. It's separate from `status`, which you
control.

| Health | Enters when (defaults) | Reads while in it |
| --- | --- | --- |
| `pending` | Created, re-enrolled, or robots.txt allows the page again | First eligible read |
| `healthy` | A read succeeds (2xx, no challenge) | Normal schedule |
| `failing` | 3 failed reads in a row, spanning at least 24 hours | After 1 h, 4 h, 1 day, 2 days, then every `max_age` |
| `gone` | 2 reads at least 24 hours apart answer 404, 410 or no such domain, or a move that isn't followed | Every 7 days, or your `max_age` if longer; or the watch pauses with `on_gone: "pause"` |
| `blocked` | 2 reads in a row answer 403 or 406, or show a challenge | After 1 day, 3 days, 7 days, then every 14 days |
| `robots_disallowed` | robots.txt refuses the page | Only robots.txt is re-read, at most once a day per origin, then weekly after a week; see [robots.txt](https://netscrapehq.com/docs/politeness.md#robotstxt). Page reads resume when it's allowed. |

Every move between states sends `watch.health_changed` with `from`, `to`, a
`reason` and the evidence (status, challenge vendor). Retry delays never come
sooner than `min_interval`. Any successful read returns the watch to `healthy`.

Tune the thresholds per watch in `lifecycle`:

| Option | Default | Range |
| --- | --- | --- |
| `failing_after` | 3 | 1–100 |
| `failing_span` | 86400 seconds | 0–90 days |
| `gone_after` | 2 | 1–100 |
| `gone_spacing` | 86400 seconds | 0–90 days |
| `blocked_after` | 2 | 1–100 |
| `on_gone` | `keep_checking` | `keep_checking` or `pause` |
| `follow_moves` | `same_site` | `same_site` or `never` |

Some failures aren't the page's fault, and never change its health: Netscrape's
own faults, a job that expired in the queue, and waits for quota. If Netscrape
can't submit a read at all, for example because a render option is no longer
supported, the watch turns `failing` at once with `evidence.stage: "submission"`
and tries again after `min_interval`; no read happens and nothing is metered.

### Moves

When a read ends on a permanent redirect (301 or 308) instead of following it,
Netscrape sends `watch.moved`. With `follow_moves: "same_site"`, a move to the
same host updates the watch's URL, up to three times. Otherwise the move is
reported with `followed: false` and counts toward `gone`.

## Pausing, resuming and retiring

- **Pause** (`POST /v1/watches/:id/pause`) stops scheduling. A read already in
  flight is still recorded, but can't change the watch.
- **Resume** (`POST /v1/watches/:id/resume`) makes the watch due at once, still
  no sooner than `min_interval` after its last read.
- **Bulk** pause and resume take a `label`: `POST /v1/watches/pause` with
  `{"label": "catalogue"}`. The answer's `count` is the number of watches that
  changed state.
- **Retire** (`DELETE /v1/watches/:id`) stops the watch for good. It stays
  readable, with its history, for 90 days.

Suspending an account pauses its active watches. Resume the labels you want
afterwards.

## Delivered checks

An unchanged read sends nothing, but sometimes you need the page anyway: your
own rules changed, or someone asked for a recheck.

- `POST /v1/watches/:id/check` with `{"deliver": true}` reads now.
- `POST /v1/watches/:id/deliver_next` marks the next scheduled read instead; it
  costs nothing extra. The bulk form takes a `label`.
- `POST /v1/watches/resync` asks for a delivered read of every matching watch.

A delivered check always ends in `watch.checked` with `delivered: true`,
`changed`, and a `result_url` for that read, even if the page didn't change or
the read failed. See [resync and recovery](https://netscrapehq.com/docs/events.md#resync-and-recovery).

Set `emit_checks: true` on a watch to get `watch.checked` for every read, not
only delivered ones.

## Manual watches

With `"schedule": "manual"` Netscrape never schedules reads; you do, by adding
`"watch_id"` to your own `POST /v1/jobs` requests. Each such job is judged as a
check of the watch: compared, given a health, turned into events. This lets you
keep your own schedule while Netscrape does the comparison, without reading any
site twice.

- The job's URL and options must match the watch's request, or it's refused
  with `400 watch_request_mismatch`. Attaching to an `auto` watch is
  `400 watch_not_manual`.
- The one-read-in-flight rule and `min_interval` still apply
  (`409 check_pending`, `429 check_rate_limited`).
- Your own `Idempotency-Key` works as usual. Keys starting `watch:` are
  reserved and refused with `400 invalid_idempotency_key`.
- Netscrape never reads a manual watch's pages on its own. A change that needs
  confirming waits for your next attached job, which confirms it or drops it as
  `flapping`. The only thing Netscrape reads by itself is the site's
  `/robots.txt`, published for crawlers, while the watch is
  `robots_disallowed`. `/check` and `resync` read when you ask;
  `deliver_next` rides on your next attached job.
- An attached job without a `policy` reads under the watch's, so it checks
  robots.txt as the watch does.
- Deployments with this behaviour list `deferred_confirmation` in each watch's
  `capabilities`, at the top of `GET /v1/watches`, and in the
  `x-netscrape-capabilities` header of watch API answers.

## Labels and filters

A watch has up to 50 labels, each 1–256 bytes; `external_id` is 1–256 bytes.
List watches with `GET /v1/watches`, filtered by `status`, `health`, `schedule`,
`label`, `url_prefix` or `changed_since`. Labels match exactly. See the
[API reference](https://netscrapehq.com/docs/api.md#list-watches).

## Retention

| Data | Kept |
| --- | --- |
| The watch | While it's active or paused, and 90 days after it's retired |
| Change history (`watch.changed` events, with diffs and field values) | The life of the watch, plus 90 days after it's retired |
| All events in the feed | 30 days |
| Check records | 90 days; unchanged, undelivered checks become daily counts after 30 days |
| The current version, and the compared text used for the next diff | Only the latest; up to 200,000 characters of text |
| Page bodies | 7 days, like every job result |

Only the current version is stored in full. Earlier versions survive as change
events, and the fingerprints of the last eight are kept to spot reversals.
Diffs are capped at 32 KiB and say `truncated: true` when shortened.
