chrome-devtools-mock

Intercept browser API calls to mock frontend data without changing source code.

8|5|Updated Dec 3, 2025
One-click install
npx skills add https://github.com/notdp/.dotfiles --skill chrome-devtools-mock
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: chrome-devtools-mock
Source: https://github.com/notdp/.dotfiles/tree/main/skills/chrome-devtools-mock
Command: npx skills add https://github.com/notdp/.dotfiles --skill chrome-devtools-mock

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

通过 Chrome DevTools MCP 的 navigate_page + initScript 注入 XMLHttpRequest 拦截,在浏览器层面 mock API 数据,无需修改源码,帮助快速预览 UI 与验证前端逻辑。

Core Features & Use Cases

  • 通过 initScript 在页面加载前注入拦截逻辑,确保 API 请求在实际网络调用前被拦截并返回 mock 数据。
  • 支持按具体 API 路径匹配和精确路由,避免误拦截。
  • 适用于前端无后端、接口变更频繁、需要快速验证 UI 的场景。

Quick Start

Navigate to the target page and inject the initScript before page load to begin mocking.

Frequently Asked Questions about chrome-devtools-mock

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I mock API data in the browser without modifying source code?

You can mock API data in the browser without modifying source code by injecting an XMLHttpRequest interceptor via Chrome DevTools Protocol. This intercepts network requests before actual calls, returning deterministic mock data for UI prototyping and testing.

What is the best way to test frontend UI when backend APIs are unavailable?

The best way to test frontend UI when backend APIs are unavailable is injecting a deterministic XHR interceptor before page load. This approach uses Chrome DevTools Protocol to match specific API paths and return mock data, allowing rapid UI verification.

How does initScript intercept XHR requests before page load?

The initScript intercepts XHR requests by executing JavaScript before the page loads, applying an XMLHttpRequest interceptor that captures API calls prior to actual network execution. This ensures deterministic mock data is returned before any real network call occurs.

Does Chrome DevTools Protocol support mocking API responses for specific routes?

Yes, Chrome DevTools Protocol supports mocking API responses for specific routes. By using initScript to inject an XHR interceptor, you can apply exact API path matching to avoid mistakenly intercepting non-target network requests during browser-testing.

Can I use navigate_page to inject mock data for feature demos?

Yes, you can use navigate_page to inject mock data for feature demos. It works with initScript to inject the XHR interceptor before page load, ensuring the browser receives mocked API data without needing backend availability or source code changes.

What are the limitations of using XHR interception for browser testing?

A limitation of using XHR interception for browser testing is that it requires Chrome DevTools Protocol support with navigate_page and initScript. It specifically targets XMLHttpRequests, meaning other network request types may not be intercepted for mocking.