Docs/API reference

Watch · Node.js

Poll selected fields and deliver detected changes to application callbacks.

Download .md
Developers3 min read10 sections
Source reference · Match your SDK version. Availability and known issues
In this guide

Purpose and lifecycle

The first successful sample establishes a baseline; later samples are compared with it. Stop the watcher explicitly when the worker shuts down.

Node run takes an error-first callback. Python registers callbacks with on_change and typed event helpers; run blocks and run_async uses an executor.

Set a positive interval in whole seconds. Zero is not a supported polling interval. Callback delivery and baseline state are not a durable event log.

Definition and availability

Source snapshot: 1.0.0-alpha.3. Package export. Declared in source; this is not a runtime test result.

Signatures and source locations are generated from the SDK wrappers. Clean snapshots link to the recorded commit. Modified snapshots link to main, which may differ; file hashes identify the local inputs.

export class Watch
typescript1 lines · copy-ready

Usage example

Use a matching source build. Where a snippet uses page, obtain it with the Page example first. Example URLs illustrate API shape; they are not promised datasets.

import { Watch } from 'crawlingo';
const watch = new Watch('https://example.com/').field('title', 'h1').interval(60);
watch.run((error, event) => {
  if (error) { console.error(error); return; }
  console.log(event.field, event.oldValue, event.newValue);
});
process.once('SIGINT', () => watch.stop());
typescript7 lines · copy-ready

Members

MemberKindReturn / value typeSource status
constructormethodWatchPresent in source
fieldmethodthisPresent in source
intervalmethodthisPresent in source
runmethodvoidPresent in source
stopmethodvoidPresent in source

constructor()

Create a monitor with a URL and optional session. Add fields and callbacks before starting the polling loop with run.

Returns / value: Watch.

constructor(url: string, session?: Session): Watch
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
urlstringRequiredHTTP(S) source URL; verify the target is appropriate for your application.
sessionSession | undefinedOptionalShared request state. Omit only where the signature provides a default.

field()

Add a named field to compare between polls. Configure all fields before starting.

Returns / value: this.

field(name: string, selector: string, options?: { selectorType?: "css" | "xpath"; defaultVal?: string; }): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
namestringRequiredField, header or attribute name for this operation.
selectorstringRequiredSelector evaluated against the fetched DOM.
options{ selectorType?: "css" | "xpath"; defaultVal?: string; } | undefinedOptionalOptional settings object. Its inline signature lists the accepted keys and types.

interval()

Set a positive poll interval in seconds. This is not a request timeout.

Returns / value: this.

interval(seconds: number): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
secondsnumberRequiredTime in seconds; see the method-specific range and timing semantics.

run()

Start polling. Node returns immediately and delivers callbacks; Python blocks.

Returns / value: void.

run(callback: (err: Error | null, event: WatchChangeEvent) => void): void
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
callback(err: Error | null, event: WatchChangeEvent) => voidRequiredApplication callback; check errors before consuming results.

stop()

Request cancellation of the polling loop. It does not erase a separately owned dataset directory.

Returns / value: void.

stop(): void
typescript1 lines · copy-ready

Errors and operational limits

Node reports poll failures to the callback. Handle err before reading the event. Python native polling logs some failures; it is not equivalent to a rejected DatasetJob.

Source availability, package publication and runtime validation are separate facts. These pages describe the source snapshot, not a claim that all platforms or every API path have passed production acceptance.