You have to extract and use the proper cookie format.
- First install this extension called EditThisCookie.
Then export your cookie. You will get an array of cookies.

Use ...
spread to pass all cookies as argument to setCookie
.
await page.setCookie(...cookies)
Done!
If you want to write the cookies, then here is a format for that.
const cookies = [
{
"domain": "localhost", // google.com, yahoo.com etc. Without the host
"hostOnly": true,
"httpOnly": true,
"name": "connect.sid", // here is the actual cookie name
"path": "/",
"sameSite": "no_restriction",
"secure": false,
"session": true,
"storeId": "0",
"value": "s%3AliYZ-M8urEQLfgn2_kSG_FIPwVTr5VQs.5rrJW7hzuXebekzTRgPYFTYri5nljhGCp8Dz%2FgLoSN4", // and the value
"id": 1
}
]
Working example
const cookie = {
name: 'login_email',
value: 'set_by_cookie@domain.com',
domain: '.paypal.com',
url: 'https://www.paypal.com/',
path: '/',
httpOnly: true,
secure: true
}
const puppeteer = require('puppeteer');
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.setCookie(cookie)
await page.goto('https://www.paypal.com/signin')
await page.screenshot({
path: 'paypal_login.png'
})
await browser.close()
If you notice original docs, it shows page.setCookie(...cookies)
cookies with three dots. Which basically means you can pass an array of objects as arguments that way.
How you put the data into cookie variable is upto you, you can hard code it, you can use some database etc. That's not related to how you pass the cookie.
If it's only one cookie like in paypal example, you pass them with page.setCookie(cookie)
, but if it's multiple cookie like you got from exporting using EditThisCookie or the localhost example above, then you have to use the spread operator with three dots like I've explained above.
You can read more about spread and rest on this question.