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
+17 -13
View File
@@ -22,6 +22,7 @@ var (
yellow = lipgloss.NewStyle().Foreground(lipgloss.Color("11"))
red = lipgloss.NewStyle().Foreground(lipgloss.Color("9"))
blue = lipgloss.NewStyle().Foreground(lipgloss.Color("12"))
magenta = lipgloss.NewStyle().Foreground(lipgloss.Color("13")).Bold(true)
selected = lipgloss.NewStyle().Reverse(true)
flashing = lipgloss.NewStyle().Background(lipgloss.Color("10")).Foreground(lipgloss.Color("0")).Bold(true)
)
@@ -34,14 +35,14 @@ var columns = []struct {
title string
min, max int
} {
{"ITEM", 8, 32},
{"SHOP", 4, 12},
{"TLD", 3, 6},
{"STATUS", 9, 9},
{"PRICE", 5, 16},
{"SELLER", 6, 11},
{"LAST", 10, 10},
{"NEXT", 9, 9},
{"ITEM", 8, 32},
{"SHOP", 4, 12},
{"TLD", 3, 6},
{"STATUS", 11, 11},
{"PRICE", 5, 16},
{"SELLER", 6, 11},
{"LAST", 10, 10},
{"NEXT", 9, 9},
}
// layout sizes the table and the log pane to the window.
@@ -160,6 +161,8 @@ func statusStyle(status string) lipgloss.Style {
return green
case statusBlocked:
return yellow
case statusNeedsHuman:
return magenta
case statusError:
return red
case statusPaused:
@@ -208,10 +211,11 @@ func (m *Model) statusBar() string {
status string
style lipgloss.Style
} {
{statusAvailable, green},
{statusBlocked, yellow},
{statusError, red},
{statusPaused, faint},
{statusAvailable, green},
{statusNeedsHuman, magenta},
{statusBlocked, yellow},
{statusError, red},
{statusPaused, faint},
} {
if n := m.count(s.status); n > 0 { parts = append(parts, s.style.Render(fmt.Sprintf("%d %s", n, s.status))) }
}
@@ -233,7 +237,7 @@ func (m *Model) statusBar() string {
func (m *Model) help() string {
if m.logFocus { return "↑↓ pgup pgdn scroll · l/esc back to the table · r reload · q quit" }
return "↑↓ select · p pause · P pause all · c check now · o open page · enter cart · l log · r reload · q quit"
return "↑↓ select · p pause · P pause all · c check now · o open page · enter cart or bot check · l log · r reload · q quit"
}
// count is the number of rows showing status.