Skip to content

Instantly share code, notes, and snippets.

@tyrm
Created June 3, 2022 21:55
Show Gist options
  • Save tyrm/eec2df65d941c804fec2eb2ebb80e835 to your computer and use it in GitHub Desktop.
Save tyrm/eec2df65d941c804fec2eb2ebb80e835 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
"github.com/google/uuid"
"github.com/h2non/filetype"
"os"
)
func main() {
path, _ := launcher.LookPath()
u := launcher.New().Bin(path).MustLaunch()
page := rod.New().ControlURL(u).MustConnect().MustPage("https://google.com")
err := page.WaitLoad()
if err != nil {
panic(err)
}
screenshot, err := page.Screenshot(true, nil)
if err != nil {
panic(err)
}
// get type
kind, err := filetype.Match(screenshot)
if err != nil {
panic(err)
}
fmt.Printf("file kind: %s", kind)
file := fmt.Sprintf("/output/%s.png", uuid.New().String())
err = os.WriteFile(file, screenshot, 0644)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment