Skip to content

feat(web): filter browser.cookies() by URL (ENG-1502) - #2250

Merged
okwasniewski merged 2 commits into
mainfrom
oskar/browser-cookies-url
Nov 25, 2026
Merged

okwasniewski merged 2 commits into
mainfrom
oskar/browser-cookies-url

Conversation

@okwasniewski

@okwasniewski okwasniewski commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

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.

const cookies = await browser.cookies('/api/orders');
const headers = { cookie: cookies.map((c) => `${c.name}=${c.value}`).join('; ') };
expect(await request.get('/api/orders', { headers })).toBeOK();
  • A cookie matches by domain (a host-only cookie only on its exact host, a .example.com cookie on subdomains too), by path (/admin matches /admin/users, not /administrator), and by Secure (https, or http on a loopback host).
  • A relative URL resolves against the base URL, as goto and a setCookies url do.
  • An empty list returns no cookies.
  • INVALID_ARGUMENT for a value that is not a string or a list of strings, POLICY_DENIED for a URL that is not http(s).

Why

The "Signed-in requests" recipe built the cookie header 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 now browser.cookies(url) for the URL the request goes to.

How it works

  1. browser.cookies(urls) resolves each URL through context.app.resolveUrl before the driver call, so a relative URL and the URL rule behave as in setCookies (packages/web/src/browser.ts:843, resolveCookieUrls in packages/web/src/cookies.ts:28). setCookies now shares the http(s) check through resolveCookieUrl (cookies.ts:19); its behavior is unchanged.
  2. The resolved list goes to the driver, context.cookies(urls), which does the matching. playwright-core 1.65.1 matches host-only and domain cookies, paths on a / boundary, and Secure with the loopback exception. Dropped alternative: a matcher of our own in cookies.ts, which would duplicate what the driver already does.
  3. An empty list returns [] 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, where context.cookies([]) returns everything.
  4. The step label is the URL as the test wrote it (cookieUrlsLabel, cookies.ts:40), like goto.
  5. Docs: the cookies reference entry and interface block, the recipe in api-testing.mdx and 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.getCookies has no URL filter, so that driver needs the matching itself, with the same cases as packages/web/tests/integration/cookies-url.test.ts: host-only against domain cookies, the path boundary, Secure with 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/web and get the same fixture. No other package implements browser.

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 with web({ browser: 'firefox' })):

✓ |web| tests/browser.e2e.ts > browser fixture > cookies set from the test reach the page and read back 95ms
✓ |web| tests/browser.e2e.ts > browser fixture > cookies(url) returns only the cookies a request to the URL carries 54ms

The failure path, from a scratch test:

× |web| tests/eng1502-fail.e2e.ts > refuses a non-URL
  INVALID_ARGUMENT: browser.cookies takes a URL or an array of URLs, got 42
× |web| tests/eng1502-fail.e2e.ts > refuses about:blank
  POLICY_DENIED: cookie URL must be http(s): about:blank
  • 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.
  • A probe with a local server confirmed all three browsers send a Secure cookie to http://localhost and http://127.0.0.1, so the loopback exception matches what a request carries.
  • Emitted browser.d.ts reviewed; the type assertions are in packages/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).
  • No pnpm bench:ab: the change adds one optional argument to one fixture method and touches no shared path.
  • No docs screenshot: the docs site does not build locally. pnpm docs:check passes.
  • In Firefox the testbed's existing offline test fails (browser.reload() does not reject offline). This PR does not touch it, and CI runs the testbed in Chromium.

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.

View guided diff Turn on auto-fix

@github-actions github-actions Bot added e2e team Opened by the e2e team size:L Up to 499 changed lines, not counting tests, fixtures, translated docs, or the lockfile labels Nov 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🟢 e2e web: 95 passed

