Skip to content

chrome.socket.Page.CaptureScreenshot

Michael Kenney edited this page Sep 29, 2018 · 1 revision
package main

import (
	chrome "github.com/mkenney/go-chrome/tot"
	"github.com/mkenney/go-chrome/tot/emulation"
	"github.com/mkenney/go-chrome/tot/page"
)

func main() {
	var err error

	// ... snip ... //

	// Set the device emulation parameters
	metricsOverride := <-tab.Emulation().SetDeviceMetricsOverride(
		&emulation.SetDeviceMetricsOverrideParams{
			Width:  1440,
			Height: 1440,
			ScreenOrientation: &emulation.ScreenOrientation{
				Type:  emulation.OrientationType.PortraitPrimary,
				Angle: 90,
			},
		},
	)
	if nil != metricsOverride.Err {
		panic(metricsOverride.Err.Error())
	}

	// Capture the current screenshot
	screenshot := <-tab.Page().CaptureScreenshot(
		&page.CaptureScreenshotParams{
			Format:  page.Format.Jpeg,
			Quality: 50,
		},
	)
	if nil != screenshot.Err {
		panic(screenshot.Err.Error())
	}
}