Repository navigation
feat(web): filter browser.cookies() by URL (ENG-1502) - #2250
Merged
Merged
Conversation
Contributor
🟢 e2e web: 95 passedAll 95 tests in 43 files
Tested by e2e 0.24.0 · 1m 7s · web · run artifacts |
Contributor
🟢 e2e web agent: 34 passed36 agent steps · 26 replayed from cache · 26 model calls · 134.7k tokens (93% cached) · $0.0058 All 34 tests in 5 files
Tested by e2e 0.24.0 · 1m 36s · web · run artifacts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
browser.cookies(urls?)takes one URL or a list and returns only the cookies a request to them would carry. Without an argument it returns every cookie, as before..example.comcookie on subdomains too), by path (/adminmatches/admin/users, not/administrator), and bySecure(https, orhttpon a loopback host).gotoand asetCookiesurldo.INVALID_ARGUMENTfor a value that is not a string or a list of strings,POLICY_DENIEDfor a URL that is nothttp(s).Why
The "Signed-in requests" recipe built the
cookieheader by picking one cookie by name and domain out of every cookie in the browser, other sites' included. It missed path scoping and apps with more than one cookie, and a looser pick could send a sign-in provider's cookie to the app. The recipe is nowbrowser.cookies(url)for the URL the request goes to.How it works
browser.cookies(urls)resolves each URL throughcontext.app.resolveUrlbefore the driver call, so a relative URL and the URL rule behave as insetCookies(packages/web/src/browser.ts:843,resolveCookieUrlsinpackages/web/src/cookies.ts:28).setCookiesnow shares the http(s) check throughresolveCookieUrl(cookies.ts:19); its behavior is unchanged.context.cookies(urls), which does the matching. playwright-core 1.65.1 matches host-only and domain cookies, paths on a/boundary, andSecurewith the loopback exception. Dropped alternative: a matcher of our own incookies.ts, which would duplicate what the driver already does.[]without asking the driver, which reads[]as no filter. A list that a test computed and that came out empty must not widen to every site's cookies. This differs from Playwright, wherecontext.cookies([])returns everything.cookieUrlsLabel,cookies.ts:40), likegoto.cookiesreference entry and interface block, the recipe inapi-testing.mdxand its example file, the Playwright and Cypress migrate rows, and the skill (plugins/copy regenerated). Translations are not updated; their old recipe still works.For #1503 to port: WebDriver BiDi's
storage.getCookieshas no URL filter, so that driver needs the matching itself, with the same cases aspackages/web/tests/integration/cookies-url.test.ts: host-only against domain cookies, the path boundary,Securewith the loopback exception, the union over several URLs. The fixture side (resolveCookieUrls, the empty-list rule, the label) names no driver and carries over as is.The provider packages (kernel, lightpanda, moli, notte, browser-run, smol, testmu, e2b) connect through
@e2e-dev/weband get the same fixture. No other package implementsbrowser.Issue
ENG-1502
Verified
Ran it locally: yes
The built CLI on the testbed,
tests/browser.e2e.ts, in Chromium and in Firefox (a scratch config withweb({ browser: 'firefox' })):The failure path, from a scratch test:
packages/web/tests/integration/cookies-url.test.ts: 36 passed, 12 cases each in Chromium, Firefox, and WebKit. With the URL argument dropped from the driver call, 27 of them fail.Securecookie tohttp://localhostandhttp://127.0.0.1, so the loopback exception matches what a request carries.browser.d.tsreviewed; the type assertions are inpackages/web/tests/types/clear-cookies.ts.pnpm check,pnpm --filter @e2e-dev/web run test(1190 passed),pnpm --filter @e2e-dev/testbed test(619 passed).pnpm bench:ab: the change adds one optional argument to one fixture method and touches no shared path.pnpm docs:checkpasses.browser.reload()does not reject offline). This PR does not touch it, and CI runs the testbed in Chromium.Checklist
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it..d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures.e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile.