Add session mode: signing in and adding to the cart.
With cart_mode = "session", dibs signs in to the shop's account and puts an item in the cart when it fires. The account's cookies are kept apart from the watcher's and stored encrypted, with the key in the OS keyring. Without a keyring, they're stored in a file only you can read. An alert now goes out right away, without a cart link, and a second one follows once the item is in the cart. If adding fails, the second alert carries the cart link instead. Amazon only accepts additions its page scripts have seen, so plugins can now press a button in headless Chrome with ctx:click. The TUI asks for one-time codes and shows the plugin's warning about account locks in a modal. 'dibs login' signs in from a terminal, or with --browser in a Chrome window, and 'dibs logout' deletes the cookies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e2cbc1a55c
commit
15a34e1f84
39 files changed
+3529
-163
No files matched your search
@@ -3,6 +3,7 @@ package chrome
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"net/url"
|
||||
|
||||
"git.security-command.org/Overlord/dibs/internal/fetch"
|
||||
)
|
||||
@@ -10,6 +11,7 @@ import (
|
||||
// Limiter is ratelimit.Limiter.
|
||||
type Limiter interface {
|
||||
WaitCheck(ctx context.Context, url string) error
|
||||
Wait(ctx context.Context, host string) error
|
||||
}
|
||||
|
||||
// Pipeline fetches pages the way the shops expect a browser to, escalating
|
||||
@@ -28,10 +30,27 @@ func (p *Pipeline) Get(ctx context.Context, rawURL string) (*fetch.Response, err
|
||||
resp, err := p.Client.Get(ctx, rawURL)
|
||||
if err != nil || resp.Verdict != fetch.Challenge || p.Chrome == nil { return resp, err }
|
||||
|
||||
// Chrome's visit is a check of the URL like any other.
|
||||
return p.escalate(ctx, rawURL, resp, func() error { return p.Limiter.WaitCheck(ctx, rawURL) })
|
||||
}
|
||||
|
||||
// Do sends a session request. A GET that runs into a bot check is retried
|
||||
// in headless Chrome like a check, but waits only for the host floor.
|
||||
func (p *Pipeline) Do(ctx context.Context, r fetch.Request) (*fetch.Response, error) {
|
||||
resp, err := p.Client.Do(ctx, r)
|
||||
if err != nil || resp.Verdict != fetch.Challenge || p.Chrome == nil || r.Method != "GET" { return resp, err }
|
||||
|
||||
u, err := url.Parse(r.URL)
|
||||
if err != nil { return nil, err }
|
||||
|
||||
return p.escalate(ctx, r.URL, resp, func() error { return p.Limiter.Wait(ctx, u.Hostname()) })
|
||||
}
|
||||
|
||||
// escalate retries a bot check in headless Chrome once wait allows it.
|
||||
func (p *Pipeline) escalate(ctx context.Context, rawURL string, resp *fetch.Response, wait func() error) (*fetch.Response, error) {
|
||||
p.Logger.Info("bot check, retrying in headless Chrome once the rate limits allow", "url", rawURL, "challenge", resp.Challenge)
|
||||
|
||||
// Chrome's visit is a check of the URL like any other.
|
||||
if err := p.Limiter.WaitCheck(ctx, rawURL); err != nil { return nil, err }
|
||||
if err := wait(); err != nil { return nil, err }
|
||||
|
||||
cr, err := p.Chrome.Fetch(ctx, rawURL)
|
||||
|
||||
|
||||
Reference in new issue
Block a user