Skip to content

Commit

Permalink
Fix nil pointer in screenshot (#699)
Browse files Browse the repository at this point in the history
Fix Panic in Screenshot #631
  • Loading branch information
alexferrari88 committed Aug 28, 2022
1 parent f9df335 commit b4b37ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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()
})
}

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

0 comments on commit b4b37ea

Please sign in to comment.