Closed ctinkong closed 7 months ago
If you just need cookies, page.Context().Cookies()
should work. If you need request headers, request.AllHeaders()
should work.
Note, do not block request:
chanReq := make(chan playwright.Request, 1)
page.OnRequest(func(r playwright.Request) {
// do not block request
go func() {
chanReq <- r
}()
})
// handle request in another goroutine
go func() {
req := <-chanReq
headers, err := req.AllHeaders()
if err != nil {
log.Print(err)
} else {
log.Print(headers)
}
}()
OK,I get it.The way I used is problematic.
request.AllHeaders() will block
page.OnRequest(func(r playwright.Request) { // r.AllHeaders() is blocking headers, _ := r.AllHeaders() })
Am I right? Thank you.
如果您只需要 cookie,应该可以工作。如果您需要请求标头,应该可以工作。
page.Context().Cookies()``request.AllHeaders()
请注意,不要阻止请求:
chanReq := make(chan playwright.Request, 1) page.OnRequest(func(r playwright.Request) { // do not block request go func() { chanReq <- r }() }) // handle request in another goroutine go func() { req := <-chanReq headers, err := req.AllHeaders() if err != nil { log.Print(err) } else { log.Print(headers) } }()
If you just need cookies,
page.Context().Cookies()
should work. If you need request headers,request.AllHeaders()
should work.Note, do not block request:
chanReq := make(chan playwright.Request, 1) page.OnRequest(func(r playwright.Request) { // do not block request go func() { chanReq <- r }() }) // handle request in another goroutine go func() { req := <-chanReq headers, err := req.AllHeaders() if err != nil { log.Print(err) } else { log.Print(headers) } }()
OK,I get it.The way I used is problematic.
request.AllHeaders() will block
page.OnRequest(func(r playwright.Request) { // r.AllHeaders() is blocking headers, _ := r.AllHeaders() })
Am I right? Thank you.
right, currently all OnSomeEvent
may have the same issue (playwrigh-go only). Hope it can be solved later.
right, currently all
OnSomeEvent
may have the same issue (playwrigh-go only). Hope it can be solved later.
I tried, but unfortunately, req.AllHeaders() blocked.
chanReq := make(chan playwright.Request, 1)
page.OnRequest(func(r playwright.Request) {
// do not block request
go func() {
chanReq <- r
}()
})
// handle request in another goroutine
go func() {
req := <-chanReq
headers, err := req.AllHeaders() // Here is blocked.
if err != nil {
log.Print(err)
} else {
log.Print(headers)
}
}()
I haven't had the time to dig more but when calling AllHeaders
in a goroutine there be might a race in ActualHeaders
. At least I get a lot of complaints when running with -race
.
use page.Context().Cookies(url) to fix it. thanks.
I want to obtain all the request headers when making an HTTP request. I've tried using
methods within
but I can only retrieve a few headers such as
headers. I am unable to get other headers, such as
I also attempted using
but with the same result. So, how can I retrieve all the request headers during an HTTP request? Thank you.