Handle cookies in request interceptor when cors request was happened
See original GitHub issueSteps to reproduce
Tell us about your environment:
- Puppeteer version: 1.15.0
- Platform / OS version: OSX 10.14.4
- Node.js version: 10.4.1
What steps will reproduce the problem? Try run next code:
await page.goto('http://localhost:3000');
await page.setRequestInterception(true);
await page.setCookie({name: 'userId', value: 'my-user-id'});
page.on('request', interceptedRequest => {
if (interceptedRequest.url().endsWith('/some-api')) { //send cors request to localhost:8080/some-api
const cookie = interceptedRequest.headers()['Cookie']; //undefined
expect(cookie).toContain('userId'); //wrong, because cookie header is undefined
interceptedRequest.continue();
}
});
With next puppeteer configuration:
launch: {
dumpio: process.env.HEADLESS === 'false',
headless: process.env.HEADLESS !== 'false',
slowMo: 20,
args: [
'--disable-web-security',
'--disable-features=IsolateOrigins,site-per-process',
'--disable-site-isolation-trials'
]
}
- Run code above
- Cookie is always empty
What is the expected result? Expect that cookie should contain in request headers
What happens instead? Cookie header is undefined
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:7
Top Results From Across the Web
angular - How to send "Cookie" in request header for all the ...
Following this (and if the authentication is successful), the server will return a cookie in the response. The browser will store this cookie...
Read more >Handling Cookies with Spring Boot and the Servlet API
This article demonstrates how to handle cookies in a Spring Boot or Servlet-based application.
Read more >Top 10 ways to use Interceptors in Angular - Medium
My ten favorite ways to use the interceptor in Angular. With examples of error handling, profiling, caching and more this list will inspire...
Read more >What is CORS (cross-origin resource sharing)? - PortSwigger
These headers state that access is allowed from the requesting domain ( malicious-website.com ) and that the cross-origin requests can include cookies ......
Read more >Angular Interceptors to Manage HTTP Requests
A similar process happens when the server replies. We now have the response being intercepted by the HTTP interceptor, allowing us to perform...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@lavcraft I’m currently using a work-around for this bug by storing the cookies from the page in a variable like this:
You can then use them in with the intercepted request i.e.
Can’t seem to get cookies from
interceptedRequest.headers();
But if you want to get all cookies from page, So you can:It return all cookies from your page