@trawlme/skills 1.4.11 → 1.4.12
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
|
@@ -127,7 +127,7 @@ try {
|
|
|
127
127
|
One run has a **time budget**: about **10 minutes**. Count it from before your script starts: a scheduled or web-app run may queue for a worker first, inside that budget, and the guard below leaves about 3 minutes for it. A run you wait on through the API (`trawl scraps trigger --wait`, the n8n node) starts its 10 minutes when your script starts instead; keep the guard anyway, the same script also runs on a schedule. 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`.
|
|
128
128
|
|
|
129
129
|
- 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.
|
|
130
|
-
- 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).
|
|
130
|
+
- 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). Between two requests to the same host, wait a random pause of 1.5 s or more (`1500 + Math.random() * 1000` ms), never a fixed one: that pause is rate-limit politeness (`references/anti-patterns.md`), never an anti-bot mechanism, never a wait for the page.
|
|
131
131
|
- A catalog that cannot fit one run is still scrapable:
|
|
132
132
|
- **targeted** — only the items you need, by search or by their URLs (passed as a param), not the whole catalog;
|
|
133
133
|
- **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).
|
|
@@ -142,7 +142,7 @@ for (const url of productUrls) { // your list, e.g. from a param or a sitemap
|
|
|
142
142
|
break;
|
|
143
143
|
}
|
|
144
144
|
// … fetch one product (awaited), push it to rows
|
|
145
|
-
await new Promise((r) => setTimeout(r, 1000)); // politeness between requests
|
|
145
|
+
await new Promise((r) => setTimeout(r, 1500 + Math.random() * 1000)); // politeness between requests
|
|
146
146
|
}
|
|
147
147
|
returnData(rows);
|
|
148
148
|
```
|
|
@@ -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.
|
|
25
|
+
Bot detection decides at the fingerprint level — milliseconds before any timing signal exists. `Math.random() * 500` delays have no effect. A random pause of 1.5 s or more between two requests to the same host (`1500 + Math.random() * 1000` ms, never a fixed one, never shorter) is for **rate-limit politeness** only, never 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. The one exception is the
|
|
33
|
+
`page.waitForTimeout(N)` is deprecated. `setTimeout` is unreliable under load and slows every run unconditionally. The one exception is the random pause of 1.5 s or more between two requests to the same host (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
|