I need to get a JSSESSIONID cookie from one page and pass it to another. But when I try to fetch cookie with a playwright I got an empty array. Any ideas?
const browser = await playwright[browserType].launch();
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(link);
const elementHandle = await page.$('#putfocushere');
await elementHandle.type(searchNumber);
console.log(await context.cookies(page.url()))
Access it through BrowserContext, which you can get through page.context(), e.g.
await page.context().cookies();
Have you tried doing await context.cookies() without specifying any origin? More than likely, this is happening because the value returned by page.url() isn't an exact match. You can try getting all the cookies and then filtering by your domain.
There is also context.storageState() that is now available in playwright, which will return all cookies and localstorage. See here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With