puppeteer-sharp icon indicating copy to clipboard operation
puppeteer-sharp copied to clipboard

Page.GetCookiesAsync does not return all the cookies

Open heinsenberg82 opened this issue 4 years ago • 3 comments

The method Page.GetCookiesAsync() doesn't return all the cookies showed in the Chrome Dev Tools. After googling this issue, i found a nice explanation on Stack Overflow (https://stackoverflow.com/questions/49389775/puppeteers-page-cookies-not-retrieving-all-cookies-shown-in-the-chrome-dev-to/59604510). So basically the cookie i want is probably an httpOnly cookie, wich is not retrieved by the "Network.getCookies" command performed by the Page.GetCookiesAsync() method.

My humble suggestion would be adding an method called Page.GetAllCookiesAsync(), with this implementation:

public async Task<CookieParam[]> GetAllCookiesAsync(params string[] urls) => (await Client.SendAsync<NetworkGetCookiesResponse>("Network.getAllCookies", new NetworkGetCookiesRequest { Urls = urls.Length > 0 ? urls : new string[] { Url } }).ConfigureAwait(false)).Cookies;

In other words, just a clone of the already existing Page.GetCookiesAsync() method, but with the "Network.getAllCookies" call instead of the "Network.getCookies".

heinsenberg82 avatar Dec 13 '21 20:12 heinsenberg82

Thank you for the insight and the time to go through it. I think that makes sense. I would like to implement that on the original puppeteer library so we are in sync. We shouldn't have any API that doesn't match an upstream one.

kblok avatar Dec 14 '21 13:12 kblok

Thank you for the insight and the time to go through it. I think that makes sense. I would like to implement that on the original puppeteer library so we are in sync. We shouldn't have any API that doesn't match an upstream one.

Thanks for the feedback! Meanwhile, I found a workaround. Since the Page.GetCookiesAsync() accepts an array of urls as optional parameter, I've just inspected and passed all the urls of the cookies I needed.

heinsenberg82 avatar Dec 15 '21 03:12 heinsenberg82

It depends on https://github.com/puppeteer/puppeteer/issues/6916

kblok avatar Oct 17 '22 12:10 kblok