...
1
2
3
4 package main
5
6 import (
7 "log"
8
9 "github.com/playwright-community/playwright-go"
10 )
11
12 func assertErrorToNilf(message string, err error) {
13 if err != nil {
14 log.Fatalf(message, err)
15 }
16 }
17
18 func main() {
19 pw, err := playwright.Run()
20 assertErrorToNilf("could not launch playwright: %w", err)
21 browser, err := pw.Chromium.Launch()
22 assertErrorToNilf("could not launch Chromium: %w", err)
23 context, err := browser.NewContext()
24 assertErrorToNilf("could not create context: %w", err)
25 page, err := context.NewPage()
26 assertErrorToNilf("could not create page: %w", err)
27 _, err = page.Goto("https://github.com/microsoft/playwright")
28 assertErrorToNilf("could not goto: %w", err)
29 _, err = page.PDF(playwright.PagePdfOptions{
30 Path: playwright.String("playwright-example.pdf"),
31 })
32 assertErrorToNilf("could not create PDF: %w", err)
33 assertErrorToNilf("could not close browser: %w", browser.Close())
34 assertErrorToNilf("could not stop Playwright: %w", pw.Stop())
35 }
36
View as plain text