Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ The daemon routes `POST /tool/:name` requests through the registry, applies Zod
| **Advanced** | |
| `mock_network` | Adds, clears, lists, and inspects targeted Playwright network mocks on the active browser context. Unmatched same-origin requests are continued unchanged. A rule with `record` and no `response` records the real request and forwards it unchanged. Rules can opt in to record request bodies and headers (redacted). |
| `events` | Bookmarks or clears the session event buffer that `mm logs` and `mm network` read: `mark` returns the current cursor (one cursor for both) and `summary.startedAt`; `clear` empties it without resetting the cursor. The buffer starts with a browser session and keeps the newest 1000 console and 2000 network records. Browser only. |
| `logs` | Read-only. Console errors and uncaught exceptions of every page and the Extension service worker, from the session event buffer: `{ records, cursor, hasMore, gap, summary }`, oldest first, with `cursor`/`since`/`limit`/`grep`. Records `error` only by default; `configure` widens the levels for the session (`warn` is accepted as `warning`). Object and array arguments are rendered from their CDP preview (a sensitive property name prints `[REDACTED]`), and a leading format string fills its `%s`/`%d`/`%o` specifiers. URLs in the text and the values of sensitive object fields (`privateKey`, `mnemonic`, `password`, …) are redacted; plain string contents are not scanned (JWTs and `Bearer` tokens excepted). Text is cut at 2000 characters. Browser only. |
| `cdp` | Sends a raw Chrome DevTools Protocol command, dispatched through the active platform driver. **Browser:** targets the active page (`target: "page"`, default) or the Extension service worker (`target: "sw"`) on a persistent CDP session shared across calls, so enabled domains and listeners survive; `fresh: true` uses a one-shot session. Full Runtime/DOM/Network/Page surface; destructive methods (`Browser.close`, `Target.closeTarget`, etc.) are blocked. **Mobile (iOS/Android):** targets the app's React Native Hermes JS runtime via Metro's inspector proxy (delegates to `@metamask/device-mcp`, needs a DEBUG build with Metro running); only the JS-engine subset exists (`Runtime`, `Debugger`, `Log`, `HeapProfiler` — no DOM/Page/Network) and `Runtime.terminateExecution` / `Inspector.detached` are blocked. Optional `metroPort` / `appId` are mobile-only (ignored on browser). Categorized as `cdp`: no observation is collected and refs are not refreshed, so run `describe_screen` after a call that changes state. See [Browser vs Mobile CDP](#browser-vs-mobile-hermes-cdp). |
| **Hermes (mobile only)** | |
| `hermes_targets` | Lists and diagnoses the debuggable Hermes targets Metro exposes (iOS and Android), reporting which target would be chosen or why selection is ambiguous. Use to confirm Metro is running and the app is registered. Pass `all` to bypass the appId filter and discover the real appId. Mobile only — there is no browser equivalent. |
Expand Down Expand Up @@ -688,6 +689,8 @@ mm describe-screen
| `mm mock-network requests [--limit <n>] [--url <glob-or-text>] [--bodies]` | Shows recorded matched and missed requests. `--url` keeps only matching URLs. `--bodies` adds the recorded (redacted) request bodies and headers. |
| `mm events mark` | Returns the current cursor of the session event buffer and `summary.startedAt`. Take it at the start of a flow and pass it to `mm logs` / `mm network` at the end. Browser only. |
| `mm events clear [--kind console\|network]` | Empties the session event buffer (one kind or all). The cursor keeps counting, so older cursors stay valid. |
| `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 since the cursor. Read again with the returned `cursor` while `hasMore`; `gap: true` also means the cursor is from an earlier session (the read restarts from the oldest record). `--grep` is a case-sensitive JavaScript regex of at most 256 characters; the pattern runs in the daemon, so avoid nested quantifiers such as `(a+)+`; a value that starts with `--` must be escaped (`--grep '\-\-x'`). Browser only. |
| `mm logs configure --levels <error,warning,info,log,debug>` | Changes the recorded console levels for the session (default `error`; `warn` is accepted as `warning`). Only `--levels <list>` is accepted; any other flag or a second `--levels` is a usage error. |
| `mm cdp <method> [params-json] [--timeout <ms>] [--target page\|sw\|hermes\|android-webview] [--fresh] [--metro-port <p>] [--app-id <id>]` | Sends a raw Chrome DevTools Protocol command against the active session. Escape hatch for when structured tools are insufficient. Works on both browser and mobile — the target runtime and blocked methods differ by platform (see below). Browser targets are the active page (`page`, default) and the Extension service worker (`sw`); `--fresh` uses a one-shot session. On mobile the session keeps the `--metro-port` given to `mm launch`, so later calls use it; a per-call `--metro-port` is only an override. |

```bash
Expand Down
25 changes: 24 additions & 1 deletion SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The default depends on the tool's category:
| Category | Examples | Default `observe` |
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
| **Mutating** | click, type, navigate, reload, launch, cleanup, build, clipboard, mock_network, scroll_to_element, device_swipe, long_press, tap_coordinates, dismiss_keyboard, dismiss_alert, open_app, close_app, press_button, device_context, device_clipboard | `diff` |
| **Read-only** | get_state, get_text, inspect, get_context, set_context, events, get_alert_text, screen_recording, device_logs, generate_locators, hermes_targets | `none` |
| **Read-only** | get_state, get_text, inspect, get_context, set_context, events, logs, get_alert_text, screen_recording, device_logs, generate_locators, hermes_targets | `none` |
| **Discovery** | describe_screen, list_testids, accessibility_snapshot, screenshot (data is already in `result`) | `none` |
| **CDP** | cdp | `none` |
| **Batch** | run_steps | `diff` |
Expand Down Expand Up @@ -761,6 +761,29 @@ Empties the buffer (one kind or all). The cursor keeps counting, so older cursor

`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. 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.

#### `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. Returns `{ records, cursor, hasMore, gap, summary }`, oldest first (default 500, max 2000 per read). While `hasMore` is true, read again with the returned `cursor`. `gap: true` means records after your cursor were dropped (buffer full), or your cursor is from an earlier session (it is above the newest `seq` of this one; the read then starts from the oldest record). `--grep` is a case-sensitive JavaScript regular expression of at most 256 characters. The pattern runs in the daemon, so avoid patterns with nested quantifiers such as `(a+)+`. A value that starts with `--` is read as a missing flag value; escape it, for example `--grep '\-\-x'`.

```json
{
"seq": 14,
"t": 1795430400123,
"target": {
"kind": "sw",
"id": "A51F9577…",
"url": "chrome-extension://…/scripts/app-init.js"
},
"level": "error",
"text": "Fetch failed: https://mainnet.infura.io/v3/[REDACTED]",
"location": "chrome-extension://…/scripts/app-init.js:10:5"
}
```

`target.kind` is `page` or `sw`. 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.

### Mobile device actions (iOS/Android only)

These commands require a mobile session (`mm launch --platform ios|android`). On a browser
Expand Down
79 changes: 79 additions & 0 deletions src/cli/mm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,7 @@ describe('printHelp', () => {
expect(output).toContain('--pretty');
expect(output).toContain('MM_PRETTY');
expect(output).toContain('mm events mark');
expect(output).toContain('mm logs configure --levels');
});
});

