Implementation:1broseidon Ketch crawl hostJSStats
| Knowledge Sources | |
|---|---|
| Domains | Crawl, Adaptive_Strategy |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
Per-host JS-shell statistics that escalate a crawler to browser rendering once a host's pages are overwhelmingly JS shells.
Description
The crawler records each page's JS-detection result (`"static"`/`"likely_shell"`/`"ambiguous"`) under the page's host in a mutex-guarded `hostJSStats{total, shells}` map. shouldForceBrowser returns true when a host has ≥10 total pages and >80% are shells, so the crawler switches to `BrowserScrape` for that host's remaining HTML pages without re-running the detector. This avoids the repeated HTTP-then-browser round-trip on sites that are uniformly client-rendered.
Usage
Internal to the crawler's `processItem`. Not called by external code; documented because the threshold is the crawl's key adaptive heuristic.
Code Reference
Source Location
- Repository: ketch
- File: crawl/crawl.go
Signature
type hostJSStats struct {
total int
shells int
}
// recordJSDetection records one page's JS detection under its host.
func (c *crawler) recordJSDetection(rawURL, detection string)
// shouldForceBrowser reports whether the host's shell ratio crossed the threshold.
func (c *crawler) shouldForceBrowser(rawURL string) bool
Import
// internal to the crawl package
import "github.com/1broseidon/ketch/crawl"
I/O Contract
Inputs (shouldForceBrowser)
| Name | Type | Required | Description |
|---|---|---|---|
| rawURL | string | Yes | A page URL whose host is checked |
Outputs (shouldForceBrowser)
| Name | Type | Description |
|---|---|---|
| return | bool | true when total >= 10 AND shells/total > 0.8 |
Usage Examples
Escalation Within the Worker
c.recordJSDetection(item.url, fr.JSDetection)
if c.shouldForceBrowser(item.url) {
page, html, err = scraper.BrowserScrape(ctx, item.url)
} else {
// normal HTTP path with JS-shell detection
}