fix: add nil guards to prevent nil-pointer panics
All checks were successful
CI / test (pull_request) Successful in 46s
CI / build (pull_request) Successful in 47s
CI / vet (pull_request) Successful in 59s

- document.go: check if resp is nil before calling resp.Status() in
  Refresh(), since Playwright's Reload() can return a nil response
- archive.go: check SelectFirst() results for nil before calling
  Type() and Click(), preventing panics when DOM elements are missing

Closes #10, #11

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-15 16:13:43 +00:00
parent 49f294e884
commit 6c68062e56
2 changed files with 13 additions and 3 deletions

View File

@@ -104,15 +104,25 @@ func (c Config) Archive(ctx context.Context, b extractor.Browser, target string)
return nil, fmt.Errorf("failed to open url: %w", err)
}
err = doc.SelectFirst("input[name='url']").Type(u.String())
urlInput := doc.SelectFirst("input[name='url']")
if urlInput == nil {
_ = doc.Close()
return nil, fmt.Errorf("failed to find url input element")
}
err = urlInput.Type(u.String())
if err != nil {
_ = doc.Close()
return nil, fmt.Errorf("failed to type url: %w", err)
}
err = doc.SelectFirst("form#submiturl input[type=\"submit\"]").Click()
submitBtn := doc.SelectFirst("form#submiturl input[type=\"submit\"]")
if submitBtn == nil {
_ = doc.Close()
return nil, fmt.Errorf("failed to find submit button")
}
err = submitBtn.Click()
if err != nil {
_ = doc.Close()
return nil, fmt.Errorf("failed to click submit: %w", err)