Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nil pointer in screenshot #699

Merged
merged 12 commits into from
Aug 28, 2022
4 changes: 4 additions & 0 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ func (p *Page) Screenshot(fullpage bool, req *proto.PageCaptureScreenshot) ([]by
return nil, err
}

if metrics.CSSContentSize == nil {
return nil, errors.New("failed to get css content size")
}

oldView := proto.EmulationSetDeviceMetricsOverride{}
set := p.LoadState(&oldView)
view := oldView
Expand Down
8 changes: 8 additions & 0 deletions page_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/go-rod/rod/lib/devices"
"github.com/go-rod/rod/lib/proto"
"github.com/go-rod/rod/lib/utils"
"github.com/ysmood/gson"
)

func TestGetPageBrowser(t *testing.T) {
Expand Down Expand Up @@ -657,6 +658,13 @@ func TestScreenshotFullPage(t *testing.T) {
g.mc.stubErr(1, proto.EmulationSetDeviceMetricsOverride{})
p.MustScreenshotFullPage()
})

g.Panic(func() {
g.mc.stub(1, proto.PageGetLayoutMetrics{}, func(send StubSend) (gson.JSON, error) {
return gson.New(proto.PageGetLayoutMetricsResult{}), nil
})
p.MustScreenshotFullPage()
ysmood marked this conversation as resolved.
Show resolved Hide resolved
})
}

func TestScreenshotFullPageInit(t *testing.T) {
Expand Down