Created
June 3, 2022 21:55
-
-
Save tyrm/eec2df65d941c804fec2eb2ebb80e835 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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