Add API mocking functionality to Playwright MCP #117
Closed
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.
API Mocking Functionality for Playwright MCP
Overview
This pull request introduces API mocking capabilities to the Playwright MCP project, allowing users to intercept and modify network requests during testing and automation. This feature enhances the toolkit by providing a way to test applications without relying on actual backend services.
Features Added
browser_mock_api: A new tool to intercept and mock API responsesbrowser_clear_mock: A complementary tool to remove API mocksImplementation Details
New Files
src/tools/mock.ts: Implements the core API mocking functionalityModified Files
src/index.ts: Integrates the mocking tools into both tool modesREADME.md: Updated documentation to include the new featuresUse Cases
Testing without backend dependencies:
Offline development:
Edge case testing:
Consistent testing environments:
Example Usage
Technical Design
The implementation leverages Playwright's route handling capabilities, allowing precise control over network requests. The tools are designed to integrate seamlessly with the existing Playwright MCP architecture and follow the established patterns for consistency.
The API mocking feature is designed to work in both snapshot and screenshot modes, ensuring compatibility with all usage scenarios of Playwright MCP.