playwright-go icon indicating copy to clipboard operation
playwright-go copied to clipboard

[Bug]: Unable to obtain response data

Open youfak opened this issue 1 year ago • 2 comments

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

youfak avatar Sep 02 '24 10:09 youfak

Handle it in another gorountine

func handleResponse(res playwright.Response) {
  go func() {
    ...
  }()
}
}

or refer to this

canstand avatar Sep 04 '24 07:09 canstand

Wow, spent half a day to find out that I need to run a separate routine here.

gate4ai-alex avatar Apr 02 '25 23:04 gate4ai-alex