Skip to content

feat(web): add browser.consoleMessages() and browser.pageErrors() (ENG-955) - #2113

Draft
satya164 wants to merge 4 commits into
mainfrom
@satya164/browser-console-errors
Draft

satya164 wants to merge 4 commits into
mainfrom
@satya164/browser-console-errors

Conversation

@satya164

@satya164 satya164 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What

browser.consoleMessages() and browser.pageErrors() on @e2e-dev/web return the console messages, uncaught errors, and unhandled promise rejections in the active tab since it opened.

await app.open('/checkout');
await screen.getByRole('button', 'Place order').tap();
await expect(screen.getByText('Order placed')).toBeVisible();
const errors = (await browser.consoleMessages()).filter((message) => message.type === 'error');
expect(errors).toEqual([]);
expect(await browser.pageErrors()).toEqual([]);

Each message has { type, text }, and each error has { name, message, stack }. A call can fail with APP_NOT_OPEN (no page is open yet), ACTION_FAILED (timed out after actionTimeout), or ENGINE_FAILURE (the browser connection was lost). All three are already in docs/reference/errors.mdx.

Why

To check a page for console errors or uncaught errors, test authors had to add an init script that wrapped console.error and listened for error and unhandledrejection, then read the results back with evaluate.

How it works

  1. Both methods read Playwright's per-page lists for the active tab with { filter: 'all' } (packages/web/src/browser.ts:710). With Playwright's default ('since-navigation'), entries would be dropped at each navigation. Playwright keeps the latest 200 entries per list. The list also has messages the browser writes, such as Chromium's Failed to load resource.

  2. The calls are recorded as browser.consoleMessages and browser.pageErrors steps without a label (packages/web/src/browser.ts:1029). Only the method name is recorded, not its return value. Console output can still appear in the app log, and a failed assertion can include the values it compared.

  3. WebConsoleMessage and WebPageError are exported from the main and engine entries (packages/web/src/browser.ts:127, packages/web/src/engine-entry.ts:38). type is a union written out in the source. It includes Playwright's ConsoleMessage.type() union plus the extra values browsers can send:

    • 'verbose': level for Chromium browser messages, from CDP's Log.entryAdded (coreBundle.js:39722).
    • 'countReset', 'timeLog', and 'timeStamp': Firefox's Juggler maps each console method to a type (consoleLevelToProtocolType in Juggler's content/Runtime.js, in the Firefox 1572 build), and Playwright passes it through (coreBundle.js:47062 and :47115).
    • 'image' and '': WebKit's Console.ConsoleMessage.type, which is optional (coreBundle.js:48507 and :49043, and src/server/webkit/protocol.d.ts in Playwright v1.65.1).

    Chromium's Runtime.consoleAPICalled doesn't add any values. The WebDriver BiDi path (coreBundle.js:43650) can't be reached from web(). If a Playwright bump adds a value, the build fails at type: message.type() (packages/web/src/browser.ts:713). Both return types, the type values, and the lack of a filter option are pinned in packages/web/tests/types/console-messages.ts.

  4. pageErrors() returns each Playwright error's name, message, and stack (packages/web/src/browser.ts:718). Playwright splits the browser's error text at its first colon (splitErrorMessage, coreBundle.js:9628), so a rejected 'Request failed: 500' has the name 'Request failed' and the message '500'. An Error has its class name, such as 'Error' or 'TypeError'.

  5. A persistent browser (connect.reconnectEndpoint, or a provider in attempt scope) reuses its first tab, and Chrome replays that tab's earlier console output and errors to every new CDP client. Both lists are cleared before navigating to about:blank, so entries from the context's init scripts are kept (packages/web/src/attempt-session.ts:328).

  6. After a CDP reconnect, Chrome only replays entries from the current document. Keeping earlier entries would mean carrying them over from the closed connection, so the limit is documented under "Recovering a CDP transport" instead.

  7. The newsletter benchmark test reads browser.consoleMessages() in place of the console hook it injected with browser.evaluate (apps/web-benchmark/tests/newsletter-signup.e2e.ts:14).

