Skip to content

feat: add mm logs for console errors from pages and the service worker - #110

Open
cryptotavares wants to merge 1 commit into
cryptotavares/mmcli-p2-15-eventsfrom
cryptotavares/mmcli-p2-16-logs
Open

cryptotavares wants to merge 1 commit into
cryptotavares/mmcli-p2-15-eventsfrom
cryptotavares/mmcli-p2-16-logs

Conversation

@cryptotavares

@cryptotavares cryptotavares commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Important

Stacked on #109 (P2-15), which stacks on #107 (P2-28, ready to review on main). Review those first. This PR targets #109's branch and contains one commit. #111 (P2-17) stacks on it.

Release validation needs the console errors of each flow from every Extension context. Most Extension errors come from the MV3 background service worker. A page-level console.error hook never sees them, and mm cdp could not reach the worker before #90.

  • Source (src/events/console-source.ts): a CdpManager.subscribe (feat: deliver CDP events from pages and the service worker #107) to Runtime.consoleAPICalled and Runtime.exceptionThrown on every page and the service worker. Each event becomes a console record in the P2-15 buffer: { seq, t, target, level, text, location?, uncaught? }.
    • level: error | warning | info | log | debug. console.assert counts as error. An uncaught exception is error with uncaught: true.
    • text: the arguments joined on one line, as DevTools does it: object and array arguments render from the CDP preview ({message: 'User rejected', chainId: 1}, [1, 2], … when the preview overflowed; a property whose name is sensitive (privateKey, mnemonic, password, token, key, *key/*token, secret, seed, pass, pk, …) renders as [REDACTED], nested previews included; publicKey, sortKey, sourceToken and similar are allowlisted; a named property of an array prints name: value; only plain objects, arrays and proxies render as a record, other subtypes keep their description such as Uint8Array(2) or Map(1)). The preview name check is the query-parameter check, so code is redacted too ({code: [REDACTED]}), a safe-side false positive. Format specifiers (%s %d %i %f %o %O %c, %%) are filled from the following arguments, and an uncaught exception value uses the same rendering. URLs are redacted, and the text is cut at 2000 characters.
    • location: 1-based url:line:column of the call or throw.
    • t: the CDP timestamp (epoch ms).
    • target: { kind: 'page'|'sw', id, url }.
  • Default: error only. mm logs configure --levels error,warning widens it for the session; warn is accepted for warning. configure accepts exactly --levels <list>: an extra argument, another flag or a second --levels is a usage error (exit 2).
  • Replays dropped: Runtime.enable replays console messages Chrome kept (P2-28 finding). Messages older than the subscription, and repeats (same target, timestamp, level, text), are ignored; the replay key is remembered before the level filter, so a widened level does not replay an old message.
  • mm logs [--cursor N | --since <iso|ms>] [--limit N] [--grep <re>] → { records, cursor, hasMore, gap, summary }. --grep is a case-sensitive JS regex of at most 256 characters (retried without u when that does not compile); a value that starts with -- must be escaped (--grep '\-\-x'); unknown flags and missing values exit 2.
  • Starts with the session (no command needed). Read-only, browser-only tool; zod schema, CLI help, README, SKILL.md.

Part of the mm CLI v2 effort: ticket P2-16 (Phase 2). Next: P2-17 mm network.

Breaking changes

None.

Consumer impact

Consumer Change needed Done on branch
Extension test/e2e/playwright/llm-workflow/ none n/a
Mobile tests/llm-workflow/ none (browser only; Hermes source is a follow-up) n/a

The Extension release-validation skill (Consensys/skills#122) can switch from its page hook to mm logs when the command is present.

Proof

Real daemon + built CLI. MV3 test extension in headless Chromium (page console.error, uncaught page TypeError, worker console.error with an Infura URL, console.warn, console.log).

Check Result
Worker and page console.error, uncaught page error, with the right target.kind ✅
console.warn not recorded by default ✅
console.warn recorded after mm logs configure --levels error,warning ✅
After ServiceWorker.stopAllWorkers (0 worker targets) and a wake, new worker errors appear ✅
--limit 1 paging (3 pages, no duplicates) ✅
Object/array/preview formatting, specifiers and exception text on real CDP payloads ✅ probe/ (headless-Chromium capture + formatter output); a second probe checks preview redaction and subtype descriptions
Round-3 probe: a named array property, broader field names and the allowlist on a real page ✅ 14/14 (probe-r3/, through the daemon and built CLI): ['one', 2, privateKey: [REDACTED], label: 'wallet'], {mnemonicPhrase: [REDACTED], pk: [REDACTED], passwd: [REDACTED], seed: [REDACTED]}, {publicKey: '0xpub', sortKey: 'abc', sourceToken: '0xtoken'}; no secret value in the output
mm logs configure with an extra argument or a second --levels ✅ exit 2 (unit)
events clear keeps seq (11 → 11) ✅
Relaunch changes startedAt ✅
No Infura key / apiKey value in any output ✅
Transcript
$ mm events mark                                  → cursor 0
$ mm navigate chrome-extension://…/trigger.html?tag=A
$ mm logs --cursor 0
{"records":[
 {"seq":1,"t":…,"target":{"kind":"page","id":"…","url":"chrome-extension://…/trigger.html?tag=A"},"level":"error","text":"page error for A","location":"chrome-extension://…/trigger.js:11:11"},
 {"seq":2,…,"target":{"kind":"page",…},"level":"error","text":"Uncaught TypeError: uncaught in page A\n    at chrome-extension://…/trigger.js:12:28","location":"…/trigger.js:12:28","uncaught":true},
 {"seq":3,…,"target":{"kind":"sw","id":"…","url":"chrome-extension://…/bg.js"},"level":"error","text":"bg flow A failed: https://mainnet.infura.io/v3/[REDACTED]","location":"chrome-extension://…/bg.js:27:11"}],
 "cursor":3,"hasMore":false,"gap":false,"summary":{"startedAt":…,"seq":3,"counts":{"console":3,"network":0},"dropped":{"console":0,"network":0}}}
$ mm logs configure --levels error,warning
# after worker stop + wake:
[8,"page","error","page error for C"] [9,"page","error","Uncaught TypeError: uncaught in page C …"]
[10,"sw","error","bg flow C failed: https://mainnet.infura.io/v3/[REDACTED]"] [11,"sw","warning","bg flow C warning"]
Unit tests
 Test Files  71 passed (71)
      Tests  2612 passed (2612)
Type Errors  no errors
All files          |   98.05 |    95.06 |   97.85 |   98.16 |
yarn lint: exit 0
yarn build: exit 0

New: src/events/console-source.test.ts (level mapping, argument formatting, truncation, redaction, location, uncaught, replay filter, level config), src/tools/logs.test.ts (cursor/since/limit/grep, invalid grep, configure), CLI routing and schemas.

Records Runtime.consoleAPICalled and Runtime.exceptionThrown from every
page and the Extension service worker (through CdpManager.subscribe)
into the session event buffer. Only 'error' is recorded by default
(console.assert and uncaught exceptions included); 'mm logs configure
--levels' widens it for the session. Text is redacted and cut at 2000
characters. Messages replayed by Runtime.enable (older than the source,
or seen already) are dropped. 'mm logs' reads with --cursor/--since/
--limit/--grep and returns { records, cursor, hasMore, gap, summary }.
@cryptotavares
cryptotavares force-pushed the cryptotavares/mmcli-p2-16-logs branch from 9ef48e3 to 2b3db17 Compare November 18, 2026 18:47
@cryptotavares
cryptotavares marked this pull request as ready for review November 18, 2026 18:58
@cryptotavares
cryptotavares requested a review from a team as a code owner November 18, 2026 18:58

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant