Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookies: Retrieving and filtering by URLs #6

Closed
9 tasks done
robingustafsson opened this issue Sep 30, 2021 · 2 comments
Closed
9 tasks done

Cookies: Retrieving and filtering by URLs #6

robingustafsson opened this issue Sep 30, 2021 · 2 comments
Assignees
Labels
cookies feature A new feature playwright Issue relating to Playwright compatibility user request Requested by the community

Comments

@robingustafsson
Copy link
Member

robingustafsson commented Sep 30, 2021

Add support for BrowserContext.cookies([urls]), to return all cookies or only cookies for specified URLs in browser context.

Relevant links:

Tasks

  1. cookies refactor
    inancgumus
  2. cookies feature
    inancgumus
  3. refactor security tests
    inancgumus
  4. bug cookies
    inancgumus
  5. cookies feature
    inancgumus
  6. bug cookies
    inancgumus
  7. Area: browser
    inancgumus
  8. browser
    inancgumus
  9. area: browser
    inancgumus
@robingustafsson robingustafsson added feature A new feature playwright Issue relating to Playwright compatibility labels Sep 30, 2021
@robingustafsson robingustafsson changed the title Implement BrowserContext.cookies([urls]) Implement BrowserContext.cookies([urls]) Nov 12, 2021
@robingustafsson
Copy link
Member Author

It might be neat if these cookies could be easily transferred to the protocol-level http.* APIs.

@robingustafsson
Copy link
Member Author

robingustafsson commented Nov 22, 2021

A possible workaround until this API is implemented if the cookie you're trying to access is not a HttpOnly cookie you can use something like this:

import launcher from 'k6/x/browser';

export default function() {
  const browser = launcher.launch('chromium', {
        headless: __ENV.XK6_HEADLESS ? true : false,
	slowMo: '500ms' // slow down by 500ms
  });
  const context = browser.newContext();
  const page = context.newPage();

  page.goto('https://google.com/', { waitUntil: 'networkidle' });
  const cookies = page.evaluate(_ => {
      return Object.fromEntries(document.cookie.split('; ').map(x => x.split(/=(.*)$/,2).map(decodeURIComponent)));
  });
  console.log(JSON.stringify(cookies));

  page.close();
  browser.close();
}

@ka3de ka3de added the user request Requested by the community label Jul 12, 2023
@inancgumus inancgumus self-assigned this Aug 1, 2023
@inancgumus inancgumus modified the milestone: v1.1.0 Aug 17, 2023
@inancgumus inancgumus mentioned this issue Aug 21, 2023
3 tasks
@inancgumus inancgumus changed the title Implement BrowserContext.cookies([urls]) Retrieve cookies by URLs Aug 31, 2023
@inancgumus inancgumus changed the title Retrieve cookies by URLs Retrieve cookies filtered by URLs Aug 31, 2023
@inancgumus inancgumus changed the title Retrieve cookies filtered by URLs Cookies: Retrieving and filtering by URLs Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cookies feature A new feature playwright Issue relating to Playwright compatibility user request Requested by the community
Projects
None yet
Development

No branches or pull requests

3 participants