playwright-go
playwright-go copied to clipboard
[Bug]: Unable to obtain response data
func handleResponse(res playwright.Response) {
statusCode := res.Status()
url := res.URL()
fmt.Printf("Response URL: %s\n", url)
fmt.Printf("Status Code: %d\n", statusCode)
var data jsonResponse
body, err := res.Body()
if err != nil {
fmt.Println("Error getting body:", err)
return
}
err = utils.ConvertStruct(body, &data)
if err != nil {
fmt.Println("Error parsing JSON:", err)
return
}
fmt.Println("Parsed JSON Data:", data)
}
page.OnResponse(handleResponse)
Executing until the step of reading the body will enter a false death state, and the subsequent code cannot be executed
Handle it in another gorountine
func handleResponse(res playwright.Response) {
go func() {
...
}()
}
}
or refer to this
Wow, spent half a day to find out that I need to run a separate routine here.