Verified

Ran it locally: yes, on Chromium and Firefox 159.

Chromium:

  • packages/web/tests/integration/console-messages.test.ts, pnpm --filter @e2e-dev/web exec vitest run tests/integration/console-messages.test.ts --reporter verbose:
✓ returns each console message with its type and text 166ms
✓ returns thrown errors and unhandled rejections with their name, message, and stack 133ms
✓ splits thrown and rejected non-Error values at the first colon, with an empty stack in Chromium 124ms
✓ includes the messages and errors from the tab's frames and dedicated workers 183ms
✓ keeps the messages and errors from earlier documents in the tab 134ms
✓ keeps a separate list for each tab 151ms
✓ drops entries from before the attempt on a persistent browser while keeping init script entries 508ms
Tests  7 passed (7)
  • The persistent-tab test fails with initial.clearConsoleMessages() deleted (before the attempt comes back), and with the clear calls moved after the about:blank navigation (only one from init script message comes back).
  • Testbed, the built CLI, node node_modules/e2e/dist/cli/bin.js run tests/browser.e2e.ts. The new test logs with console.error, leaves a rejection unhandled, and throws from a timer. All three are read back, and the lists are empty after app.restart():
 ✓ target "web" command at http://127.0.0.1:4271/ ready 98ms
   ✓ |web| tests/browser.e2e.ts > browser fixture > navigation verbs and the URL and title matchers 536ms
   ✓ |web| tests/browser.e2e.ts > browser fixture > reload runs the page again 175ms
   ✓ |web| tests/browser.e2e.ts > browser fixture > an init script runs before the page reads it, from the next load on 192ms
   ✓ |web| tests/browser.e2e.ts > browser fixture > the viewport size is what the page measures 177ms
   ✓ |web| tests/browser.e2e.ts > browser fixture > cookies set from the test reach the page and read back 182ms
   ✓ |web| tests/browser.e2e.ts > browser fixture > console messages and page errors read back and clear on restart 216ms
   ✓ |web| tests/browser.e2e.ts > offline fails the page's requests and navigations until the test goes back online 492ms
   ✓ |web| tests/browser.e2e.ts > emulated media reaches the page's own @media rules, from the first paint on 340ms
 ✓ |web| tests/browser.e2e.ts (8 tests) 2.31s
      Tests  8 passed (8)
  • Web benchmark, node node_modules/e2e/dist/cli/bin.js run tests/newsletter-signup.e2e.ts after pnpm run build:
 ✓ target "web" command at http://127.0.0.1:4280/ ready 1.05s
   ✓ |web| tests/newsletter-signup.e2e.ts > subscribe renders no feedback and logs a TypeError (planted bug) 2.89s
      Tests  1 passed (1)

Firefox, with browser: 'firefox' added to the engine options locally (not committed):

  • console-messages.test.ts: 5 of 7 pass. The persistent-tab test can't run there, since connect is Chromium-only (INVALID_CONFIG). The test for values that aren't an Error fails on its stack: '' expectation, because Firefox reports a stack for them (uncaught exception: 7 and the frames). That still matches the stack doc ("as the browser reports it").
  • Testbed tests/browser.e2e.ts: 7 passed, the new test included.
  • Firefox doesn't add Failed to load resource for a 404. It logs other warnings instead, such as [JavaScript Warning: "This page is in Quirks Mode..."] for a page without a doctype. The consoleMessages entry covers both browsers, with Chromium's message as the example.

Not captured:

  • pnpm bench:ab wasn't run. The cost of clearing both lists when a persistent browser's first tab is reused wasn't measured.
  • Run video: the methods return data and don't change anything on screen.
  • Docs screenshots: the docs site isn't built from this repository, so the changed pages (docs/reference/web.mdx and the Playwright, Cypress, and Selenium migration guides) can't be rendered locally.

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.

@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 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

🟢 e2e web agent: 34 passed

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