All 95 tests in 43 files
Test Time
🟢 tests/aria-hidden-flow.e2e.ts · 2 passed 733ms
🟢 aria hidden flow › picks the Pro plan by its visible text and confirms it 543ms
🟢 aria hidden flow › another plan shows the error and keeps the picker open 190ms
🟢 tests/async-states.e2e.ts · 2 passed 7.0s
🟢 async states › reads the code off the transient toast and verifies it once the button enables 2.2s
🟢 async states › a wrong code is rejected after the toast has gone 4.7s
🟢 tests/canvas-only.e2e.ts · 2 passed 271ms
🟢 canvas only › taps square, circle, then diamond at their pixel coordinates 145ms
🟢 canvas only › a shape out of order paints the error and resets progress 126ms
🟢 tests/canvas-whiteboard.e2e.ts · 2 passed 476ms
🟢 canvas whiteboard › drags both shapes into their slots and saves 257ms
🟢 canvas whiteboard › bounces a shape off the wrong slot and refuses to save early 219ms
🟢 tests/cart-totals.e2e.ts · 2 passed 468ms
🟢 cart totals › increasing a quantity updates the line total but the order summary stays stale (planted bug) 259ms
🟢 cart totals › a quantity never drops below one 209ms
🟢 tests/checkout-review.e2e.ts · 1 passed 205ms
🟢 shows a raw greeting token and an undefined delivery date (planted bug), yet places the order 205ms
🟢 tests/context-menu-trap.e2e.ts · 2 passed 734ms
🟢 context menu trap › right-click opens nothing; the row menu renames the file 368ms
🟢 context menu trap › the decoy menu items refuse and keep the file 366ms
🟢 tests/control-inventory.e2e.ts · 8 passed 4.2s
🟢 control inventory › check sets the checkbox and the radio without flipping a set one 361ms
🟢 control inventory › check picks a radio the pick replaces with its summary 230ms
🟢 control inventory › a long press and a double click are told apart from a tap 1.2s
🟢 control inventory › the file menu opens on right-click only and Rename renames the file 366ms
🟢 control inventory › setInputFiles attaches files named from the project root 250ms
🟢 control inventory › the details view is left through the browser history 298ms
🟢 control inventory › scrollIntoView brings the footnote into view 237ms
🟢 control inventory › every exercise done shows the success message 1.3s
🟢 tests/css-content-ui.e2e.ts · 2 passed 408ms
🟢 css content ui › the tile labelled Ship it advances and confirming ships 242ms
🟢 css content ui › a wrong tile shows the CSS-rendered error and keeps the picker 166ms
🟢 tests/date-picker.e2e.ts · 2 passed 733ms
🟢 date picker › navigates three months ahead and books the required date 400ms
🟢 date picker › confirming without the exact date shows the error 333ms
🟢 tests/debounced-search.e2e.ts · 2 passed 2.8s
🟢 debounced search › a decoy one character off is refused 1.4s
🟢 debounced search › picking the exact item adds it to the cart 1.4s
🟢 tests/deferred-dialog.e2e.ts · 1 passed 1.1s
🟢 one submit opens one confirm, even when double-clicked 1.1s
🟢 tests/div-soup.e2e.ts · 2 passed 705ms
🟢 div soup › a wrong code is rejected 324ms
🟢 div soup › the right code grants access after the delete tile fixes a typo 381ms
🟢 tests/drag-and-drop.e2e.ts · 2 passed 632ms
🟢 drag and drop › an out-of-order item resets the dropzone 320ms
🟢 drag and drop › dropping Banana then Cherry passes 312ms
🟢 tests/file-round-trip.e2e.ts · 2 passed 470ms
🟢 file round trip › downloads the issued voucher and verifies the same file uploaded back 223ms
🟢 file round trip › rejects a file that is not the voucher, then accepts the issued one 247ms
🟢 tests/filter-deep-link.e2e.ts · 2 passed 265ms
🟢 filter deep link › filtering writes the query to the URL 153ms
🟢 filter deep link › opening a shared link restores the filter 112ms
🟢 tests/gift-card-purchase.e2e.ts · 3 passed 612ms
🟢 gift card purchase › refuses to buy without an amount 179ms
🟢 gift card purchase › refuses a recipient without an at sign 193ms
🟢 gift card purchase › sends the gift card 240ms
🟢 tests/hover-menu.e2e.ts · 2 passed 515ms
🟢 hover menu › a decoy leaf is refused 228ms
🟢 hover menu › hovering Account, then Billing, reaches Redeem voucher 287ms
🟢 tests/iframe-form.e2e.ts · 2 passed 587ms
🟢 iframe form › a wrong code is refused by the host page 307ms
🟢 iframe form › the code read from one frame applies through the other 280ms
🟢 tests/image-only-ui.e2e.ts · 3 passed 503ms
🟢 image only ui › the icons have no names, so the bare svg locator is ambiguous 116ms
🟢 image only ui › a wrong icon shows the error image and keeps the icons 173ms
🟢 image only ui › tapping the star, then the heart, verifies the icons 214ms
🟢 tests/infinite-scroll.e2e.ts · 1 passed 2.8s
🟢 scrolls the feed until the Golden Ticket loads, then claims it 2.8s
🟢 tests/kanban-board.e2e.ts · 3 passed 781ms
🟢 kanban board › pointer drags move both cards into the goal layout 415ms
🟢 kanban board › a swipe along a path drags a card as well 152ms
🟢 kanban board › a plain tap moves nothing and the untouched board is rejected 214ms
🟢 tests/login-form.e2e.ts · 4 passed 849ms
🟢 login form › rejects a malformed email 199ms
🟢 login form › rejects a short password 200ms
🟢 login form › rejects an unknown account 200ms
🟢 login form › signs in and logs out 250ms
🟢 tests/lying-labels.e2e.ts · 4 passed 799ms
🟢 lying labels › the button whose accessible name says Pay now is the wrong one 195ms
🟢 lying labels › a text match for Pay now catches the decoy phrase too 129ms
🟢 lying labels › the field whose accessible name says Amount is the wrong one 226ms
🟢 lying labels › visible text drives the payment through 249ms
🟢 tests/native-dialogs.e2e.ts · 3 passed 531ms
🟢 native dialogs › answers the confirm, prompt, and alert chain 187ms
🟢 native dialogs › dismissing the confirm cancels the order 164ms
🟢 native dialogs › a wrong gift code is rejected 180ms
🟢 tests/new-tab-flow.e2e.ts · 2 passed 522ms
🟢 new tab flow › reads the code in the tab the app opens and enters it back in the original tab 225ms
🟢 new tab flow › a tap that opens a tab leaves the screen on the original tab, and activate shows the new one 297ms
🟢 tests/newsletter-signup.e2e.ts · 1 passed 2.2s
🟢 subscribe renders no feedback and logs a TypeError (planted bug) 2.2s
🟢 tests/onboarding-wizard.e2e.ts · 5 passed 5.1s
🟢 onboarding wizard › back keeps what was typed and the brief comes back with it 321ms
🟢 onboarding wizard › the address step takes the brief through its bare-div dropdown 367ms
🟢 onboarding wizard › the profile step steers the calendar three decades back 1.3s
🟢 onboarding wizard › the preferences step flips the toggles the brief names and leaves the trap off 1.4s
🟢 onboarding wizard › the review step repeats the brief and finishes with the PIN 1.7s
🟢 tests/order-history.e2e.ts · 2 passed 1.4s
🟢 order history › overview and settings render their panels 198ms
🟢 order history › the orders tab never leaves its loading state (planted bug) 1.2s
🟢 tests/otp-auto-advance.e2e.ts · 3 passed 1.4s
🟢 otp auto-advance › focus advances with each digit and the full code verifies 484ms
🟢 otp auto-advance › backspace on an empty box clears and refocuses the previous one 159ms
🟢 otp auto-advance › a wrong code clears every box and starts over 790ms
🟢 tests/overlay-trap.e2e.ts · 1 passed 732ms
🟢 continues only after the banner and the overlay are gone 732ms
🟢 tests/playbook-cleanup.e2e.ts · 2 passed 594ms
🟢 playbook cleanup › deleting the draft removes it from an exact-name search 297ms
🟢 playbook cleanup › cancelling the dialog keeps the draft searchable 297ms
🟢 tests/price-sorting.e2e.ts · 3 passed 432ms
🟢 price sorting › opens in the featured order with sale prices struck through 120ms
🟢 price sorting › low to high sorts by the original price, not the paid one (planted bug) 155ms
🟢 price sorting › high to low is the same wrong order reversed (planted bug) 157ms
🟢 tests/product-reviews.e2e.ts · 1 passed 1.1s
🟢 the running-shoe page lists coffee-grinder reviews (planted bug) 1.1s
🟢 tests/promo-storefront.e2e.ts · 1 passed 1.3s
🟢 buys a deal once the promo chrome is out of the way 1.3s
🟢 tests/rich-text-editor.e2e.ts · 2 passed 540ms
🟢 rich text editor › bolding exactly the required word passes the check 289ms
🟢 rich text editor › bold that spills into the previous word fails the check 251ms
🟢 tests/saved-addresses.e2e.ts · 3 passed 634ms
🟢 saved addresses › adds an address and clears the form 205ms
🟢 saved addresses › ignores an add with an empty field 196ms
🟢 saved addresses › delete shows its toast but keeps the address, on retry too (planted bug) 233ms
🟢 tests/shadow-dom-form.e2e.ts · 2 passed 431ms
🟢 shadow DOM form › rejects a wrong access code 211ms
🟢 shadow DOM form › grants access with the code from the hint inside the root 220ms
🟢 tests/smoke.e2e.ts · 1 passed 298ms
🟢 home lists the scenarios and opens one 298ms
🟢 tests/stale-dom.e2e.ts · 1 passed 2.2s
🟢 taps the moving target three times across rebuilds of the list 2.2s
🟢 tests/sticky-chrome.e2e.ts · 1 passed 255ms
🟢 accepts the terms once the button clears the sticky footer 255ms
🟢 tests/virtualized-table.e2e.ts · 1 passed 16.5s
🟢 scrolls the windowed table to the Golden Row and claims it 16.5s
🟢 tests/wishlist.e2e.ts · 2 passed 1.6s
🟢 wishlist › saving toggles the button and the tab badge 302ms
🟢 wishlist › the wishlist tab renders the empty state despite the badge count (planted bug) 1.3s

