Browser CLI
@msw-dev-tool/browser-cli is built for AI agents. It exposes machine-readable,
one-shot commands so an agent can programmatically control an in-browser
msw-dev-tool session. It is not a human interactive TUI.
@msw-dev-tool/browser-cli lets an AI agent control an in-browser MSW Dev Tool
session through Chrome DevTools Protocol (CDP). It uses the same handler commands
and JSON output conventions as the Node CLI, but requires an explicit browser tab.
Install
pnpm add -D @msw-dev-tool/browser-cli @msw-dev-tool/core mswStart the Chrome instance controlled by your AI with a remote-debugging port. Use a separate profile: this port gives local processes full browser-debugging access.
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
--remote-debugging-port=9222 \
--user-data-dir=/tmp/msw-dev-tool-chromeConfigure your AI agent’s Chrome DevTools MCP server to connect to the same
endpoint. For example, in Codex add the following to .codex/config.toml and
restart the MCP session:
[mcp_servers.chrome-devtools]
command = "npx"
args = ["-y", "chrome-devtools-mcp@latest", "--browser-url=http://127.0.0.1:9222"]Your MCP client and msw-dev-tool-browser can then inspect the same Chrome tabs. See
the Chrome DevTools MCP guide for connecting to a running Chrome instance
for other operating systems and remote-debugging details.
Your application must call setupDevToolWorker(...handlers) in the target tab.
That registers the in-page control endpoint used by the CLI.
Choose a tab
sessionStorage is scoped to a tab, even for pages on the same origin. List the
available page targets and copy the intended id:
msw-dev-tool-browser tabs --cdp-url http://127.0.0.1:9222Every other command requires both --cdp-url and --target:
msw-dev-tool-browser list --cdp-url http://127.0.0.1:9222 --target <target-id>
msw-dev-tool-browser set-behavior '<handler-id>' delay --cdp-url http://127.0.0.1:9222 --target <target-id>Commands
msw-dev-tool-browser session --cdp-url ... --target <target-id>
msw-dev-tool-browser list --cdp-url ... --target <target-id>
msw-dev-tool-browser get '<handler-id>' --cdp-url ... --target <target-id>
msw-dev-tool-browser set-behavior '<handler-id>' delay --cdp-url ... --target <target-id>
msw-dev-tool-browser add-temp --json '<temp-handler-json>' --cdp-url ... --target <target-id>
msw-dev-tool-browser remove-temp '<handler-id>' --cdp-url ... --target <target-id>
msw-dev-tool-browser reset --cdp-url ... --target <target-id>All commands print JSON. Changes are applied immediately: the CLI calls the same
in-memory handler store used by the Dev Tool UI and persists the resulting state
to sessionStorage. A refresh is only needed to confirm persisted state survives
page reload, not to apply a CLI mutation.
reset immediately restores handlers from the code supplied to
setupDevToolWorker(). If a target reports that no browser session is initialized,
open the tab where that setup function has run.