@trawlme/skills 1.4.7 → 1.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -155,7 +155,7 @@ trawl scraps update <id> --tier tier2 --json # full scrap JSON, o
|
|
|
155
155
|
### Params are scenarios
|
|
156
156
|
|
|
157
157
|
- Params stored on a scrap (`-p` / `--params-file`) are **scenarios**: an array of param sets. Each scheduled, dashboard or `trawl run` run picks **one set at random** — never "the last saved set". Put everything a run needs in each set; sets are alternatives, not additions.
|
|
158
|
-
- To run with your own values instead, use `trawl trigger <id> --param key=value` (repeatable). It is a one-off run: the stored scenarios are left untouched. **Since CLI 3.15.0
|
|
158
|
+
- To run with your own values instead, use `trawl trigger <id> --param key=value` (repeatable). It is a one-off run: the stored scenarios are left untouched. **Since CLI 3.15.0.**
|
|
159
159
|
- Rules: the first stored set defines the schema. Keys are that set's keys, `TRAWL.` prefix optional. Values are typed like the stored value: number, `true`/`false`, or string. Every key is required; blank values and unknown, duplicate or wrongly typed keys are refused with exit 2 (a number error says `must be a number`, a boolean one `must be true or false`; unknown or missing keys list the expected keys). Works with `--wait`, `--watch` and the async default.
|
|
160
160
|
- A scrap without stored params takes no `--param`. A scrap that has params and is triggered without `--param` fails (422 under `--wait`; async, it is acked as queued and exits 0, then the run is dropped with no history row, and `--watch` polls until its 660s timeout, then prints "Timed out waiting for the run to finish" and exits 1; use `--wait` to see the error).
|
|
161
161
|
- `--param` reads the scrap first, so an API key needs `trawl:scraps:read` besides `trawl:scraps:run`. On a scrap without a cron, `trigger` prints a stderr warning that nothing runs it unattended.
|
|
@@ -175,7 +175,7 @@ trawl scraps update <id> --tier tier2 --json # full scrap JSON, o
|
|
|
175
175
|
- `trawl scraps run <id> --watch` — same, then polls for progress (since CLI 1.18.4 — see below; it does **not** stream)
|
|
176
176
|
- `trawl scraps trigger <id>` — **async by default**: queues the worker run and returns immediately (no waiting on the 30-250s run)
|
|
177
177
|
- `trawl scraps trigger <id> --wait` — synchronous: block until the run completes (legacy behaviour). Same timeout as `run` (660s since CLI 3.12.6).
|
|
178
|
-
- `trawl scraps trigger <id> --param key=value` — one-off run with your own param values, see "Params are scenarios" (CLI 3.15.0
|
|
178
|
+
- `trawl scraps trigger <id> --param key=value` — one-off run with your own param values, see "Params are scenarios" (CLI 3.15.0+)
|
|
179
179
|
- `trawl scraps trigger <id> --watch` — queue, then poll for progress (since CLI 1.18.4 — see below; it does **not** stream)
|
|
180
180
|
- `trawl scraps watch <id>` — the standalone command: attach to an in-progress run's activity stream over SSE. **Unchanged** by any of the above — this is the one that actually streams.
|
|
181
181
|
|
|
@@ -81,7 +81,7 @@ returnData([
|
|
|
81
81
|
## Params
|
|
82
82
|
|
|
83
83
|
- **`TRAWL.url`** — the target URL, set by the scrap schedule. Treat as immutable; never override it.
|
|
84
|
-
- **`TRAWL.<custom>`** — a custom parameter of the run. Where it comes from: the scrap's stored params (Settings → Parameters, or `trawl scraps update <id> -p/--params '[{"TRAWL.<name>":"<value>"}]'`, or `--params-file <path>` for bulk — see the `trawl-cli` skill) or the caller's own values (`trawl trigger <id> --param name=value`, CLI 3.15.0
|
|
84
|
+
- **`TRAWL.<custom>`** — a custom parameter of the run. Where it comes from: the scrap's stored params (Settings → Parameters, or `trawl scraps update <id> -p/--params '[{"TRAWL.<name>":"<value>"}]'`, or `--params-file <path>` for bulk — see the `trawl-cli` skill) or the caller's own values (`trawl trigger <id> --param name=value`, CLI 3.15.0+). An on-demand run (`trawl trigger`, the public API, MCP) receives the caller's values instead of a stored set, limited to the keys of the FIRST stored set. Either way the script sees one flat value per key, never the array.
|
|
85
85
|
- **Stored params are scenarios.** The array holds alternative param sets, and each scheduled, dashboard or `trawl run` run receives **one set picked at random**. The script never sees the whole array, so every set must carry every key the script needs, and every set must use the same keys as set 0. A `--param` run replaces the pick with the caller's values for that run only.
|
|
86
86
|
- **Value generators** (written as a param VALUE and resolved server-side on every run before the script starts; the script only reads `TRAWL.<name>`). They are unrelated to the random pick of the stored set above.
|
|
87
87
|
- `RANDOM(a,b,c)` returns one of the comma-separated values, e.g. `{"TRAWL.city":"RANDOM(paris,lyon)"}`. Values are not trimmed, so `RANDOM(a, b)` can yield `" b"`: write no spaces.
|
|
@@ -121,6 +121,31 @@ try {
|
|
|
121
121
|
- Page never loaded or returned a fatal error
|
|
122
122
|
- Required param missing
|
|
123
123
|
|
|
124
|
+
## Run budget
|
|
125
|
+
|
|
126
|
+
One run has a **time budget**: about **10 minutes** from dispatch, and the clock starts before your script does (the run may queue first). Past it the worker stops the run and nothing is returned. Time is almost always the limit, not size: the whole output may reach tens of MB before a run fails with `output too large`.
|
|
127
|
+
|
|
128
|
+
- Add a **deadline guard**: note `Date.now()` at the start, stop about **7 minutes** in, and `returnData` the rows read so far, with `truncated: true` on the last one (the platform reads it as a marker that the run stopped early, not as a data column). The guard runs between requests, so also give each request its own timeout (e.g. `fetch(url, { signal: AbortSignal.timeout(20000) })` inside `page.evaluate`, with a `try`/`catch` that breaks the loop): one stuck page must not carry the run past its budget.
|
|
129
|
+
- Read fewer, cheaper pages: each `page.goto` costs seconds on its own. For lists, prefer same-origin `fetch` from inside the page (`page.evaluate`) on JSON feeds, pagination or search APIs, sitemaps. One request at a time, never parallel tabs or `page.goto`s to the same site (several loads within a few seconds can get the run blocked). Space requests about 1 s apart: that pause is rate-limit politeness (`references/anti-patterns.md`), never a wait for the page.
|
|
130
|
+
- A catalog that cannot fit one run is still scrapable:
|
|
131
|
+
- **targeted** — only the items you need, by search or by their URLs (passed as a param), not the whole catalog;
|
|
132
|
+
- **split** — one scrap per category or section, each small enough for one run; each scrap keeps its own rows. Slices of ONE scrap across runs (a different param per run) replace each other's rows, unless the scrap's `items` option keeps them (`keepData`, set by the Trawl team on request).
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
const started = Date.now();
|
|
136
|
+
const STOP_AFTER_MS = 7 * 60 * 1000;
|
|
137
|
+
const rows = [];
|
|
138
|
+
for (const url of productUrls) { // your list, e.g. from a param or a sitemap
|
|
139
|
+
if (Date.now() - started > STOP_AFTER_MS) {
|
|
140
|
+
if (rows.length) rows[rows.length - 1].truncated = true; // marks where the run stopped
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
// … fetch one product (awaited), push it to rows
|
|
144
|
+
await new Promise((r) => setTimeout(r, 1000)); // politeness between requests
|
|
145
|
+
}
|
|
146
|
+
returnData(rows);
|
|
147
|
+
```
|
|
148
|
+
|
|
124
149
|
## Hard anti-bot sites
|
|
125
150
|
|
|
126
151
|
The platform auto-escalates proxy tiers when a run comes back empty — you usually don't manage tiers at all. For a site you *know* is heavily protected, there are two CLI knobs (see the `trawl-cli` skill for full flag docs):
|
|
@@ -22,7 +22,7 @@ Source: [browser-use.com/posts/bot-detection](https://browser-use.com/posts/bot-
|
|
|
22
22
|
|
|
23
23
|
## No random jitter as primary defence
|
|
24
24
|
|
|
25
|
-
Bot detection decides at the fingerprint level — milliseconds before any timing signal exists. `Math.random() * 500` delays have no effect. Small jitter (200–800ms) is acceptable for **rate-limit politeness** only, never as an anti-bot mechanism.
|
|
25
|
+
Bot detection decides at the fingerprint level — milliseconds before any timing signal exists. `Math.random() * 500` delays have no effect. Small jitter (200–800ms), or a pause of about 1 s between two requests to the same site, is acceptable for **rate-limit politeness** only, never as an anti-bot mechanism.
|
|
26
26
|
|
|
27
27
|
Source: [browser-use.com/posts/bot-detection](https://browser-use.com/posts/bot-detection)
|
|
28
28
|
|
|
@@ -30,7 +30,7 @@ Source: [browser-use.com/posts/bot-detection](https://browser-use.com/posts/bot-
|
|
|
30
30
|
|
|
31
31
|
## No fixed setTimeout / waitForTimeout
|
|
32
32
|
|
|
33
|
-
`page.waitForTimeout(N)` is deprecated. `setTimeout` is unreliable under load and slows every run unconditionally. Use state-based waits:
|
|
33
|
+
`page.waitForTimeout(N)` is deprecated. `setTimeout` is unreliable under load and slows every run unconditionally. The one exception is the ~1 s pause between two requests to the same site (rate-limit politeness, see Run budget in the skill), never a wait for the page. Use state-based waits:
|
|
34
34
|
- `page.waitForSelector(selector)` — most targeted
|
|
35
35
|
- `page.waitForNetworkIdle()` — for SPA-heavy pages
|
|
36
36
|
- `page.waitForFunction(fn)` — for complex DOM conditions
|