question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Context:

  • Playwright Version: 1.14.1
  • Operating System: Mac
  • Node.js version: 16.14.0
  • Browser: Chromium

Code Snippet

Help us help you! Put down a short code snippet that illustrates your bug and that we can run and debug locally. For example:


const cookieObj = {
  name: "Bearer",
  value: token,
  url: "http://localhost:4000",
}

test.beforeAll(async ({ browser }) => {
  const page = await browser.newPage()
  const context = await browser.newContext()
  await context.addCookies([cookieObj])

  await page.goto(`/#/`, { waitUntil: "networkidle", timeout: 60 * 1000 })

})

Describe the bug

I try to set a cookie but it does not show up in dev tools I have tried this: console.log(await context.cookies()) and it logs the cookie

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
yury-scommented, Apr 25, 2022
 const context = await browser.newContext()
 const page = await context.newPage()
 await context.addCookies([cookieObj])

This solved the problem and now I see the cookie in dev tools

Oh, it makes sense, I missed the fact that you create the page using browser.newPage, that method is a shortcut for creating a new page in a new context, so the code before was equivalent to:

test.beforeAll(async ({ browser }) => {
  const context1 = await browser.newContext()
  const page = await context1.newPage()

  const context = await browser.newContext()
  await context.addCookies([cookieObj])

  await page.goto(`/#/`, { waitUntil: "networkidle", timeout: 60 * 1000 })

})

i.e. the cookies were added to a different context.

0reactions
michelebymancommented, Apr 26, 2022

@yury-s do you mind renaming the issue for future references, ‘how to add cookie in playwright’ ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug Definition & Meaning - Merriam-Webster
The meaning of BUG is any of an order (Hemiptera and especially its suborder Heteroptera) of insects (such as an assassin bug or...
Read more >
Bug (2006) - IMDb
An unhinged war veteran holes up with a lonely woman in a spooky Oklahoma motel room. The line between reality and delusion is...
Read more >
bug - Wiktionary
(entomology) An insect of the order Hemiptera (the “true bugs”). Any of various species of marine or freshwater crustaceans; e.g. a Moreton Bay...
Read more >
Bug - Wikipedia
A terrestrial arthropod animal (with at least six legs). Insect, a six-legged arthropod · Covert listening device, used in surveillance, espionage and policing ......
Read more >
BUG | definition in the Cambridge English Dictionary
bug noun (INSECT) ... an insect: Some tiny white bugs had eaten the leaves of my house plants. ... A bug is also...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found