dipakprajapati2703/playwright-mcp-server
If you are the rightful owner of playwright-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
Playwright MCP Server is a Model Context Protocol server that integrates Claude Code with Microsoft Playwright for advanced browser automation and debugging capabilities.
Playwright MCP Server - Installation & Frontend Debugging Guide [Cluade Code]
Complete guide for setting up Playwright MCP (Model Context Protocol) server with Claude Code for debugging frontend issues in Magento 2.
Table of Contents
- What is Playwright MCP Server?
- Prerequisites
- Installation
- Configuration
- Available Tools
- Debugging Frontend Issues
- Magento 2 Specific Examples
- Troubleshooting
- Best Practices
What is Playwright MCP Server?
Playwright MCP Server is a Model Context Protocol server that provides Claude Code with browser automation capabilities through Microsoft Playwright. It enables:
- Browser Automation: Navigate, click, fill forms, interact with elements
- Visual Testing: Capture screenshots and videos
- Network Monitoring: Inspect API calls and requests
- Console Logging: Track JavaScript errors and warnings
- Multi-Browser Support: Test across Chromium, Firefox, and WebKit
- Mobile Emulation: Test responsive designs
This is particularly valuable for debugging complex frontend issues in Magento 2 e-commerce platforms.
Prerequisites
Before installing Playwright MCP server, ensure you have:
- Node.js: Version 16 or higher
- npm: Latest version (comes with Node.js)
- Claude Code: Installed and configured
- MCP Configuration:
.mcp.jsonfile in your project root
Check Prerequisites
# Check Node.js version
node --version
# Expected: v16.x.x or higher
# Check npm version
npm --version
# Expected: 8.x.x or higher
# Check if .mcp.json exists
ls -la .mcp.json
Installation
Step 1: Install Playwright MCP Server
You can install the Playwright MCP server globally or use it via npx.
Option A: Global Installation (Recommended)
npm install -g @executeautomation/playwright-mcp-server
Advantages:
- Faster startup time
- No need to download on each use
- Better for frequent use
Option B: Use via npx (No Installation)
# No installation needed - npx will download on first use
npx -y @executeautomation/playwright-mcp-server
Advantages:
- Always uses latest version
- No global package management
- Good for occasional use
Step 2: Verify Installation
# If installed globally
which playwright-mcp-server
# Test with npx
npx @executeautomation/playwright-mcp-server --help
Configuration
Step 1: Create or Update .mcp.json
Create or edit .mcp.json in your project root:
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": [
"-y",
"@executeautomation/playwright-mcp-server"
]
}
}
}
If you have existing MCP servers, add Playwright alongside them:
{
"mcpServers": {
"magento-api-m246": {
"command": "magento-api-mcp",
"env": {
"MAGENTO_API_SWAGGER_PATH": "/var/www/html/m246/swagger.json",
"MAGENTO_API_DB_PATH": "/home/logicrays/.mcp/magento-api/m246.db"
}
},
"playwright": {
"command": "npx",
"args": [
"-y",
"@executeautomation/playwright-mcp-server"
]
}
}
}
Step 2: Restart Claude Code
After updating .mcp.json, you must restart Claude Code:
# If running in terminal, press Ctrl+C and restart
# Or restart your IDE/terminal session
Step 3: Verify MCP Server is Loaded
After restart, check available tools in Claude Code. You should see Playwright-related tools.
Available Tools
Once configured, Playwright MCP provides these tools:
Navigation Tools
playwright_navigate- Navigate to URLsplaywright_screenshot- Capture page screenshotsplaywright_click- Click elementsplaywright_fill- Fill form fieldsplaywright_evaluate- Execute JavaScript on page
Inspection Tools
playwright_get_page_content- Get HTML contentplaywright_wait_for_selector- Wait for elementsplaywright_get_element_text- Extract text contentplaywright_get_element_attribute- Get element attributes
Console & Network Tools
playwright_console_messages- Get console logsplaywright_network_requests- Monitor network activityplaywright_network_responses- Inspect API responses
Browser Management
playwright_new_browser- Launch new browser instanceplaywright_new_page- Open new page/tabplaywright_close- Close browser/pageplaywright_set_viewport- Set screen size (responsive testing)
Debugging Frontend Issues
Common Debugging Workflow
1. Start Browser and Navigate
// Claude will execute:
// 1. Launch browser
// 2. Navigate to your Magento store
// 3. Wait for page load
Example Request:
"Open a browser and navigate to http://localhost/m246/"
2. Capture Initial State
// Take screenshot of homepage
// Get console errors
// Check network requests
Example Request:
"Take a screenshot of the homepage and show me any JavaScript errors"
3. Interact with Elements
// Click buttons, fill forms, navigate
// Monitor behavior and responses
Example Request:
"Click on the 'Add to Cart' button and show me the network requests"
4. Verify Results
// Check DOM changes
// Verify API responses
// Capture final state
Example Request:
"Check if the cart counter updated and take a screenshot"
Magento 2 Specific Examples
Example 1: Debug Product Page Issues
Scenario: Product images not loading correctly
**Request to Claude:**
"Open http://localhost/m246/catalog/product/view/id/123 and:
1. Take a screenshot
2. Check console for JavaScript errors
3. Show me all network requests for images
4. Inspect the gallery element's HTML"
What Claude will do:
- Navigate to product page
- Capture screenshot showing current state
- Extract console errors (e.g., 404 errors, JS exceptions)
- List all image requests with status codes
- Show DOM structure of product gallery
Expected Output:
- Screenshot showing missing images
- Console error: "Failed to load resource: the server responded with a status of 404"
- Network log showing failed image requests
- HTML showing incorrect image paths
Example 2: Debug Add to Cart Functionality
Scenario: Add to Cart button not working
**Request to Claude:**
"Debug the Add to Cart functionality:
1. Navigate to product page SKU-12345
2. Click 'Add to Cart' button
3. Monitor AJAX requests
4. Check for JavaScript errors
5. Verify minicart update"
What Claude will do:
- Open product page
- Click the Add to Cart button
- Capture all XHR/Fetch requests to
/checkout/cart/add/ - Show response data (success/error messages)
- Check if minicart counter updated
- Screenshot before/after states
Expected Output:
- Network request to
/customer/section/load/ - Response showing cart data
- Console errors if AJAX failed
- Minicart DOM changes
Example 3: Debug Checkout Page
Scenario: Shipping method not appearing
**Request to Claude:**
"Debug checkout shipping step:
1. Open checkout page
2. Fill shipping address form
3. Wait for shipping methods to load
4. Take screenshot of shipping methods section
5. Show me the API call to get shipping rates
6. Check for JavaScript errors"
What Claude will do:
- Navigate to
/checkout/ - Fill in address fields (street, city, zip, country)
- Monitor network for
/rest/V1/guest-carts/{cartId}/estimate-shipping-methods - Capture screenshot of shipping options
- Show API response with available methods
- Display any console errors
Expected Output:
- API response showing shipping methods array
- Screenshot showing rendered shipping options
- Console errors if rates failed to load
- Timing information for API calls
Example 4: Debug Bundle Product Custom Options
Scenario: Bundle options not displaying (CellularIsrael/BundleCustomOptions module)
**Request to Claude:**
"Debug bundle product custom options:
1. Open bundle product page
2. Inspect custom options HTML structure
3. Check for JavaScript errors related to options
4. Monitor AJAX calls when selecting options
5. Capture screenshots of option selections"
What Claude will do:
- Navigate to bundle product
- Show HTML of
.product-custom-optionelements - Display RequireJS/Knockout.js errors
- Monitor
/catalog/product/view/AJAX calls - Screenshot each step of option selection
Expected Output:
- DOM structure of custom options
- JavaScript errors (e.g., "Cannot read property 'push' of undefined")
- AJAX requests for option pricing
- Visual confirmation of options rendering
Example 5: Debug Payment Gateway Integration
Scenario: CardknoxDevelopment payment form not appearing
**Request to Claude:**
"Debug Cardknox payment integration:
1. Navigate through checkout to payment step
2. Check if Cardknox payment method is visible
3. Monitor network for Cardknox API calls
4. Inspect iframe elements (if using hosted fields)
5. Show console errors related to payment"
What Claude will do:
- Navigate to checkout payment step
- Check DOM for payment method elements
- Monitor network for
*.cardknox.comrequests - Inspect iframe src and loading status
- Show console errors (CSP issues, loading failures)
Expected Output:
- Payment methods HTML structure
- Cardknox API initialization requests
- Iframe elements and their sources
- CSP or CORS errors if present
Example 6: Debug Responsive Design Issues
Scenario: Mobile menu not working on tablets
**Request to Claude:**
"Test mobile menu on tablet viewport:
1. Set viewport to iPad (768x1024)
2. Navigate to homepage
3. Click hamburger menu icon
4. Take screenshot of opened menu
5. Check for touch event handlers
6. Show any JavaScript errors"
What Claude will do:
- Set browser viewport to 768x1024
- Navigate to homepage
- Find and click
.mobile-menu-toggle - Screenshot showing menu state
- Execute JavaScript to check event listeners
- Display console errors
Expected Output:
- Screenshot showing menu opened/closed state
- Event listeners attached to menu elements
- CSS media query information
- Touch event compatibility issues
Example 7: Debug Search Autocomplete
Scenario: Search suggestions not appearing
**Request to Claude:**
"Debug search autocomplete:
1. Navigate to homepage
2. Click in search box
3. Type 'iphone' slowly
4. Monitor AJAX requests to search endpoint
5. Show autocomplete dropdown HTML
6. Check for JavaScript errors"
What Claude will do:
- Open homepage
- Focus on
.search-fieldinput - Type characters with delays
- Monitor
/search/ajax/suggest/requests - Show autocomplete container HTML
- Display timing and response data
Expected Output:
- AJAX requests with query parameters
- JSON response with product suggestions
- HTML structure of dropdown
- JavaScript errors (if autocomplete fails)
Example 8: Debug Customer Login Issues
Scenario: Login form not submitting
**Request to Claude:**
"Debug customer login:
1. Navigate to login page
2. Fill email and password fields
3. Click login button
4. Monitor POST request to /customer/account/loginPost/
5. Show response data
6. Check for validation errors
7. Capture screenshot of result"
What Claude will do:
- Open
/customer/account/login/ - Fill form fields
- Submit form
- Capture POST request with form data
- Show response (redirect or error)
- Check for form validation messages
- Screenshot final state
Expected Output:
- POST request with credentials (masked)
- Response status code (302 redirect or 400 error)
- Error messages in DOM
- Console errors if AJAX failed
Example 9: Debug Page Performance
Scenario: Slow page load times
**Request to Claude:**
"Analyze homepage performance:
1. Navigate to homepage with network monitoring
2. Show all network requests with timing
3. Identify slowest resources
4. Check for render-blocking resources
5. Show total page load time
6. Recommend optimizations"
What Claude will do:
- Load homepage with performance monitoring
- List all requests with waterfall timing
- Highlight requests >1s
- Identify blocking CSS/JS
- Calculate total load time
- Suggest improvements
Expected Output:
- Network waterfall chart data
- Slow resources identified (e.g., large images, slow APIs)
- Blocking resources list
- Total load time: X seconds
- Recommendations (image optimization, lazy loading, etc.)
Example 10: Debug Cookie/Session Issues
Scenario: Shopping cart losing items on refresh
**Request to Claude:**
"Debug cart session persistence:
1. Navigate to product page
2. Add product to cart
3. Check cookies set by server
4. Refresh the page
5. Verify cart still contains items
6. Show session cookie details"
What Claude will do:
- Open product page
- Add item to cart
- Extract all cookies (frontend, private_content_version)
- Refresh browser
- Check cart contents
- Show cookie values and expiration
Expected Output:
- Cookie list:
PHPSESSID,mage-cache-storage,form_key - Session ID before/after refresh
- Cart persistence status
- Cookie expiration times
Troubleshooting
Issue 1: MCP Server Not Loading
Symptoms:
- Playwright tools not available in Claude Code
- Error: "MCP server failed to start"
Solutions:
# 1. Verify installation
npm list -g @executeautomation/playwright-mcp-server
# 2. Test npx execution
npx @executeautomation/playwright-mcp-server --help
# 3. Check .mcp.json syntax
cat .mcp.json | jq .
# Should output valid JSON
# 4. Restart Claude Code completely
# Exit all sessions and restart
Issue 2: Browser Launch Failures
Symptoms:
- Error: "Failed to launch browser"
- Error: "Executable doesn't exist"
Solutions:
# 1. Install Playwright browsers manually
npx playwright install
# 2. Install specific browser
npx playwright install chromium
# 3. Install system dependencies (Linux)
npx playwright install-deps
# 4. Check browser installation
npx playwright --version
Issue 3: Timeout Errors
Symptoms:
- Error: "Timeout waiting for selector"
- Error: "Navigation timeout exceeded"
Solutions:
**Increase timeouts in requests:**
"Navigate to the page with a 30-second timeout"
"Wait up to 60 seconds for the element to appear"
**Use explicit waits:**
"Wait for the network to be idle before taking screenshot"
"Wait for the loading spinner to disappear"
**Check page load:**
"Check if the page is still loading"
"Show me the current page state"
Issue 4: Element Not Found
Symptoms:
- Error: "Element not found"
- Error: "Selector resolved to hidden element"
Solutions:
**Debug selector:**
"Show me all elements matching '.add-to-cart'"
"List all buttons on the page"
"Get the HTML of the product section"
**Use alternative selectors:**
"Click the button with text 'Add to Cart'"
"Find element by aria-label='Add to Cart'"
"Use XPath to find the submit button"
**Wait for visibility:**
"Wait for the button to become visible"
"Check if the element is hidden by CSS"
Issue 5: Network Requests Not Captured
Symptoms:
- Missing AJAX requests in logs
- Empty network request list
Solutions:
**Start monitoring before navigation:**
"Start browser with network monitoring enabled"
"Monitor network, then navigate to the page"
**Clear and retry:**
"Close browser and start fresh with network monitoring"
"Clear cache and reload with network capture"
**Check timing:**
"Wait 5 seconds after navigation, then show network requests"
"Monitor network for 10 seconds after clicking the button"
Best Practices
1. Always Start with Clean State
**Good Practice:**
"Open a new browser, clear cookies, and navigate to homepage"
**Why:** Ensures reproducible results without cached data
2. Use Explicit Waits
**Good Practice:**
"Wait for the product grid to load, then take screenshot"
**Why:** Avoids race conditions and timing issues
3. Capture Context for Debugging
**Good Practice:**
"Take screenshot, show console errors, and list network requests"
**Why:** Provides complete picture of issue
4. Test Across Viewports
**Good Practice:**
"Test on desktop (1920x1080), tablet (768x1024), and mobile (375x667)"
**Why:** Ensures responsive design works correctly
5. Monitor Network Performance
**Good Practice:**
"Load the page with network monitoring and show requests over 1 second"
**Why:** Identifies performance bottlenecks
6. Use Specific Selectors
**Good Practice:**
"Click button[data-role='proceed-to-checkout']"
**Better than:** "Click the checkout button"
**Why:** More reliable and specific
7. Document Test Scenarios
**Good Practice:**
Create test documentation:
1. Steps to reproduce
2. Expected behavior
3. Actual behavior
4. Screenshots/logs
5. Environment details
**Why:** Makes debugging reproducible
8. Clean Up Resources
**Good Practice:**
"After testing, close the browser to free resources"
**Why:** Prevents memory leaks and resource exhaustion
Advanced Usage
Custom Browser Configuration
If you need custom browser settings, you can create a wrapper script:
1. Create playwright-wrapper.js:
#!/usr/bin/env node
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({
headless: false, // Show browser window
slowMo: 100, // Slow down actions
args: [
'--disable-web-security', // Disable CORS (for testing only!)
'--ignore-certificate-errors'
]
});
const context = await browser.newContext({
viewport: { width: 1920, height: 1080 },
userAgent: 'Custom User Agent',
locale: 'en-US',
timezoneId: 'America/New_York',
permissions: ['geolocation']
});
const page = await context.newPage();
// Your automation code here
})();
2. Update .mcp.json:
{
"mcpServers": {
"playwright": {
"command": "node",
"args": ["/path/to/playwright-wrapper.js"]
}
}
}
Debugging with Playwright Inspector
For complex debugging, use Playwright Inspector:
# Set environment variable
export PWDEBUG=1
# Run your test
npx playwright test
# Or use inspector directly
npx playwright codegen http://localhost/m246/
This opens a GUI for:
- Step-by-step debugging
- Selector picker
- Network inspection
- Screenshot comparison
Integration with Magento 2 Development Workflow
1. Theme Development
**Testing custom theme changes:**
1. "Navigate to homepage with Custom theme"
2. "Compare screenshot with Luma theme"
3. "Check CSS overrides are applied"
4. "Test responsive breakpoints"
2. Module Testing
**Testing custom module frontend:**
1. "Enable module: bin/magento module:enable Vendor_Module"
2. "Clear cache and reload page"
3. "Test module functionality"
4. "Check for JavaScript errors"
3. Integration Testing
**Test complete user flows:**
1. "Browse products → Add to cart → Checkout → Payment"
2. "Monitor all API calls"
3. "Verify data consistency"
4. "Check error handling"
4. Regression Testing
**Verify no regressions after updates:**
1. "Take baseline screenshots before upgrade"
2. "Apply Magento patches/updates"
3. "Re-run tests and compare screenshots"
4. "Identify visual differences"
Security Considerations
1. Never Commit Sensitive Data
# Add to .gitignore
.mcp.json.local
playwright-config.json
screenshots/
videos/
2. Use Environment Variables
{
"mcpServers": {
"playwright": {
"command": "npx",
"args": ["-y", "@executeautomation/playwright-mcp-server"],
"env": {
"BASE_URL": "${MAGENTO_BASE_URL}",
"TEST_USER": "${TEST_USER_EMAIL}",
"TEST_PASS": "${TEST_USER_PASSWORD}"
}
}
}
}
3. Sanitize Logs
Always review logs before sharing:
- Remove passwords
- Remove API keys
- Remove customer data
- Remove session tokens
Resources
Official Documentation
- Playwright Docs: https://playwright.dev/
- Playwright MCP Server: https://github.com/executeautomation/playwright-mcp-server
- MCP Protocol: https://modelcontextprotocol.io/
Magento 2 Resources
- Magento DevDocs: https://devdocs.magento.com/
- Frontend Developer Guide: https://developer.adobe.com/commerce/frontend-core/guide/
Community
- Playwright Discord: https://discord.gg/playwright
- Magento Stack Exchange: https://magento.stackexchange.com/
Summary
Playwright MCP Server enables powerful frontend debugging capabilities for Magento 2:
- Automated Testing: Click, fill, navigate programmatically
- Visual Debugging: Screenshots and videos
- Network Analysis: Monitor AJAX, API calls
- Console Monitoring: JavaScript errors and warnings
- Responsive Testing: Multiple viewports
- Performance Analysis: Page load metrics
By integrating Playwright with Claude Code, you can efficiently debug complex frontend issues in your Cellular Israel Magento 2 e-commerce platform.
Last Updated: 2025-11-05 Magento Version: 2.4.6-p10 Node Version: 18.19.1 Playwright MCP Version: Latest (via npx)