...

Source file src/github.com/playwright-community/playwright-go/examples/network-monitoring/main.go

Documentation: github.com/playwright-community/playwright-go/examples/network-monitoring

     1  //go:build ignore
     2  // +build ignore
     3  
     4  package main
     5  
     6  import (
     7  	"fmt"
     8  	"log"
     9  
    10  	"github.com/playwright-community/playwright-go"
    11  )
    12  
    13  func main() {
    14  	pw, err := playwright.Run()
    15  	if err != nil {
    16  		log.Fatalf("could not launch playwright: %v", err)
    17  	}
    18  	browser, err := pw.Chromium.Launch()
    19  	if err != nil {
    20  		log.Fatalf("could not launch Chromium: %v", err)
    21  	}
    22  	page, err := browser.NewPage()
    23  	if err != nil {
    24  		log.Fatalf("could not create page: %v", err)
    25  	}
    26  	page.On("request", func(request playwright.Request) {
    27  		fmt.Printf(">> %s %s\n", request.Method(), request.URL())
    28  	})
    29  	page.On("response", func(response playwright.Response) {
    30  		fmt.Printf("<< %v %s\n", response.Status(), response.URL())
    31  	})
    32  	if _, err = page.Goto("http://todomvc.com/examples/react/", playwright.PageGotoOptions{
    33  		WaitUntil: playwright.WaitUntilStateNetworkidle,
    34  	}); err != nil {
    35  		log.Fatalf("could not goto: %v", err)
    36  	}
    37  	if err = browser.Close(); err != nil {
    38  		log.Fatalf("could not close browser: %v", err)
    39  	}
    40  	if err = pw.Stop(); err != nil {
    41  		log.Fatalf("could not stop Playwright: %v", err)
    42  	}
    43  }
    44  

View as plain text