@trawlme/skills 1.2.1 → 1.2.3
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 +1 -1
- package/skills/trawl-cli/SKILL.md +4 -0
- package/skills/trawl-scrap-account/SKILL.md +10 -4
- package/skills/trawl-scrap-design/SKILL.md +14 -3
- package/skills/trawl-scrap-design/references/anti-patterns.md +6 -0
- package/skills/trawl-scrap-design/references/interaction-patterns.md +23 -0
- package/skills/trawl-scrap-local-test/SKILL.md +9 -0
package/package.json
CHANGED
|
@@ -81,10 +81,14 @@ trawl scraps update <id> -d "Updated description" # update what it doe
|
|
|
81
81
|
trawl scraps update <id> --no-cron # disable schedule
|
|
82
82
|
trawl scraps update <id> --alert ops@example.com # email on failure
|
|
83
83
|
trawl scraps update <id> --no-alert # disable alerts
|
|
84
|
+
trawl scraps update <id> --autofix # enable AI Fix (auto-repair on failure) — @trawlme/cli@1.11.0+
|
|
85
|
+
trawl scraps update <id> --no-autofix # disable AI Fix
|
|
84
86
|
trawl scraps update <id> -p '{"key":"page","value":"2"}' # add a param (JSON object)
|
|
85
87
|
trawl scraps update <id> --params-file ./params.json # bulk params from file
|
|
86
88
|
```
|
|
87
89
|
|
|
90
|
+
> **GTM seed scraps:** always run `trawl scraps update <id> --autofix --cron '0 0 * * 0'` post-create (weekly schedule + AI Fix enabled).
|
|
91
|
+
|
|
88
92
|
### Run / trigger / watch
|
|
89
93
|
|
|
90
94
|
- `trawl scraps run <id>` — synchronous run, blocks until done
|
|
@@ -19,7 +19,7 @@ Injecting cookies does not change the worker's fingerprint policy.
|
|
|
19
19
|
|
|
20
20
|
2. **One-shot test or short-lived experiment, or you want to verify your cookies work before setting up persistence** → use **Flavour A — Embedded BYO-cookies**. Hard-code the cookie array directly in the script body. Accepts the trade-off that cookies are in plain text in the script source.
|
|
21
21
|
|
|
22
|
-
3. **MFA, SSO, OAuth, or you don't want to hand credentials to Trawl** → use **Flavour B — Persisted BYO-cookies**. Export cookies from a logged-in browser session, push them into `account.session.cookies` via
|
|
22
|
+
3. **MFA, SSO, OAuth, or you don't want to hand credentials to Trawl** → use **Flavour B — Persisted BYO-cookies**. Export cookies from a logged-in browser session, push them into `account.session.cookies` via UI, CLI, or API, and the script reads them back before navigation. Cookies are encrypted at rest.
|
|
23
23
|
|
|
24
24
|
## Trawl-managed credentials (legacy flow)
|
|
25
25
|
|
|
@@ -78,11 +78,17 @@ await page.goto('https://example.com/dashboard', { waitUntil: 'domcontentloaded'
|
|
|
78
78
|
|
|
79
79
|
## Flavour B — Persisted BYO-cookies
|
|
80
80
|
|
|
81
|
-
Export cookies from a logged-in browser session
|
|
81
|
+
Export cookies from a logged-in browser session. Three write paths exist for `account.session.cookies` (any one is fine; the scrap source reads them back identically):
|
|
82
|
+
|
|
83
|
+
- **UI** (one-off / interactive): scrap settings drawer → Account section → **Upload session cookies** → paste a Puppeteer cookie JSON array → Save.
|
|
84
|
+
- **CLI** (scripted / batch): `trawl scraps account session set <scrap-id> --cookies <file>` (npm `@trawlme/cli` ≥ 1.14.0).
|
|
85
|
+
- **API** (custom tooling): `PUT /api/scraps/:scrapId/account/session` with body `{ cookies: [...] }`.
|
|
86
|
+
|
|
87
|
+
The worker encrypts them at rest; the script reads the same global as the managed flow:
|
|
82
88
|
|
|
83
89
|
```js
|
|
84
90
|
if (!account.session?.cookies) {
|
|
85
|
-
throw new Error('Flavour B requires account.session.cookies — push them via
|
|
91
|
+
throw new Error('Flavour B requires account.session.cookies — push them via UI / CLI / API first.');
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
const page = await browser.newPage();
|
|
@@ -90,7 +96,7 @@ await page.setCookie(...account.session.cookies);
|
|
|
90
96
|
await page.goto('https://example.com/dashboard', { waitUntil: 'domcontentloaded' });
|
|
91
97
|
```
|
|
92
98
|
|
|
93
|
-
|
|
99
|
+
See `references/cookie-injection.md` for domain matching, HttpOnly export, localStorage, and expiry handling.
|
|
94
100
|
|
|
95
101
|
## Anti-patterns to avoid
|
|
96
102
|
|
|
@@ -33,6 +33,12 @@ const ADD_TO_CART_SEL = '[role="button"][aria-label="Add to cart"]';
|
|
|
33
33
|
const price = await page.$eval(PRICE_SEL, (el) => el.textContent.trim());
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
**Avoid obfuscated hash classes** (`css-1a2b3c`, styled-components like `fPSBzf`) — they rotate every deploy. When the only classes are hashes:
|
|
37
|
+
- prefer `data-*` / `aria-*` / `role` / semantic tags (`<article>`, `<address>`) / `time[datetime]`
|
|
38
|
+
- module-CSS (stable prefix + hash suffix) → match the prefix: `[class*="ListingCard_price"]`
|
|
39
|
+
- `aria-label` often encodes the value (`[aria-label*="Current price"]`) — more stable than any class
|
|
40
|
+
- **JSON beats DOM**: `window.__NEXT_DATA__` (Next.js SSR) and JSON-LD (`script[type="application/ld+json"]`, schema.org) carry the data pre-render — use as primary, DOM as fallback.
|
|
41
|
+
|
|
36
42
|
## Waits
|
|
37
43
|
|
|
38
44
|
- **`page.waitForSelector(selector)`** — most targeted; use as the default.
|
|
@@ -88,6 +94,8 @@ if (!category) throw new Error('Missing required param: category (set in Setting
|
|
|
88
94
|
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
|
89
95
|
```
|
|
90
96
|
|
|
97
|
+
**URL hygiene**: a page can return HTTP 200 with a soft-404 ("page not found") body — verify *content*, not status. Prefer search/category URLs over guessed deep-link IDs (product/hotel IDs go stale). Pre-wire locale in the URL (`/en/`, `intl=nosplash`, country path) to skip region splashes.
|
|
98
|
+
|
|
91
99
|
## Resilience
|
|
92
100
|
|
|
93
101
|
Wrap each logical field in its own `try/catch` and return what you have. Throw only for structural failures that make the entire run meaningless.
|
|
@@ -101,9 +109,8 @@ try {
|
|
|
101
109
|
// continue — return partial data with price: null
|
|
102
110
|
}
|
|
103
111
|
|
|
104
|
-
// Structural failure:
|
|
105
|
-
|
|
106
|
-
if (bodyText.includes('Access Denied')) throw new Error('Access denied — escalate proxy tier');
|
|
112
|
+
// Structural failure: required param missing — throw immediately
|
|
113
|
+
// Do NOT sniff for bot-challenge markers ("Access Denied", "Just a moment") — see anti-patterns.md
|
|
107
114
|
```
|
|
108
115
|
|
|
109
116
|
**Throw only for:**
|
|
@@ -111,6 +118,10 @@ if (bodyText.includes('Access Denied')) throw new Error('Access denied — escal
|
|
|
111
118
|
- Page never loaded or returned a fatal error
|
|
112
119
|
- Required param missing
|
|
113
120
|
|
|
121
|
+
## Hard anti-bot sites
|
|
122
|
+
|
|
123
|
+
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, you can pin a higher tier from the start so the first run doesn't waste a cycle; the top tier passes most protections. That's the whole knob. Don't try to outsmart protection in your script — return what you can and let the platform escalate.
|
|
124
|
+
|
|
114
125
|
## Anti-patterns (don't do this)
|
|
115
126
|
|
|
116
127
|
Full detail in `references/anti-patterns.md`. Summary:
|
|
@@ -56,6 +56,12 @@ Source: [rebrowser.net/blog/xpath-vs-css-selectors-a-comprehensive-guide-for-web
|
|
|
56
56
|
|
|
57
57
|
---
|
|
58
58
|
|
|
59
|
+
## Don't detect bot-challenges in your script
|
|
60
|
+
|
|
61
|
+
Do NOT sniff for challenge markers to throw — e.g. `if (html.includes('px-captcha')) throw …` or checking for "Just a moment" / "Access Denied". Two reasons: (1) it **false-throws on pages that actually loaded** (the marker can be present in benign markup, or the challenge already cleared), killing good runs; (2) it isn't your job — the platform handles bot-detection and auto-escalates on empty results. **Throw only on structural failure** (required param missing, page genuinely never loaded). If the content selector times out, return what you have (often `[]`) and let the platform escalate.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
59
65
|
## No silent catch on data writes
|
|
60
66
|
|
|
61
67
|
Never swallow extraction errors silently:
|
|
@@ -4,6 +4,29 @@
|
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
+
## Dismiss first-visit interstitials (before the content wait)
|
|
8
|
+
|
|
9
|
+
Consent (GDPR) modals and language/region splashes block the content `waitForSelector`. Dismiss FIRST, then wait for cards.
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
// click the consent/region button by text, then let the page settle
|
|
13
|
+
await page.evaluate(() => {
|
|
14
|
+
const rx = /^(accept all|allow all|agree|tout accepter|united states|continue)/i;
|
|
15
|
+
const b = [...document.querySelectorAll('button,[role="button"],a')]
|
|
16
|
+
.find(el => rx.test((el.textContent||'').trim()) && el.offsetParent);
|
|
17
|
+
if (b) b.click();
|
|
18
|
+
});
|
|
19
|
+
await page.waitForNetworkIdle({ idleTime: 800, timeout: 8000 }).catch(() => {});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## waitUntil: 'load' for redirect-heavy pages
|
|
25
|
+
|
|
26
|
+
`domcontentloaded` can fire before a post-load redirect settles → `page.evaluate` throws "execution context destroyed". Use `waitUntil:'load'` when the URL changes after navigation (auth/locale redirects).
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
7
30
|
## Scroll to trigger lazy-load
|
|
8
31
|
|
|
9
32
|
Use `window.scrollBy` in a loop; wait for new content, stop when the item count stabilises.
|
|
@@ -62,6 +62,15 @@ No changes to the script body are needed to run it locally.
|
|
|
62
62
|
2. `trawl scraps update <id> -r "$(cat scrap.js)"` (see the `trawl-cli` skill for full CLI usage).
|
|
63
63
|
3. `trawl scraps run <id> --watch` to confirm the worker behaves the same.
|
|
64
64
|
|
|
65
|
+
## Headless vs headed-remote — which to trust
|
|
66
|
+
|
|
67
|
+
- `--headless` tests script wiring fast, but its automation fingerprint trips bot-walls that a real browser never sees → **false `len=0`**. Do not conclude "this site is walled" from a headless empty result.
|
|
68
|
+
- To validate **selectors + returnData logic** under a real fingerprint, run `--remote` against a manually-launched Chrome (no `--enable-automation` flag): `--remote-debugging-port=9222 --user-data-dir=/tmp/chrome-trawl`, then `run-local.mjs scrap.js --remote`. This is the truth signal for *script logic* (not the worker network surface).
|
|
69
|
+
|
|
70
|
+
## `len=0` is ambiguous — classify, don't assume "wall"
|
|
71
|
+
|
|
72
|
+
An empty result has 5 causes: real bot-wall · first-visit interstitial (consent/region) · wrong/stale selector on a page that renders fine (most common) · dead/wrong URL (soft-404 — `curl 200` ≠ content exists) · auth wall. **Capture the page title + a screenshot + visible body text and read it** before deciding — the title usually reveals which. `page.screenshot()` + `document.title` + `body.innerText.slice(0,600)`.
|
|
73
|
+
|
|
65
74
|
## Limitations (intentional)
|
|
66
75
|
|
|
67
76
|
- Local runs use the user's IP — no proxy tier, no fingerprint policy.
|