Implementation:1broseidon Ketch extract Detector
| Knowledge Sources | |
|---|---|
| Domains | Extraction, JS_Detection |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
Classifies raw HTML as `"static"`, `"likely_shell"`, or `"ambiguous"` to decide whether the fast HTTP fetch suffices or a browser render is needed.
Description
The Detector decides whether a page is a JavaScript shell requiring browser rendering. DetectJSShellFromDoc runs in two phases. Phase 1 collects visible text and meaningful blocks in one pass: ≥200 chars of visible text is "static" unless a "loading" page override or a strong client-rendered hydration/streaming marker and script payload dwarfing visible text escalate it. Phase 2 (low-text pages) looks for cheap DOM-local corroborators before paying for a full-source lowercase. The result drives the browser fallback and the crawl's adaptive browser escalation.
The zero value matches only built-in framework markers; `NewDetector` folds in operator-configured `spa_markers`.
Usage
Constructed once per Scraper. `DetectJSShell` takes raw HTML; `DetectJSShellFromDoc` takes a pre-parsed goquery doc (the crawler reuses it for link extraction). The package-level `DetectJSShell` uses a default detector (built-in markers only).
Code Reference
Source Location
- Repository: ketch
- File: extract/detect.go
Signature
type Detector struct {
extraMarkers []string
}
func NewDetector(extraMarkers []string) *Detector
func DetectJSShell(rawHTML string) string
func DetectJSShellFromDoc(doc *goquery.Document, rawHTML string) string
func (d *Detector) DetectJSShell(rawHTML string) string
func (d *Detector) DetectJSShellFromDoc(doc *goquery.Document, rawHTML string) string
Import
import "github.com/1broseidon/ketch/extract"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| doc | *goquery.Document | Yes (FromDoc) | Pre-parsed document |
| rawHTML | string | Yes | Raw HTML source (for corroborator checks) |
Outputs
| Name | Type | Description |
|---|---|---|
| return | string | "static" (has content), "likely_shell" (needs browser), or "ambiguous" |
Usage Examples
Fast-Path Decision
doc, _ := goquery.NewDocumentFromReader(strings.NewReader(html))
detection := detector.DetectJSShellFromDoc(doc, html)
if detection == "likely_shell" {
html, source = scraper.MaybeBrowserFetch(ctx, url, html)
}
Operator SPA Markers
// config spa_markers are lowercased and folded in on top of the built-ins.
detector := extract.NewDetector(cfg.SPAMarkers)