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
@@ -48,17 +48,18 @@ func DefaultBrowser() Browser {
|
||||
}
|
||||
}
|
||||
|
||||
// navigationHeaders are the headers Chrome sends when the user opens u by
|
||||
// typing it or from a bookmark, in Chrome's order.
|
||||
func (b Browser) navigationHeaders(u *url.URL) http.Header {
|
||||
return http.Header{
|
||||
// navigationHeaders are the headers Chrome sends when the user opens u, in
|
||||
// Chrome's order. Without a referer, u was typed in or opened from a
|
||||
// bookmark. A content type makes it the submission of a form on referer.
|
||||
func (b Browser) navigationHeaders(u, referer *url.URL, contentType string) http.Header {
|
||||
h := http.Header{
|
||||
"sec-ch-ua": {secCHUA(b.Major)},
|
||||
"sec-ch-ua-mobile": {"?0"},
|
||||
"sec-ch-ua-platform": {`"` + b.Platform + `"`},
|
||||
"upgrade-insecure-requests": {"1"},
|
||||
"user-agent": {b.UserAgent},
|
||||
"accept": {"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"},
|
||||
"sec-fetch-site": {"none"},
|
||||
"sec-fetch-site": {fetchSite(u, referer)},
|
||||
"sec-fetch-mode": {"navigate"},
|
||||
"sec-fetch-user": {"?1"},
|
||||
"sec-fetch-dest": {"document"},
|
||||
@@ -66,9 +67,13 @@ func (b Browser) navigationHeaders(u *url.URL) http.Header {
|
||||
"accept-language": {acceptLanguage(u.Hostname())},
|
||||
"priority": {"u=0, i"},
|
||||
http.HeaderOrderKey: {
|
||||
"content-length",
|
||||
"cache-control",
|
||||
"sec-ch-ua",
|
||||
"sec-ch-ua-mobile",
|
||||
"sec-ch-ua-platform",
|
||||
"origin",
|
||||
"content-type",
|
||||
"upgrade-insecure-requests",
|
||||
"user-agent",
|
||||
"accept",
|
||||
@@ -76,12 +81,56 @@ func (b Browser) navigationHeaders(u *url.URL) http.Header {
|
||||
"sec-fetch-mode",
|
||||
"sec-fetch-user",
|
||||
"sec-fetch-dest",
|
||||
"referer",
|
||||
"accept-encoding",
|
||||
"accept-language",
|
||||
"cookie",
|
||||
"priority",
|
||||
},
|
||||
}
|
||||
|
||||
if referer != nil {
|
||||
// Chrome's default referrer policy leaves out the path on requests
|
||||
// to other origins.
|
||||
ref := referer.Scheme + "://" + referer.Host + "/"
|
||||
if sameOrigin(u, referer) { ref = (&url.URL{Scheme: referer.Scheme, Host: referer.Host, Path: referer.Path, RawPath: referer.RawPath, RawQuery: referer.RawQuery}).String() }
|
||||
|
||||
h.Set("referer", ref)
|
||||
}
|
||||
|
||||
if contentType != "" {
|
||||
h.Set("cache-control", "max-age=0")
|
||||
h.Set("content-type", contentType)
|
||||
if referer != nil { h.Set("origin", referer.Scheme+"://"+referer.Host) } else { h.Set("origin", "null") }
|
||||
}
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
// fetchSite is the Sec-Fetch-Site of a navigation to u from referer.
|
||||
func fetchSite(u, referer *url.URL) string {
|
||||
switch {
|
||||
case referer == nil:
|
||||
return "none"
|
||||
case sameOrigin(u, referer):
|
||||
return "same-origin"
|
||||
case u.Scheme == referer.Scheme && site(u.Hostname()) == site(referer.Hostname()):
|
||||
return "same-site"
|
||||
default:
|
||||
return "cross-site"
|
||||
}
|
||||
}
|
||||
|
||||
func sameOrigin(a, b *url.URL) bool {
|
||||
return a.Scheme == b.Scheme && strings.EqualFold(a.Host, b.Host)
|
||||
}
|
||||
|
||||
// site is the registrable domain of host, such as amazon.co.uk.
|
||||
func site(host string) string {
|
||||
s, err := publicsuffix.EffectiveTLDPlusOne(strings.ToLower(host))
|
||||
if err != nil { return strings.ToLower(host) }
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Brand is one entry of Chrome's brand list, which sec-ch-ua and
|
||||
|
||||
Reference in new issue
Block a user