All 34 tests in 5 files
Test Agent Time
🟢 tests-agent/control-inventory.e2e.ts · 7 passed 7 steps 8.1s
🟢 control inventory › check sets the checkbox and the radio 1 step 846ms
🟢 control inventory › check picks a radio the pick replaces with its summary 1 step 483ms
🟢 control inventory › a long press and a double click are chosen over a plain tap 1 step 1.1s
🟢 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.5s
🟢 control inventory › back returns from the details view to the inventory 1 step 277ms
🟢 control inventory › scroll_to brings the footnote into view 1 step 361ms
🟢 tests-agent/login-form.e2e.ts · 1 passed 1 step 368ms
🟢 act signs in with the benchmark account 1 step 368ms
🟢 tests-agent/planted-bugs.e2e.ts · 3 passed 5 steps · 9 calls 12.6s
🟢 cart totals: a judgment catches the stale order summary 2 steps · 4 calls 5.5s
🟢 checkout review: a judgment catches the broken copy 1 step · 1 call 1.3s
🟢 wishlist: a judgment catches the lost saved items 2 steps · 4 calls 5.7s
🟢 tests-agent/scenarios.e2e.ts · 22 passed 22 steps · 17 calls 1m 17s
🟢 act completes shadow-dom-form 1 step · 3 calls 4.0s
🟢 act completes lying-labels 1 step · 3 calls 4.6s
🟢 act completes iframe-form 1 step · 3 calls 3.7s
🟢 act completes infinite-scroll 1 step 3.5s
🟢 act completes virtualized-table 1 step 20.5s
🟢 act completes overlay-trap 1 step 881ms
🟢 act completes sticky-chrome 1 step 884ms
🟢 act completes async-states 1 step · 3 calls 6.5s
🟢 act completes debounced-search 1 step 2.3s
🟢 act completes hover-menu 1 step 542ms
🟢 act completes drag-and-drop 1 step 486ms
🟢 act completes kanban-board 1 step 645ms
🟢 act completes context-menu-trap 1 step 2.7s
🟢 act completes stale-dom 1 step 590ms
🟢 act completes otp-auto-advance 1 step 866ms
🟢 act completes date-picker 1 step 1.0s
🟢 act completes rich-text-editor 1 step 10.3s
🟢 act completes playbook-cleanup 1 step 591ms
🟢 act completes promo-storefront 1 step 1.3s
🟢 act completes new-tab-flow 1 step · 5 calls 8.5s
🟢 act completes gift-card-purchase 1 step 2.4s
🟢 act filters the list and the URL carries the filter 1 step 249ms
🟢 tests-agent/unique-cache.e2e.ts · 1 passed 1 step 336ms
🟢 act adds an address with a run-unique label 1 step 336ms

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

@github-actions

