fix: add nil guards to prevent nil-pointer panics
- 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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user