Repository navigation
feat(playwright-core): add remove cookies api - #29698
Pavel Feldman (pavelfeldman) merged 6 commits into
Conversation
This patch contains removeCookies method to remove cookies from BrowserContext by it's names
This comment has been minimized.
This comment has been minimized.
|
@microsoft-github-policy-service agree |
Pavel Feldman (pavelfeldman)
left a comment
There was a problem hiding this comment.
Looks great!
| async removeCookies(cookieNames: string | string[]): Promise<void> { | ||
| const setCookies = await this.cookies(); | ||
|
|
||
| const newCookiesSet = setCookies.filter(c => !cookieNames.includes(c.name)); |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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' });There was a problem hiding this comment.
Thank you for comments! Fixed. Please let me know if there is something else I could change or fix.
Change removeCookies signature
Fix eslint issues
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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) |
There was a problem hiding this comment.
the call above is a waste if you will early return here
maybe moving the await this.cookies() under?
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
I second this, filter would probably be a better name, but we can fix it during the pre-release api review.
Pavel Feldman (pavelfeldman)
left a comment
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
This should probably throw 'Either name, domain or path are required'. Same should be mentioned in the doc (md file).
Change removeCookies signature and logic
Fix review comments
This comment has been minimized.
This comment has been minimized.
|
Pavel Feldman (@pavelfeldman) I guess it's done. Please, let me know if I missed something |
This comment has been minimized.
This comment has been minimized.
Signed-off-by: Pavel Feldman <[email protected]>
Test results for "tests 1"1 failed 5 flaky26696 passed, 614 skipped Merge workflow run. |
Implements the changes suggested in #29662
This patch contains removeCookies method to remove cookies from BrowserContext by it's names