The `page.setCookie` method should also accept raw cookies
See original GitHub issueSteps to reproduce
Tell us about your environment:
- Puppeteer version: 1.12.2
- Platform / OS version: macOS 10.14.3
- URLs (if applicable):
- Node.js version: 10.15.0
What steps will reproduce the problem?
await page.setCookie('foo=bar');
What is the expected result?
It works.
What happens instead?
It doesn’t.
Not being able to set raw cookies is very inconvenient. There are multiple situations where it would be useful:
- Copy-pasting cookies from DevTools.
- Accepting cookies as user input in a command-line tool.
- Getting cookies from a server request, for example in Express where you read the cookie header, and then pass them to Puppeteer.
Yes, I could find an npm package for this, but the ones I found are not very good (tough-cookie
included). I also think it’s such a basic thing that a big percentage of Puppeteer users will need, that it should be supported by Puppeteer natively.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:9 (2 by maintainers)
Top Results From Across the Web
json - Passing multiple cookies to puppeteer - Stack Overflow
There is only page.setCookie method which allows setting only one cookie at a time. · But it contains a rest and spread operator...
Read more >setcookie - Manual - PHP
setcookie () defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent...
Read more >Page.setCookie() method - Puppeteer
On this page. Page.setCookie() method. Signature:. class Page { setCookie(...cookies: Protocol.Network.CookieParam[]): Promise<void>; }. Parameters ...
Read more >Using HTTP cookies - MDN Web Docs
After receiving an HTTP request, a server can send one or more Set-Cookie headers with the response. The browser usually stores the cookie...
Read more >A Complete Guide to Working With Cookies in Go
Cookies can be written in a HTTP response using the http.SetCookie() function, and read from a HTTP request using the *Request.Cookie() method.
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
Hello, there googler!!
I used the ‘EditThisCookie’ extension that has a nice feature
export
, it will export cookies as JSON, in a perfect format so the puppeteer can consume without any transformation.@sindresorhus in this case
page.evaluateOnNewDocument
would probably work as a workaround.But I guess what you really want is a
browserContext.setCookie(url, 'foo=bar')
method.