Skip to content
Open
10 changes: 5 additions & 5 deletions README.md

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -781,9 +781,9 @@ mm hermes-targets
mm hermes-targets --all
```

### Session events (browser only)
### Session events

From `mm launch` on, the daemon records events from every page, the Extension's background service worker, the MV3 offscreen document and its snaps iframes into one buffer per session. `mm logs` and `mm network` read it. All kinds share one cursor (`seq`), so one `mark` covers both. Traffic during `mm launch` itself (for example self-onboarding) is not recorded. Mobile sessions return `MM_TOOL_NOT_SUPPORTED_ON_PLATFORM`.
From `mm launch` on, the daemon records events from every page, the Extension's background service worker, the MV3 offscreen document and its snaps iframes into one buffer per session. `mm logs` and `mm network` read it. All kinds share one cursor (`seq`), so one `mark` covers both. Traffic during `mm launch` itself (for example self-onboarding) is not recorded. On mobile, `mm events` and `mm logs` read the console of the app's Hermes runtime (see [`mm logs` on mobile](#mm-logs-on-mobile)); `mm network` returns `MM_TOOL_NOT_SUPPORTED_ON_PLATFORM`.

#### `mm events mark`

Expand All @@ -793,7 +793,7 @@ Returns `{ cursor, summary }`. Take it at the start of a flow.

Empties the buffer (one kind or all). The cursor keeps counting, so older cursors stay valid.

`summary` is `{ startedAt, seq, counts: { console, network }, dropped: { console, network }, captureErrors, lastCaptureError? }`. `startedAt` (epoch ms) changes when the session is relaunched; `seq` then starts at 1 again. Every appended record and every settled network request (a request that ended) takes the next `seq`, so `seq` can skip values. The buffer keeps the newest 1000 console and 2000 network records; older ones are dropped and counted. `captureErrors` counts the times the session could not listen to a page or the service worker (for example a target that did not answer within 5 s, or a domain that could not be enabled); `lastCaptureError` is the newest one, redacted. When it grows during a flow, events of that target can be missing. A call that starts the recording waits at most 5 s for a target that does not answer.
`summary` is `{ startedAt, seq, counts: { console, network }, dropped: { console, network }, captureErrors, lastCaptureError? }`. `startedAt` (epoch ms) changes when the session is relaunched; `seq` then starts at 1 again. Every appended record and every settled network request (a request that ended) takes the next `seq`, so `seq` can skip values. The buffer keeps the newest 1000 console and 2000 network records; older ones are dropped and counted. `captureErrors` counts the times the session could not listen to a page or the service worker (for example a target that did not answer within 5 s, or a domain that could not be enabled); `lastCaptureError` is the newest one, redacted. On mobile it also counts a lost Hermes connection and an uncaught-error wrapper that could not be installed within 60 s of a reload. When it grows during a flow, events of that target can be missing. A call that starts the recording waits at most 5 s for a target that does not answer.

#### `mm logs [--cursor <n> | --since <iso|epoch-ms>] [--limit <n>] [--grep <regex>]`

Expand All @@ -814,10 +814,19 @@ Console errors and uncaught exceptions of every page, the Extension service work
}
```

`target.kind` is `page`, `sw`, `offscreen` (the MV3 offscreen document) or `iframe` (a snaps iframe of the offscreen document; its `url` is empty until the iframe loads). Uncaught exceptions have `"uncaught": true`. `text` (console arguments, error messages and stacks, uncaught exceptions) is cut at 2000 characters and redacted only for URLs, JWTs, `Bearer` values and sensitive property names in object previews (`privateKey`, `mnemonic`, `password`, …); a secret in free text, such as `new Error('… password hunter2')`, is not detected. `t` is the CDP time of the message (epoch ms).
`target.kind` is `page`, `sw`, `offscreen` (the MV3 offscreen document), `iframe` (a snaps iframe of the offscreen document; its `url` is empty until the iframe loads) or `hermes` (mobile). Uncaught exceptions have `"uncaught": true`. `text` (console arguments, error messages and stacks, uncaught exceptions) is cut at 2000 characters and redacted only for URLs, JWTs, `Bearer` values and sensitive property names in object previews (`privateKey`, `mnemonic`, `password`, …); a secret in free text, such as `new Error('… password hunter2')`, is not detected. `t` is the CDP time of the message (epoch ms).

