fix(deps): migrate to chromedp 0.19 and drop the cdproto replace

Update chromedp to v0.19.1 and cdproto to v0.157.4, port the browser, reader and login code to the generic Action API, group both modules in Renovate, and move the Docker build to Go 1.27.
This commit is contained in:
2026-10-05 10:32:22 +01:00
parent 5d945156ba
commit 956aa3c0cb
9 changed files with 67 additions and 91 deletions
+6 -7
View File
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"github.com/chromedp/cdproto/cdp"
"github.com/chromedp/chromedp"
)
@@ -13,8 +12,8 @@ import (
// a separate chromedp.Run so a slow extraction does not re-do navigation.
func (r *Reader) extractHTML(ctx context.Context, selector string) (string, error) {
if selector == "" {
var html string
if err := chromedp.Run(ctx, chromedp.OuterHTML("html", &html, chromedp.ByQuery)); err != nil {
html, err := chromedp.Run(ctx, chromedp.OuterHTML(chromedp.CSS("html")))
if err != nil {
return "", fmt.Errorf("read document: %w", err)
}
return html, nil
@@ -22,16 +21,16 @@ func (r *Reader) extractHTML(ctx context.Context, selector string) (string, erro
// Verify the selector matches at least one node; an empty result is
// almost always a caller mistake, not an empty page.
var nodes []*cdp.Node
if err := chromedp.Run(ctx, chromedp.Nodes(selector, &nodes, chromedp.ByQuery)); err != nil {
nodes, err := chromedp.Run(ctx, chromedp.Nodes(chromedp.CSS(selector)))
if err != nil {
return "", fmt.Errorf("locate %q: %w", selector, err)
}
if len(nodes) == 0 {
return "", fmt.Errorf("selector %q matched no elements", selector)
}
var html string
if err := chromedp.Run(ctx, chromedp.OuterHTML(selector, &html, chromedp.ByQuery)); err != nil {
html, err := chromedp.Run(ctx, chromedp.OuterHTML(chromedp.CSS(selector)))
if err != nil {
return "", fmt.Errorf("extract %q: %w", selector, err)
}
return html, nil
+11 -8
View File
@@ -94,12 +94,12 @@ func (r *Reader) Read(parentCtx context.Context, opts ReadOptions) (*ReadResult,
// Build the action chain. Cookies were already applied by NewContext
// (if a session exists). localStorage is applied post-navigation
// because it is origin-scoped.
actions := []chromedp.Action{
actions := []chromedp.Action[chromedp.Void]{
chromedp.Navigate(opts.URL),
chromedp.WaitReady("body"),
}
if statePath != "" {
actions = append(actions, chromedp.ActionFunc(func(ctx context.Context) error {
actions = append(actions, chromedp.Func(func(ctx context.Context, _ *chromedp.Target) error {
return browser.ApplyLocalStorageOnCurrentOrigin(ctx, statePath)
}))
}
@@ -109,14 +109,17 @@ func (r *Reader) Read(parentCtx context.Context, opts ReadOptions) (*ReadResult,
chromedp.Sleep(500*time.Millisecond),
)
if opts.WaitSelector != "" {
actions = append(actions, chromedp.WaitVisible(opts.WaitSelector, chromedp.ByQuery))
actions = append(actions, chromedp.WaitVisible(chromedp.CSS(opts.WaitSelector)))
}
actions = append(actions,
chromedp.Title(&title),
chromedp.Location(&finalURL),
)
actions = append(actions, chromedp.Func(func(ctx context.Context, t *chromedp.Target) (err error) {
if title, err = chromedp.Title()(ctx, t); err != nil {
return err
}
finalURL, err = chromedp.Location()(ctx, t)
return err
}))
if err := chromedp.Run(cdpCtx, actions...); err != nil {
if err := chromedp.Do(cdpCtx, actions...); err != nil {
return nil, fmt.Errorf("navigate: %w", err)
}