Created
May 17, 2020 07:13
-
-
Save NaniteFactory/b181532bdde21a7401f12a0cfcffb421 to your computer and use it in GitHub Desktop.
chromedp full screen shot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func FullScreenshot(quality int64, result *[]byte) chromedp.Action { | |
return chromedp.ActionFunc(func(ctx context.Context) error { | |
// get layout metrics | |
_, _, contentSize, err := page.GetLayoutMetrics().Do(ctx) | |
if err != nil { | |
return err | |
} | |
width, height := int64(math.Ceil(contentSize.Width)), int64(math.Ceil(contentSize.Height)) | |
// force viewport emulation | |
err = emulation.SetDeviceMetricsOverride(width, height, 1, false). | |
WithScreenOrientation(&emulation.ScreenOrientation{ | |
Type: emulation.OrientationTypePortraitPrimary, | |
Angle: 0, | |
}). | |
Do(ctx) | |
if err != nil { | |
return err | |
} | |
// capture screenshot | |
*result, err = page.CaptureScreenshot(). | |
WithQuality(quality). | |
WithClip(&page.Viewport{ | |
X: contentSize.X, | |
Y: contentSize.Y, | |
Width: contentSize.Width, | |
Height: contentSize.Height, | |
Scale: 1, | |
}).Do(ctx) | |
if err != nil { | |
return err | |
} | |
return nil | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment