Add the Chrome fallback and the needs-human flow.

Bot checks escalate to headless Chrome with stealth, which claims the
same identity as tls-client and hands its cookies back to the jar. The
visit counts against the rate limits. If Chrome can't clear a check,
the URL is marked needs-human. Pressing Enter on it in the TUI, or
running 'dibs solve', opens a visible window; dibs carries on once the
page loads. Processes now merge the cookie file on save, with the
newest cookie winning.
This commit is contained in:
Overlord committed 2026-10-14 14:08:56 +02:00
1 parent f2ea1297e8
commit e2cbc1a55c
20 files changed
+905 -73

No files matched your search

+37 -6
View File
@@ -38,6 +38,9 @@ type Controller interface {
PauseAll(paused bool)
CheckNow(item string) bool
Reload() ([]string, error)
// Solve opens a visible browser on fetchURL for the user to pass its
// bot check. It blocks until the check is passed or the window closes.
Solve(fetchURL string) error
}
// CheckMsg is one finished check and what the alert engine made of it.
@@ -58,15 +61,20 @@ type (
url string
err error
}
solveMsg struct {
host string
err error
}
)
// Status texts, as the STATUS column shows them.
const (
statusWatching = "watching"
statusAvailable = "AVAILABLE"
statusBlocked = "blocked"
statusError = "error"
statusPaused = "paused"
statusWatching = "watching"
statusAvailable = "AVAILABLE"
statusBlocked = "blocked"
statusNeedsHuman = "needs-human"
statusError = "error"
statusPaused = "paused"
)
// result is what the last check of a URL found.
@@ -100,6 +108,7 @@ type Model struct {
noteError bool
noteTime time.Time
reloading bool
solving string // the host whose bot check is open in a browser
}
// New returns the TUI for ctl. path is the config file, and logs is the
@@ -157,6 +166,10 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.widths = nil
m.clampCursor()
if msg.err != nil { m.setNote(reloadError(msg.err), true) } else { m.setNote(reloadNote(msg.summary), false) }
case solveMsg:
m.solving = ""
if msg.err != nil { m.setNote("bot check on "+msg.host+" not solved: "+msg.err.Error(), true) } else { m.setNote("bot check on "+msg.host+" solved, checking again", false) }
m.rows = m.ctl.Statuses()
case openMsg:
if msg.err != nil { m.setNote("cannot open the browser: "+msg.err.Error(), true) } else { m.setNote("opened "+msg.url, false) }
case tea.KeyPressMsg:
@@ -200,6 +213,8 @@ func statusOf(c CheckMsg) string {
switch {
case rep == nil:
return statusError
case rep.Verdict == fetch.NeedsHuman.String():
return statusNeedsHuman
case rep.Verdict == fetch.Challenge.String() || rep.Verdict == fetch.Blocked.String():
return statusBlocked
case c.Result.Err != nil || rep.Verdict == fetch.HTTPError.String():
@@ -285,7 +300,9 @@ func (m *Model) rowKey(k string) tea.Cmd {
case "o":
return open(row.FetchURL)
case "enter":
if r := m.results[row.URL]; r != nil && r.cartLink != "" { return open(r.cartLink) }
r := m.results[row.URL]
if r != nil && r.status == statusNeedsHuman { return m.solve(row) }
if r != nil && r.cartLink != "" { return open(r.cartLink) }
m.setNote("no cart link yet, opening the product page", false)
return open(row.FetchURL)
@@ -294,6 +311,20 @@ func (m *Model) rowKey(k string) tea.Cmd {
return nil
}
// solve opens the row's page in a browser for the user. One bot check is
// open at a time.
func (m *Model) solve(row watch.Status) tea.Cmd {
if m.solving != "" {
m.setNote("a browser is already open for "+m.solving, true)
return nil
}
m.solving = row.Host
m.setNote("pass the bot check in the Chrome window; it closes by itself", false)
return func() tea.Msg { return solveMsg{host: row.Host, err: m.ctl.Solve(row.FetchURL)} }
}
// pauseAll pauses every URL, or resumes them all if all are paused.
func (m *Model) pauseAll() {
pause := false