bug: document.Refresh() panics if page.Reload() returns nil response #11

Closed
opened 2026-02-14 16:06:09 +00:00 by Claude · 3 comments
Collaborator

Parent: #1

Description

In document.go:58-69:

func (d *document) Refresh() error {
    resp, err := d.page.Reload()
    if err != nil {
        return fmt.Errorf("failed to reload page: %w", err)
    }
    resp.Status() // panics if resp is nil
}

If Playwright's Reload() returns (nil, nil) — which can happen if the page is already navigating or in some edge cases — resp.Status() will cause a nil pointer dereference.

Fix

Add a nil check: if resp == nil { return nil } or treat nil response as an error.

**Parent:** #1 ## Description In `document.go:58-69`: ```go func (d *document) Refresh() error { resp, err := d.page.Reload() if err != nil { return fmt.Errorf("failed to reload page: %w", err) } resp.Status() // panics if resp is nil } ``` If Playwright's `Reload()` returns `(nil, nil)` — which can happen if the page is already navigating or in some edge cases — `resp.Status()` will cause a nil pointer dereference. ## Fix Add a nil check: `if resp == nil { return nil }` or treat nil response as an error.
Claude added the bugpriority/mediumtype/task labels 2026-02-14 16:06:18 +00:00
Author
Collaborator

Starting work on this as part of PR 2 (also includes #10). Will add nil check for resp from Reload() in document.go:Refresh().

Starting work on this as part of PR 2 (also includes #10). Will add nil check for `resp` from `Reload()` in `document.go:Refresh()`.
Author
Collaborator

Work finished. PR: #33

Added nil check for resp from Reload() in document.go:Refresh().

Work finished. PR: #33 Added nil check for `resp` from `Reload()` in `document.go:Refresh()`.
Author
Collaborator

Resolved by PR #33 — added nil guard for resp before calling resp.Status() in document.Refresh().

Resolved by PR #33 — added nil guard for `resp` before calling `resp.Status()` in `document.Refresh()`.
Sign in to join this conversation.