github-actions Bot commented Nov 23, 2026 •

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 684ms
🟢 aria hidden flow › picks the Pro plan by its visible text and confirms it 515ms
🟢 aria hidden flow › another plan shows the error and keeps the picker open 169ms
🟢 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 282ms
🟢 canvas only › taps square, circle, then diamond at their pixel coordinates 147ms
🟢 canvas only › a shape out of order paints the error and resets progress 135ms
🟢 tests/canvas-whiteboard.e2e.ts · 2 passed 460ms
🟢 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 203ms
🟢 tests/cart-totals.e2e.ts · 2 passed 442ms
🟢 cart totals › increasing a quantity updates the line total but the order summary stays stale (planted bug) 243ms
🟢 cart totals › a quantity never drops below one 199ms
🟢 tests/checkout-review.e2e.ts · 1 passed 193ms
🟢 shows a raw greeting token and an undefined delivery date (planted bug), yet places the order 193ms
🟢 tests/context-menu-trap.e2e.ts · 2 passed 697ms
🟢 context menu trap › right-click opens nothing; the row menu renames the file 349ms
🟢 context menu trap › the decoy menu items refuse and keep the file 348ms
🟢 tests/control-inventory.e2e.ts · 8 passed 3.7s
🟢 control inventory › check sets the checkbox and the radio without flipping a set one 292ms
🟢 control inventory › check picks a radio the pick replaces with its summary 197ms
🟢 control inventory › a long press and a double click are told apart from a tap 1.0s
🟢 control inventory › the file menu opens on right-click only and Rename renames the file 285ms
🟢 control inventory › setInputFiles attaches files named from the project root 150ms
🟢 control inventory › the details view is left through the browser history 202ms
🟢 control inventory › scrollIntoView brings the footnote into view 210ms
🟢 control inventory › every exercise done shows the success message 1.3s
🟢 tests/css-content-ui.e2e.ts · 2 passed 417ms
🟢 css content ui › the tile labelled Ship it advances and confirming ships 232ms
🟢 css content ui › a wrong tile shows the CSS-rendered error and keeps the picker 185ms
🟢 tests/date-picker.e2e.ts · 2 passed 733ms
🟢 date picker › navigates three months ahead and books the required date 434ms
🟢 date picker › confirming without the exact date shows the error 299ms
🟢 tests/debounced-search.e2e.ts · 2 passed 2.9s
🟢 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 769ms
🟢 div soup › a wrong code is rejected 336ms
🟢 div soup › the right code grants access after the delete tile fixes a typo 433ms
🟢 tests/drag-and-drop.e2e.ts · 2 passed 692ms
🟢 drag and drop › an out-of-order item resets the dropzone 364ms
🟢 drag and drop › dropping Banana then Cherry passes 328ms
🟢 tests/file-round-trip.e2e.ts · 2 passed 355ms
🟢 file round trip › downloads the issued voucher and verifies the same file uploaded back 173ms
🟢 file round trip › rejects a file that is not the voucher, then accepts the issued one 182ms
🟢 tests/filter-deep-link.e2e.ts · 2 passed 266ms
🟢 filter deep link › filtering writes the query to the URL 153ms
🟢 filter deep link › opening a shared link restores the filter 113ms
🟢 tests/gift-card-purchase.e2e.ts · 3 passed 622ms
🟢 gift card purchase › refuses to buy without an amount 179ms
🟢 gift card purchase › refuses a recipient without an at sign 223ms
🟢 gift card purchase › sends the gift card 220ms
🟢 tests/hover-menu.e2e.ts · 2 passed 510ms
🟢 hover menu › a decoy leaf is refused 265ms
🟢 hover menu › hovering Account, then Billing, reaches Redeem voucher 245ms
🟢 tests/iframe-form.e2e.ts · 2 passed 634ms
🟢 iframe form › a wrong code is refused by the host page 285ms
🟢 iframe form › the code read from one frame applies through the other 349ms
🟢 tests/image-only-ui.e2e.ts · 3 passed 595ms
🟢 image only ui › the icons have no names, so the bare svg locator is ambiguous 130ms
🟢 image only ui › a wrong icon shows the error image and keeps the icons 240ms
🟢 image only ui › tapping the star, then the heart, verifies the icons 225ms
🟢 tests/infinite-scroll.e2e.ts · 1 passed 2.9s
🟢 scrolls the feed until the Golden Ticket loads, then claims it 2.9s
🟢 tests/kanban-board.e2e.ts · 3 passed 773ms
🟢 kanban board › pointer drags move both cards into the goal layout 404ms
🟢 kanban board › a swipe along a path drags a card as well 153ms
🟢 kanban board › a plain tap moves nothing and the untouched board is rejected 216ms
🟢 tests/login-form.e2e.ts · 4 passed 879ms
🟢 login form › rejects a malformed email 217ms
🟢 login form › rejects a short password 201ms
🟢 login form › rejects an unknown account 213ms
🟢 login form › signs in and logs out 248ms
🟢 tests/lying-labels.e2e.ts · 4 passed 717ms
🟢 lying labels › the button whose accessible name says Pay now is the wrong one 186ms
🟢 lying labels › a text match for Pay now catches the decoy phrase too 106ms
🟢 lying labels › the field whose accessible name says Amount is the wrong one 223ms
🟢 lying labels › visible text drives the payment through 202ms
🟢 tests/native-dialogs.e2e.ts · 3 passed 532ms
🟢 native dialogs › answers the confirm, prompt, and alert chain 188ms
🟢 native dialogs › dismissing the confirm cancels the order 193ms
🟢 native dialogs › a wrong gift code is rejected 151ms
🟢 tests/new-tab-flow.e2e.ts · 2 passed 516ms
🟢 new tab flow › reads the code in the tab the app opens and enters it back in the original tab 258ms
🟢 new tab flow › a tap that opens a tab leaves the screen on the original tab, and activate shows the new one 258ms
🟢 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 4.9s
🟢 onboarding wizard › back keeps what was typed and the brief comes back with it 311ms
🟢 onboarding wizard › the address step takes the brief through its bare-div dropdown 407ms
🟢 onboarding wizard › the profile step steers the calendar three decades back 1.2s
🟢 onboarding wizard › the preferences step flips the toggles the brief names and leaves the trap off 1.5s
🟢 onboarding wizard › the review step repeats the brief and finishes with the PIN 1.5s
🟢 tests/order-history.e2e.ts · 2 passed 1.4s
🟢 order history › overview and settings render their panels 194ms
🟢 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 475ms
🟢 otp auto-advance › backspace on an empty box clears and refocuses the previous one 152ms
🟢 otp auto-advance › a wrong code clears every box and starts over 800ms
🟢 tests/overlay-trap.e2e.ts · 1 passed 650ms
🟢 continues only after the banner and the overlay are gone 650ms
🟢 tests/playbook-cleanup.e2e.ts · 2 passed 532ms
🟢 playbook cleanup › deleting the draft removes it from an exact-name search 281ms
🟢 playbook cleanup › cancelling the dialog keeps the draft searchable 251ms
🟢 tests/price-sorting.e2e.ts · 3 passed 404ms
🟢 price sorting › opens in the featured order with sale prices struck through 114ms
🟢 price sorting › low to high sorts by the original price, not the paid one (planted bug) 146ms
🟢 price sorting › high to low is the same wrong order reversed (planted bug) 144ms
🟢 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 495ms
🟢 rich text editor › bolding exactly the required word passes the check 242ms
🟢 rich text editor › bold that spills into the previous word fails the check 253ms
🟢 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 209ms
🟢 saved addresses › delete shows its toast but keeps the address, on retry too (planted bug) 220ms
🟢 tests/shadow-dom-form.e2e.ts · 2 passed 397ms
🟢 shadow DOM form › rejects a wrong access code 197ms
🟢 shadow DOM form › grants access with the code from the hint inside the root 200ms
🟢 tests/smoke.e2e.ts · 1 passed 296ms
🟢 home lists the scenarios and opens one 296ms
🟢 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 223ms
🟢 accepts the terms once the button clears the sticky footer 223ms
🟢 tests/virtualized-table.e2e.ts · 1 passed 17.9s
🟢 scrolls the windowed table to the Golden Row and claims it 17.9s
🟢 tests/wishlist.e2e.ts · 2 passed 1.8s
🟢 wishlist › saving toggles the button and the tab badge 374ms
🟢 wishlist › the wishlist tab renders the empty state despite the badge count (planted bug) 1.4s

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

@satya164
satya164 force-pushed the @satya164/browser-console-errors branch 2 times, most recently from 2f071f6 to ae853b6 Compare November 24, 2026 10:24
@satya164 satya164 changed the title feat(web): add browser.consoleMessages() and browser.pageErrors() feat(web): add browser.consoleMessages() and browser.pageErrors() (ENG-955) Nov 24, 2026
@satya164
satya164 force-pushed the @satya164/browser-console-errors branch from d73c252 to afa9368 Compare November 25, 2026 10:27
@satya164
satya164 force-pushed the @satya164/browser-console-errors branch from 17d3df7 to a30f448 Compare November 25, 2026 12:35

This branch has not been deployed

No deployments
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 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