Tested by e2e 0.24.0 · 1m 7s · web · run artifacts

@github-actions

Copy link
Copy Markdown
Contributor

🟢 e2e web agent: 34 passed

36 agent steps · 26 replayed from cache · 26 model calls · 134.7k tokens (93% cached) · $0.0058

All 34 tests in 5 files
Test Agent Time
🟢 tests-agent/control-inventory.e2e.ts · 7 passed 7 steps 7.4s
🟢 control inventory › check sets the checkbox and the radio 1 step 702ms
🟢 control inventory › check picks a radio the pick replaces with its summary 1 step 274ms
🟢 control inventory › a long press and a double click are chosen over a plain tap 1 step 898ms
🟢 control inventory › a right-click opens the file menu and Rename renames the file 1 step 2.6s
🟢 control inventory › upload attaches the named project files 1 step 2.4s
🟢 control inventory › back returns from the details view to the inventory 1 step 249ms
🟢 control inventory › scroll_to brings the footnote into view 1 step 360ms
🟢 tests-agent/login-form.e2e.ts · 1 passed 1 step 391ms
🟢 act signs in with the benchmark account 1 step 391ms
🟢 tests-agent/planted-bugs.e2e.ts · 3 passed 5 steps · 9 calls 13.2s
🟢 cart totals: a judgment catches the stale order summary 2 steps · 4 calls 5.0s
🟢 checkout review: a judgment catches the broken copy 1 step · 1 call 1.4s
🟢 wishlist: a judgment catches the lost saved items 2 steps · 4 calls 6.8s
🟢 tests-agent/scenarios.e2e.ts · 22 passed 22 steps · 17 calls 1m 15s
🟢 act completes shadow-dom-form 1 step · 3 calls 3.6s
🟢 act completes lying-labels 1 step · 3 calls 4.1s
🟢 act completes iframe-form 1 step · 3 calls 3.7s
🟢 act completes infinite-scroll 1 step 3.4s
🟢 act completes virtualized-table 1 step 19.2s
🟢 act completes overlay-trap 1 step 898ms
🟢 act completes sticky-chrome 1 step 852ms
🟢 act completes async-states 1 step · 3 calls 6.2s
🟢 act completes debounced-search 1 step 2.3s
🟢 act completes hover-menu 1 step 527ms
🟢 act completes drag-and-drop 1 step 482ms
🟢 act completes kanban-board 1 step 663ms
🟢 act completes context-menu-trap 1 step 2.7s
🟢 act completes stale-dom 1 step 465ms
🟢 act completes otp-auto-advance 1 step 729ms
🟢 act completes date-picker 1 step 818ms
🟢 act completes rich-text-editor 1 step 10.2s
🟢 act completes playbook-cleanup 1 step 670ms
🟢 act completes promo-storefront 1 step 1.3s
🟢 act completes new-tab-flow 1 step · 5 calls 9.0s
🟢 act completes gift-card-purchase 1 step 2.5s
🟢 act filters the list and the URL carries the filter 1 step 241ms
🟢 tests-agent/unique-cache.e2e.ts · 1 passed 1 step 319ms
🟢 act adds an address with a run-unique label 1 step 319ms

Tested by e2e 0.24.0 · 1m 36s · web · run artifacts

@okwasniewski okwasniewski added the Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. label Nov 25, 2026
@okwasniewski
okwasniewski merged commit a47a956 into main Nov 25, 2026
38 checks passed
@okwasniewski
okwasniewski deleted the oskar/browser-cookies-url branch November 25, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e team Opened by the e2e team Ready for Human Review Green, conflict-free, every thread handled. Waiting on a maintainer. size:L Up to 499 changed lines, not counting tests, fixtures, translated docs, or the lockfile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant