Missing header in page.on("response")
See original GitHub issueSteps to reproduce
Tell us about your environment:
- Puppeteer version: 1.14
- Platform / OS version: Linux Ubuntu
- URLs (if applicable):
- Node.js version: 10
What steps will reproduce the problem?
Please include code that reproduces the issue.
- Launch server.js
const http = require("http");
const hostname = "127.0.0.1";
const port = 5000;
const server = http.createServer((req, res) => {
if (req.url === "/one") {
res.statusCode = 200;
res.setHeader("Content-Type", "text/html");
res.setHeader("set-cookie", "_one=1");
res.end('<html><script src="http://127.0.0.1:5000/two"></script></html>');
} else if (req.url === "/two") {
res.statusCode = 200;
res.setHeader("Content-Type", "application/javascript");
res.setHeader("set-cookie", "_two=2");
res.end(`console.log('Hello two');`);
}
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
- Launch this puppeteer script
const puppeteer = require("puppeteer");
(async () => {
const browser = await puppeteer.launch({
headless: true
});
const page = await browser.newPage();
page.on("response", response => {
console.log("New response:");
console.log(response.url());
console.log(response.headers());
});
await page.goto("http://127.0.0.1:5000/one", {
waitUntil: "load"
});
await browser.close();
})();
What is the expected result?
We should get the set-cookie
headers for both requests.
What happens instead?
New response:
http://127.0.0.1:5000/one
{ 'content-type': 'text/html',
'set-cookie': '_one=1',
date: 'Mon, 09 Sep 2019 09:59:48 GMT',
connection: 'keep-alive',
'content-length': '62' }
New response:
http://127.0.0.1:5000/two
{ date: 'Mon, 09 Sep 2019 09:59:48 GMT',
connection: 'keep-alive',
'content-length': '25',
'content-type': 'application/javascript' }
The second set-cookie
header is missing.
We can add this lines to the end of the script to confirm the second set-cookie
header was successfully interpreted by the browser (but no visible in the response event).
const client = await page.target().createCDPSession();
console.log(await client.send("Network.getAllCookies"));
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:8
Top Results From Across the Web
`xhr.getAllHeaders()` is missing some headers in a browser ...
In a script running on the popup page, I am making an ajax request. On the first line of my handler for the...
Read more >HTTP response status codes - MDN Web Docs - Mozilla
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:
Read more >Mitigating framesniffing with the X-Frame-Options header
Double-click the HTTP Response Headers icon in the feature list in the middle. In the Actions pane on the right side, click Add....
Read more >HTTP/1.1: Status Code Definitions
There are no required headers for this class of status code. Since HTTP/1.0 did not define any 1xx status codes, servers MUST NOT...
Read more >URL Inspection Tool - Search Console Help - Google Support
Troubleshoot a missing page: There can be many reasons why a page hasn't been ... including a screenshot and HTTP response headers, click...
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
I had this same issue but I managed to find a workaround. The solution is to listen on the
Network.responseReceivedExtraInfo
event suggested by https://github.com/puppeteer/puppeteer/issues/4918#issuecomment-539454771 and extract the cookies from there. I’ve created a class that collects the cookies set in request and looks something like thisIt can be used like this:
NOTE: This collects all cookies, you will need to filter duplicates after Hope this helps
I’ve also run into this and can reproduce it in v1.20. It looks like puppeteer is not listening to the Network.responseReceivedExtraInfo event that contains the raw headers (you can do that yourself to work around the issue). DevTools are doing just that:
It also might be a Chromium bug since this cookie is not really blocked, so IMO it should appear in the
Network.responseReceived
headers.