Skip to content

feat(playwright-core): add remove cookies api - #29698

Merged
Pavel Feldman (pavelfeldman) merged 6 commits into
microsoft:mainfrom
PaulTriandafilov:add-remove-cookies-api
Mar 2, 2024
Merged

Pavel Feldman (pavelfeldman) merged 6 commits into
microsoft:mainfrom
PaulTriandafilov:add-remove-cookies-api

Conversation

@PaulTriandafilov

Copy link
Copy Markdown
Contributor

Implements the changes suggested in #29662

This patch contains removeCookies method to remove cookies from BrowserContext by it's names

This patch contains removeCookies method to remove cookies from BrowserContext by it's names
@github-actions

This comment has been minimized.

@PaulTriandafilov

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

async removeCookies(cookieNames: string | string[]): Promise<void> {
const setCookies = await this.cookies();

const newCookiesSet = setCookies.filter(c => !cookieNames.includes(c.name));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like context.removeCookies('long-cookie-name') will remove cookies with names long, cookie and name.

await this._channel.clearCookies();
}

async removeCookies(cookieNames: string | string[]): Promise<void> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functionality you are implementing is more of a "remove cookies by name". I wonder if you'd like to be a bit more proactive and include optional domain and path parameters.

async removeCookies(cookies: { name?: string, domain?: string, path?: string });

that way you could be able to clear all cookies by name, all cookies for a given domain, all cookies for a given path and their combinations:

await context.removeCookies({ name: 'session-id' });
await context.removeCookies({ domain: 'my-origin.com' });
await context.removeCookies({ path: '/api/v1' });
await context.removeCookies({ name: 'session-id', domain: 'my-origin.com' });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for comments! Fixed. Please let me know if there is something else I could change or fix.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

async removeCookies(cookies: {name?: string, domain?: string, path?: string}): Promise<void> {
const setCookies = await this.cookies();

if (!cookies.name && !cookies.domain && !cookies.path)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the call above is a waste if you will early return here
maybe moving the await this.cookies() under?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably throw 'Either name, domain or path are required'. Same should be mentioned in the doc (md file).

return await this.doGetCookies(urls as string[]);
}

async removeCookies(cookies: {name?: string, domain?: string, path?: string}): Promise<void> {

@Smrtnyk Smrtnyk (Smrtnyk) Mar 1, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow I feel like cookies as name of the argument is misleading
If I see cookies I would expect an array of cookies or something
maybe naming it criteria or something similar?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second this, filter would probably be a better name, but we can fix it during the pre-release api review.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, a couple of nits and it is ready to go!

return await this.doGetCookies(urls as string[]);
}

async removeCookies(cookies: {name?: string, domain?: string, path?: string}): Promise<void> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second this, filter would probably be a better name, but we can fix it during the pre-release api review.

async removeCookies(cookies: {name?: string, domain?: string, path?: string}): Promise<void> {
const setCookies = await this.cookies();

if (!cookies.name && !cookies.domain && !cookies.path)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably throw 'Either name, domain or path are required'. Same should be mentioned in the doc (md file).

@github-actions

This comment has been minimized.

@PaulTriandafilov

Copy link
Copy Markdown
Contributor Author

Pavel Feldman (@pavelfeldman) I guess it's done. Please, let me know if I missed something

@github-actions

This comment has been minimized.

Signed-off-by: Pavel Feldman <[email protected]>
@pavelfeldman
Pavel Feldman (pavelfeldman) merged commit 8e48ee7 into microsoft:main Mar 2, 2024
@github-actions

github-actions Bot commented Mar 2, 2024

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

1 failed
❌ [playwright-test] › runner.spec.ts:118:5 › should ignore subprocess creation error because of SIGINT

5 flaky ⚠️ [chromium-library] › library/tracing.spec.ts:243:5 › should not include trace resources from the previous chunks
⚠️ [chromium-library] › library/tracing.spec.ts:243:5 › should not include trace resources from the previous chunks
⚠️ [chromium-library] › library/tracing.spec.ts:243:5 › should not include trace resources from the previous chunks
⚠️ [firefox-library] › library/tracing.spec.ts:243:5 › should not include trace resources from the previous chunks
⚠️ [chromium-library] › library/tracing.spec.ts:243:5 › should not include trace resources from the previous chunks

26696 passed, 614 skipped
✔️✔️✔️

Merge workflow run.

Yusuke Iwaki (YusukeIwaki) added a commit to YusukeIwaki/playwright-ruby-client that referenced this pull request Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants