Comments (6)
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)
}
}()
from playwright-go.
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.
from playwright-go.
right, currently all OnSomeEvent
may have the same issue (playwrigh-go only). Hope it can be solved later.
from playwright-go.
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)
}
}()
from playwright-go.
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
.
from playwright-go.
use page.Context().Cookies(url) to fix it. thanks.
from playwright-go.
Related Issues (20)
- could not launch playwright when updating to v0.4101.0 HOT 5
- Visual comparisons HOT 2
- Ways to pass context from one browser instance to another HOT 2
- Hangs on Content() HOT 3
- Page.Evaluate returns undefined for a specific site HOT 4
- APIRequestContextFetch does not seem to populate cookie and update cookie from response HOT 2
- Assign values to js's variables or Call a js function fail. HOT 1
- Incorrect url pattern for non-release driver versions
- Runtime error during pw.Chromium.Connect
- Randomly Crash Issue on Firefox HOT 1
- Secured Cookies HOT 1
- Jose library has security Vulnurability, can this be upgraded to latest version. HOT 2
- Can't change user-agent on headless mode HOT 1
- [Bug]: access multiple websites. Firefox browser opens multiple windows HOT 1
- [Bug]: hardwareConcurrency is limited to 4 HOT 2
- unable goto ins page
- [Bug]: Using "request. Headers()" in "requestfinished" yields an error message. panic: interface conversion: interface {} is [] map [string] string, not [] interface {}
- [Bug]: Host system is missing dependencies to run browsers - on Ubuntu 24.04 HOT 1
- [Bug]: Open fullscreen without "chrome is being controlled..."
- How does `Evaluate` work? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playwright-go.