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

Fix context.clearCookies #1040

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ func (b *BrowserContext) ClearCookies() error {
clearCookies := storage.
ClearCookies().
WithBrowserContextID(b.id)
if err := clearCookies.Do(b.ctx); err != nil {
if err := clearCookies.Do(cdp.WithExecutor(b.ctx, b.browser.conn)); err != nil {
ka3de marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("clearing cookies: %w", err)
}
return nil
Expand Down
7 changes: 7 additions & 0 deletions examples/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ export default async function () {
'the second filtered cookie name should be baz': c => c.name === 'baz',
'the second filtered cookie value should be 44': c => c.value === '44',
});

// clear cookies
context.clearCookies();
cookies = context.cookies();
check(cookies.length, {
'number of cookies should be zero': n => n === 0,
});
} finally {
page.close();
}
Expand Down
26 changes: 26 additions & 0 deletions tests/browser_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,32 @@ func TestBrowserContextCookies(t *testing.T) {
}
}

func TestBrowserContextClearCookies(t *testing.T) {
t.Parallel()

// add a cookie and clear it out

tb := newTestBrowser(t, withHTTPServer())
p := tb.NewPage(nil)
bctx := p.Context()

err := bctx.AddCookies(
[]*api.Cookie{
{
Name: "test_cookie_name",
Value: "test_cookie_value",
URL: "http://test.go",
},
},
)
require.NoError(t, err)
require.NoError(t, bctx.ClearCookies())

cookies, err := bctx.Cookies()
require.NoError(t, err)
require.Emptyf(t, cookies, "want no cookies, but got: %#v", cookies)
}

func TestK6Object(t *testing.T) {
t.Parallel()

Expand Down
Loading