Repository navigation
feat: add mm network-log, a passive request and console log with service-worker traffic - #106
Closed
cryptotavares wants to merge 9 commits into
Closed
cryptotavares wants to merge 9 commits into
cryptotavares wants to merge 9 commits into
Conversation
An agent that validates an Extension PR needs to check which analytics
events the Extension sent to Segment. mock-network only recorded
method, URL and status, so the agent could not see the batch payload.
- A rule can set `record: { body?, headers?, maxBodyBytes? }`. It is off
by default and applies only to requests that the rule matches.
- Bodies: JSON is parsed. Other UTF-8 text is kept as text. Binary
bodies record only their type and size. Bodies longer than
maxBodyBytes (default 64 KiB, max 512 KiB) are cut on a UTF-8
boundary, kept as text and marked `truncated`.
- Redaction: secret body fields (writeKey, password, apiKey,
accessToken, privateKey, mnemonic, ...) and sensitive headers
(authorization, cookie, and names with token/secret/key/auth/
session/password) are replaced with [REDACTED].
- Each record has `serviceWorker: true` when a service worker sent the
request.
- `mm mock-network requests` gains `--bodies` and
`--url <glob-or-text>`. The default output is unchanged.
network_log reuses the body-field secret list and the service-worker check from mock-network instead of copying them.
Release validation needs per-flow network and console data from the Extension, and most confirmation traffic (gas, security alerts, bridge, RPC) is sent by the MV3 service worker, which a page-level fetch patch cannot see. Playwright 1.57+ reports service-worker requests and console messages on the browser context, so a listener-only recorder covers both the pages and the worker. - The recorder listens to request/response/requestfinished/ requestfailed/console/weberror on the browser context. It never routes a request. launch starts it for browser sessions, so the log covers every flow without a start call; attachNetworkLog is exported so a session manager can start it earlier. - Requests: start time, method, redacted URL, resource type, status, duration (Playwright timing), failure text, source (page or service-worker, with page/frame URL) and JSON-RPC method(s) from the request body (single and batch). URL redaction removes credentials, key-like host labels and path segments (Infura ids) and sensitive query values; addresses, hashes and UUIDs stay readable. - Console: error and warning by default (configurable), text redacted and cut at 2000 characters, source, location; uncaught page errors are recorded as errors. - Bounded ring buffers (2000 requests, 1000 console messages) with dropped counts. Records share one sequence number, so a cursor from mark (or the last read) returns only newer records, oldest first, with hasMore and a gap flag when records after the cursor were dropped. Reads also take since, url, errors, limit and clear. - configure rpcErrors (off by default) reads JSON-RPC response bodies up to 64 KiB, at most 8 at a time with a 2 s limit, and records the error object. - Browser only, readonly category (no observation).
mm network-log requests|console [--cursor <n>] [--since <iso|epoch-ms>] [--limit <n>] [--url <glob-or-text>] [--errors] [--clear], mm network-log mark|clear and mm network-log configure [--console-levels <list>] [--rpc-errors|--no-rpc-errors]. A flag without a valid value fails with a usage error before any request is sent.
Playwright 1.57 is the first version that reports the network and console events of an MV3 extension service worker without an environment flag, and network-log depends on them. The playwright and @playwright/test peer and dev dependency ranges are now ^1.57.0. The lockfile still resolves 1.58.1.
Warnings from the Extension are noisy and not useful in a release report. The default console level is now error (uncaught page errors included); configure --console-levels still adds warning or others. A test checks that mark and every read return summary.startedAt, which the release skill uses to detect a relaunch.
Base automatically changed from
cryptotavares/mock-network-request-bodies
to
main
November 18, 2026 09:55
Collaborator
Author
|
Closing in favour of the mm CLI v2 plan (P2-15 events buffer, P2-16 |
This was referenced Nov 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Extension release validation needs, per flow: the slowest endpoints, HTTP and network errors, JSON-RPC methods and console errors. Mobile already gets this from a
fetchinterceptor. The Extension has nothing like it:mm cdpand page-level patches do not reach it, and LavaMoat blocks global patches in production builds.mock-networkonly sees hosts that a rule routes, and it records no status or timing.Playwright 1.57+ reports service-worker requests and console messages on the browser context. So a recorder that only listens can see both the pages and the worker.
What
network_logandmm network-log. It only listens (request,response,requestfinished,requestfailed,console,weberror). It never routes, blocks or changes a request.mm launch(browser only), so agents cannot forget to start it. It keeps recording across navigation, tab switches and service-worker restarts.pageorservice-worker, with page/frame URL) and the JSON-RPC method(s) from the request body (single and batch).erroronly by default, uncaught page errors included. Other levels can be added withconfigure --console-levels. Text is redacted and cut at 2000 characters, with source andurl:line:column.markreturns a cursor, and--cursorreturns only newer records, oldest first, withhasMoreandgap.--since,--url(same glob/substring rules as feat: record request bodies in mock-network #93),--errors,--limitand--clear.key,token,sig, ...).configure --rpc-errorsreads JSON-RPC response bodies (up to 64 KiB, 8 at a time, 2 s timeout) and recordsrpcError. It is off by default.^1.57.0. The peer and dev dependency ranges change from^1.49.0. 1.57 is the first version with service-worker network and console events without an environment flag.CLI
Sample output from the smoke test. The extension's service worker sends a 200, a 404, a JSON-RPC call that reverts, a batch, an aborted request and
console.error.--rpc-errorsis on.{"seq":3,"method":"GET","url":"http://127.0.0.1:47123/ok?from=page","type":"fetch","status":200,"ms":146,"source":"page","pageUrl":"chrome-extension://…/trigger.html?tag=flow1"} {"seq":4,"method":"GET","url":"http://127.0.0.1:47123/ok?tag=flow1&apiKey=[REDACTED]","type":"fetch","status":200,"ms":122,"source":"service-worker"} {"seq":5,"method":"GET","url":"http://127.0.0.1:47123/missing?tag=flow1","type":"fetch","status":404,"ms":0,"source":"service-worker"} {"seq":6,"method":"POST","url":"http://127.0.0.1:47123/v3/[REDACTED]","type":"fetch","status":200,"ms":42,"rpcMethod":"eth_call","rpcError":{"code":-32000,"message":"execution reverted"},"source":"service-worker"} {"seq":9,"method":"GET","url":"http://127.0.0.1:47123/slow","type":"fetch","ms":57,"failure":"net::ERR_ABORTED","source":"service-worker"} {"seq":10,"method":"POST","url":"http://127.0.0.1:47123/v3/[REDACTED]","type":"fetch","status":200,"ms":42,"rpcMethod":["eth_chainId","eth_blockNumber"],"rpcBatchSize":2,"source":"service-worker"}{"seq":1,"level":"error","text":"page error for flow1","source":"page"} {"seq":2,"level":"error","text":"Uncaught TypeError: uncaught in page flow1","source":"page","uncaught":true} {"seq":7,"level":"error","text":"bg flow flow1 failed: https://mainnet.infura.io/v3/[REDACTED]","source":"service-worker"}(
tand some URL fields are left out here. The worker'sconsole.warnandconsole.logare not recorded with the default level.)Cursors start at 0 again after a relaunch.
markand every read returnsummary.startedAt. When it changes, the caller reads from cursor 0 and records a capture gap.Testing
Unit tests: 55 tests in
network-log.test.tswith mocked browser-context events. They cover timing, sources, failures, JSON-RPC single/batch/error capture and its limits, console levels, redaction, buffer limits, cursors,since,clear, andstartedAtacross a relaunch. There are also tests for the CLI, schemas, registry, platform gating and launch.Checks:
yarn lint,yarn buildandCI=1 yarn testpass (60 files, 2227 tests, coverage floors met;network-log.tshas 100% lines).Real smoke test through the daemon and
mmCLI built from this branch, with a tiny MV3 extension and a local HTTP server. The output above comes from it.Playwright version matrix (same extension, service-worker requests / console messages recorded):
PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS=1metamask-extension)Known limits
ServiceWorker.stopWorker,Target.closeTargetand 90 s idle did not stop the worker, andchrome.runtime.reload()disables an unpacked extension. The listeners are on the browser context, so a new worker should report to the same recorder.mm launchis not recorded (for example self-onboarding). The log starts after launch returns.mm mock-networkwithrecord(feat: record request bodies in mock-network #93) for bodies.