fix: bug fixes, test coverage, and CI workflow
- Fix Nodes.First() panic on empty slice (return nil) - Fix ticker leak in archive.go (create once, defer Stop) - Fix cookie path matching for empty and root paths - Fix lost query params in google.go (u.Query().Set was discarded) - Fix type assertion panic in useragents.go - Fix dropped date parse error in powerball.go - Remove unreachable dead code in megamillions.go and powerball.go - Simplify document.go WaitForNetworkIdle, remove unused root field - Remove debug fmt.Println calls across codebase - Replace panic(err) with stderr+exit in all cmd/ programs - Fix duckduckgo cmd: remove useless defer, return error on bad safesearch - Fix archive cmd: ToConfig returns error instead of panicking - Add 39+ unit tests across 6 new test files - Add Gitea Actions CI workflow (build, test, vet in parallel) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
27
document.go
27
document.go
@@ -25,30 +25,22 @@ type document struct {
|
||||
pw *playwright.Playwright
|
||||
browser playwright.Browser
|
||||
page playwright.Page
|
||||
root playwright.ElementHandle
|
||||
locator playwright.Locator
|
||||
}
|
||||
|
||||
func newDocument(pw *playwright.Playwright, browser playwright.Browser, page playwright.Page) (Document, error) {
|
||||
root, err := page.QuerySelector("html")
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
root2 := page.Locator("html")
|
||||
locator := page.Locator("html")
|
||||
|
||||
res := &document{
|
||||
node: node{
|
||||
locator: root2,
|
||||
locator: locator,
|
||||
},
|
||||
pw: pw,
|
||||
browser: browser,
|
||||
page: page,
|
||||
root: root,
|
||||
}
|
||||
|
||||
slog.Info("new document", "url", page.URL(), "root", root, "locator", root2)
|
||||
slog.Info("new document", "url", page.URL(), "locator", locator)
|
||||
|
||||
return res, nil
|
||||
}
|
||||
@@ -78,21 +70,14 @@ func (d *document) Refresh() error {
|
||||
}
|
||||
|
||||
func (d *document) WaitForNetworkIdle(timeout *time.Duration) error {
|
||||
|
||||
var f *float64 = nil
|
||||
if timeout == nil {
|
||||
t := 30 * time.Second
|
||||
timeout = &t
|
||||
}
|
||||
|
||||
if timeout != nil {
|
||||
ms := float64(timeout.Milliseconds())
|
||||
f = &ms
|
||||
}
|
||||
|
||||
err := d.page.WaitForLoadState(playwright.PageWaitForLoadStateOptions{
|
||||
ms := float64(timeout.Milliseconds())
|
||||
return d.page.WaitForLoadState(playwright.PageWaitForLoadStateOptions{
|
||||
State: playwright.LoadStateNetworkidle,
|
||||
Timeout: f,
|
||||
Timeout: &ms,
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user