A Chrome extension for mocking REST and GraphQL API responses. Perfect for testing error handling, edge cases, and UI behavior without modifying your backend.
- 🔄 Mock Status Codes - Change any API response status (200 → 400, 500, etc.)
- 🎯 URL Pattern Matching - Use wildcards (
*) or regex patterns - 📊 GraphQL Support - Filter by operation name
- ⏱️ Response Delays - Simulate slow network conditions
- 📝 Custom Response Bodies - Return custom JSON responses
- 🔌 Easy Toggle - Enable/disable mocking globally or per-rule
- Clone or download this repository
- Open Chrome and navigate to
chrome://extensions/ - Enable Developer mode (toggle in top-right corner)
- Click Load unpacked
- Select the
LeanMockfolder - The extension icon should appear in your toolbar
- Click the LeanMock extension icon in your toolbar
- Click the + button to add a new rule
- Fill in the rule details:
| Field | Description |
|---|---|
| Rule Name | A descriptive name for your rule |
| URL Pattern | The URL pattern to match (supports wildcards and regex) |
| Method | HTTP method to match (GET, POST, PUT, etc.) or ANY |
| GraphQL Operation | (Optional) Match specific GraphQL operations |
| Mock Status | The status code to return |
| Delay | (Optional) Add response delay in milliseconds |
- Click Save Rule
| Pattern | Matches |
|---|---|
*/api/users* |
Any URL containing /api/users |
*/api/v1/login |
Any URL ending with /api/v1/login |
/.*\/graphql$/ |
Regex: URLs ending with /graphql |
example.com |
Any URL containing example.com |
For GraphQL APIs, you can:
- Set the URL pattern to match your GraphQL endpoint (e.g.,
*/graphql) - Specify the GraphQL Operation name to mock specific queries/mutations
Example: Mock only the GetUser query while allowing other operations to pass through.
- URL Pattern:
*/api/auth/login - Method: POST
- Status: 401 Unauthorized
- URL Pattern:
*/api/* - Method: ANY
- Status: 500 Internal Server Error
- URL Pattern:
*/api/search* - Method: GET
- Status: 200 OK
- Delay: 3000ms
- URL Pattern:
*/graphql - Method: POST
- GraphQL Operation: CreatePost
- Status: 400 Bad Request
LeanMock intercepts fetch() and XMLHttpRequest calls in the browser. When a request matches one of your rules:
- The original request may or may not be sent (depending on configuration)
- The response is modified to return your specified status code
- Optional custom response body is returned
- Console logs show intercepted requests:
[LeanMock] Intercepted GET /api/users → Status: 404
The extension consists of:
manifest.json- Extension configurationbackground.js- Service worker for state managementcontent.js- Injects interceptor into pagesinterceptor.js- Actual fetch/XHR interception logicpopup.html/js/css- Extension popup UI