Russian  English  All projects

Understand the method of downloading cookies



There is a function that loads cookies using the puppeteer-core library




export const setCookies = async (page: Page, cookies: any[]) => {


try {


const client = await page.target().createCDPSession()




const items = cookies


.map((cookie) => {


const item = { ... cookie }


if (!item.value) item.value =


console.assert(!item.url, `Cookies must have a URL defined`)


console.assert(


item.url !== about:blank,


`Blank page can not have cookie "${item.name}"`,


)


console.assert(


! String.prototype.startsWith.call(item.url || , data:),


`Data URL page can not have cookie "${item.name}"`,


)


return item


})


.filter((cookie) => cookie.name)




await page.deleteCookie(... items).catch()




if (items.length) await client.send(Network.setCookies, { cookies: items })


} catch (err) {


error(err)


}}



When importing cookies (I will send you to the telegram, it is not attached here), there is an exception in the catch block.


Your task


1. Figure out what exactly is wrong with this cookie


2. Implement the possibility of importing such cookies, with error handling


write directly to the personal telegram - @neuro25
The price is negotiable, the task is a small price



05.01.2023 20:21



 Answers freelancers