Expand Down Expand Up @@ -3170,6 +3171,84 @@ describe('routeCommand', () => {
expectFailure(expect.stringContaining('Usage: mm events'), 2);
});

it('routes logs with read flags', async () => {
await routeCommand(
'logs',
[
'--cursor',
'12',
'--limit',
'50',
'--since',
'2026-11-18T10:00:00Z',
'--grep',
'boom',
],
3000,
);
expect(globalThis.fetch).toHaveBeenLastCalledWith(
'http://127.0.0.1:3000/tool/logs',
expect.objectContaining({
body: JSON.stringify({
cursor: 12,
limit: 50,
since: '2026-11-18T10:00:00Z',
grep: 'boom',
}),
}),
);
await routeCommand('logs', [], 3000);
expect(globalThis.fetch).toHaveBeenLastCalledWith(
'http://127.0.0.1:3000/tool/logs',
expect.objectContaining({ body: JSON.stringify({}) }),
);
// A cursor of 0 is valid (the start of the session).
await routeCommand('logs', ['--cursor', '0'], 3000);
expect(globalThis.fetch).toHaveBeenLastCalledWith(
'http://127.0.0.1:3000/tool/logs',
expect.objectContaining({ body: JSON.stringify({ cursor: 0 }) }),
);
});

it('routes logs configure', async () => {
await routeCommand(
'logs',
['configure', '--levels', 'error, warning'],
3000,
);
expect(globalThis.fetch).toHaveBeenLastCalledWith(
'http://127.0.0.1:3000/tool/logs',
expect.objectContaining({
body: JSON.stringify({
action: 'configure',
levels: ['error', 'warning'],
}),
}),
);
});

it.each([
[['--cursor', 'x']],
[['--limit']],
[['--limit', '0']],
[['--limit', '-5']],
[['--since']],
[['--grep', '--cursor', '1']],
[['--grap', 'x']],
[['--levels', 'warning']],
[['configure']],
[['configure', '--levels', ',']],
[['configure', '--levels', 'warning', '--cursor', '1']],
[['configure', '--levels', 'warning', 'extra']],
[['configure', '--levels', 'warning', '--levels', 'error']],
[['tail']],
])('exits on bad logs arguments %j', async (args) => {
await expect(routeCommand('logs', args, 3000)).rejects.toThrowError(
'process.exit',
);
expectFailure(expect.stringContaining('Usage: mm logs'), 2);
});

it('exits when mock-network has an unknown action', async () => {
await expect(
routeCommand('mock-network', ['unknown'], 3000),
Expand Down
Loading
Loading