Only `error` (including `console.assert` and uncaught exceptions) is recorded by default. `mm logs configure --levels error,warning` records more levels from then on, for this session (`warn` is accepted as `warning`). Non-error objects and arrays are rendered from their CDP preview (`{message: 'User rejected', chainId: 1}`, `[1, 2]`); a named property of an array prints as `name: value`, and a sensitive property name prints `[REDACTED]`. A leading format string fills `%s`, `%d`, `%i`, `%f`, `%o`, `%O`, `%c` from its arguments. `mm logs configure` accepts only `--levels <list>`: any other flag or a second `--levels` is a usage error.

#### `mm logs` on mobile

On iOS and Android dev builds (with Metro), `mm logs` records `console.*` calls of the app's Hermes runtime from `mm launch` on, using the same output shape, levels, limits, `--grep` and redaction as the browser, with `target: { kind: "hermes", id: <Metro target id>, url: "" }`.

- **Uncaught errors:** an observe-only wrapper of `ErrorUtils` reports each error to the daemon and calls the app's handler unchanged, producing one record with `"uncaught": true` (and `"fatal": true` when React Native passed `isFatal`; the app's own handler may still swallow the error, as MetaMask does for Ledger and Keystone errors, so `fatal` does not always mean a red box).
- **Reloads and reconnects:** recording continues across JS reloads (`DevSettings.reload()`, Metro reload) with no reload marker, and the wrapper reinstalls once the new bundle runs (errors before then still appear from `console.error` without `uncaught`). Lost Metro connections reconnect and increment `summary.captureErrors`.
- **Overhead and `Runtime`:** while a session is open, the app serializes every `console.*` call with previews, like an open DevTools; `mm cdp Runtime.disable` on the session connection is refused with `MM_CDP_BLOCKED`.
- **Not captured:** native crashes and native logs (use `mm device-logs`), pre-connect Hermes replays, messages sent while disconnected, and release builds without Metro.

#### `mm network [--cursor <n> | --since <iso|epoch-ms>] [--limit <n>] [--url <glob|text>] [--errors] [--settled]`

HTTP(S) requests of every page, the Extension service worker (gas, security alerts, bridge, RPC: most Extension traffic comes from the worker), the offscreen document and its snaps iframes (`target.kind` as in `mm logs`). It only listens: it never mocks, blocks or changes a request, and it stores no bodies (use `mm mock-network` for that). One record per request, created when it starts and updated in place when it ends; it keeps its first `seq` and gets a `settledSeq` when it ends. Same paging as `mm logs`, plus `stats: { pending, ignored, rpcErrorsSkipped }`. A request whose page, worker, offscreen document or iframe goes away before it ends (the offscreen document goes away when it is recreated) is finalized with `failure: "target closed"`; one dropped from the pending limit is finalized with `failure: "abandoned"`.
Expand Down
7 changes: 4 additions & 3 deletions src/cli/mm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2574,15 +2574,16 @@ Advanced:
mm cdp <method> [params-json] [--timeout <ms>] [--target page|sw|hermes|android-webview] [--fresh] [--url-filter <substr>] [--metro-port <p>] [--app-id <id>]
mm hermes-targets [--all] [--metro-port <p>] [--app-id <id>] (mobile only)

Session events (browser only; recorded from launch on, not during it):
Session events (recorded from launch on, not during it; network: browser only):
mm events mark Current cursor and summary.startedAt. Take one at the
start of a flow; pass the cursor to logs/network.
mm events clear [--kind console|network]
Empty the buffer; the cursor keeps counting.
mm logs [--cursor <n> | --since <iso|epoch-ms>] [--limit <n>] [--grep <regex>]
Console errors and uncaught exceptions of every page
and the Extension service worker. Oldest first; read
again with the returned cursor while hasMore.
and the Extension service worker (mobile: the app's
Hermes runtime). Oldest first; read again with the
returned cursor while hasMore.
mm logs configure --levels <error,warning,info,log,debug>
Levels to record from now on (default: error).
mm network [--cursor <n> | --since <iso|epoch-ms>] [--limit <n>] [--url <glob|text>] [--errors] [--settled]
Expand Down
3 changes: 1 addition & 2 deletions src/events/console-source.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { BrowserContext } from '@playwright/test';
import { describe, expect, it, vi } from 'vitest';

import {
Expand Down Expand Up @@ -78,7 +77,7 @@ async function startSource(): Promise<{
return { unsubscribe: vi.fn() };
}),
} as unknown as CdpManager;
const events = new SessionEvents({} as BrowserContext, []);
const events = new SessionEvents(() => manager, []);
await new ConsoleSource().start(manager, events);
const subscribed = options as CdpSubscribeOptions;
return {
Expand Down
Loading
Loading