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.

[BUG] browserContext.cookies([urls]) doesn't work when URLs are specified

See original GitHub issue

Context:

  • Playwright Version: 1.7.0
  • Operating System: macOS 10.15.7
  • Node.js version: 12.18.4
  • Browser: All
  • Extra: None

Code Snippet

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch()
  const page = await browser.newPage()
  const URL = 'https://google.com.vn/'
  await page.goto(URL)
  const cookies = await page.context().cookies(URL)
  cookies.map((cookie) => console.log(JSON.stringify(cookie)))
  await browser.close()
})();

Describe the bug

When the URLs params are specified, this method can not get any cookies that affect those URLs (e.g: https://google.com.vn) while If no URLs are specified, this method returns all cookies of https://google.com.vn

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
honglaxcommented, Jan 13, 2021

I’ve tried with Playwright@next but it seems to be unstable between browsers. When I used webkit, the returned cookies is consistent between await page.context().cookies() and await page.context().cookies([urls]). But when I used chromium and specified urls like below lines of code

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch()
  const page = await browser.newPage()
  const URL = 'https://google.com/'
  await page.goto(URL, { waitUntil: 'load' })

  const cookies = await page.context().cookies(URL)
  for (const cookie of cookies) {
    console.log(JSON.stringify(cookie))
  }
  await browser.close()
})();

I just got 1 cookie instead of 2.

0reactions
honglaxcommented, Jan 19, 2021

Thanks for your information.

Read more comments on GitHub >

github_iconTop Results From Across the Web

BrowserContext | Playwright - CukeTest
If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs are returned. browserContext.exposeBinding ......
Read more >
BrowserContext (Playwright - Main Library 1.12.1 API)
If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs are returned.
Read more >
Why can't I get cookie value in Playwright? - Stack Overflow
The reason the first method seemingly does not work is because it returns the headers of the request and responses made. Cookies can...
Read more >
Playwright setCookie - CodeceptJS Community
I.setCookie({cookie}) . I have an error: browserContext.addCookies: Cookie should have a url or a domain/path pair at Connection.
Read more >
Safari Technology Preview Release Notes - Apple Developer
Changed URL breakpoints to also pause when an HTML attribute is set that ... Fixed "no-cache" network error (r286655); Fixed same-site lax cookies...
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