Skip to content

Commit

Permalink
Migrate screenshoter from deprecated visualViewport to cssVisualViewp…
Browse files Browse the repository at this point in the history
…ort. Fallback to defaults in case of visualViewport is nil
  • Loading branch information
olegbespalov committed Dec 11, 2024
1 parent 40795d5 commit 3e28115
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions common/screenshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,27 +175,38 @@ func (s *screenshotter) screenshot(

// Add clip region
//nolint:dogsled
_, visualViewport, _, _, _, _, err := cdppage.GetLayoutMetrics().Do(cdp.WithExecutor(s.ctx, sess))
_, _, _, _, visualViewport, _, err := cdppage.GetLayoutMetrics().Do(cdp.WithExecutor(s.ctx, sess))
if err != nil {
return nil, fmt.Errorf("getting layout metrics for screenshot: %w", err)
}

visualViewportScale := 1.0
visualViewportPageX, visualViewportPageY := 0.0, 0.0
// we had a null pointer panic cases, when visualViewport is nil
// instead of the erroring out, we fallback to defaults and still try to do a screenshot
// ideally this case also should be logged
if visualViewport != nil {
visualViewportScale = visualViewport.Scale
visualViewportPageX = visualViewport.PageX
visualViewportPageY = visualViewport.PageY
}

if doc == nil {
s := Size{
Width: viewport.Width / visualViewport.Scale,
Height: viewport.Height / visualViewport.Scale,
Width: viewport.Width / visualViewportScale,
Height: viewport.Height / visualViewportScale,
}.enclosingIntSize()
doc = &Rect{
X: visualViewport.PageX + viewport.X,
Y: visualViewport.PageY + viewport.Y,
X: visualViewportPageX + viewport.X,
Y: visualViewportPageY + viewport.Y,
Width: s.Width,
Height: s.Height,
}
}

scale := 1.0
if viewport != nil {
scale = visualViewport.Scale
scale = visualViewportScale
}
clip = &cdppage.Viewport{
X: doc.X,
Expand Down

0 comments on commit 3e28115

Please sign in to comment.