Trong thời đại AI và automation, việc kết hợp GitHub Copilot Agent với browser automation đã mở ra những khả năng mới thú vị cho developers. Playwright MCP (Model Context Protocol) server là công cụ cho phép AI agents như GitHub Copilot tương tác trực tiếp với web browsers, mang đến trải nghiệm automation hoàn toàn mới. Trong bài viết này, chúng ta sẽ khám phá cách sử dụng VS Code với Playwright MCP để cho phép GitHub Copilot Agent tự động tương tác với website demo Demoblaze.
Playwright MCP là gì?
Hiểu về Model Context Protocol (MCP)
Model Context Protocol (MCP) là một chuẩn mở cho phép các AI models tương tác với external tools và services thông qua một giao diện thống nhất. Cụ thể với Playwright MCP:
- Không phải là testing framework: MCP là một server protocol, không phải framework testing
- Bridge cho AI agents: Cho phép LLM/AI agents điều khiển browser thông qua Playwright
- Structured accessibility snapshots: Sử dụng accessibility tree của browser thay vì screenshots, giúp LLM hiểu được cấu trúc trang web một cách structured
- Fast and lightweight: Nhanh hơn và nhẹ hơn các phương pháp dựa trên visual analysis
Playwright MCP hoạt động như thế nào?
Playwright MCP hoạt động chủ yếu ở hai chế độ: Snapshot Mode (mặc định) sử dụng accessibility tree của browser để hiểu cấu trúc trang web, và Vision Mode sử dụng screenshots cho các tương tác phức tạp hơn.
Snapshot Mode mang lại những ưu điểm:
- Fast: Tạo và parse accessibility tree nhanh hơn nhiều so với xử lý screenshots
- LLM-friendly: LLM xử lý structured text data hiệu quả hơn
- Deterministic: Tránh sự mơ hồ thường gặp với screenshot-based approaches
Tại sao chọn VS Code với GitHub Copilot Agent?
GitHub Copilot Agent Mode
GitHub Copilot Agent Mode là tính năng mới cho phép Copilot thực hiện các hành động complex, từ việc sửa lỗi code generation đến xây dựng webapp, thậm chí tương tác với external services.
Agent Mode có khả năng:
- Action-oriented: Không chỉ trả lời câu hỏi mà thực hiện các task cụ thể
- Multi-step execution: Thực hiện các subtasks tự động để hoàn thành mục tiêu chính
- Tool integration: Tích hợp với MCP servers để mở rộng capabilities
- Self-healing: Phân tích runtime errors và tự sửa lỗi
MCP Integration trong VS Code
VS Code hỗ trợ MCP servers từ phiên bản 1.99, cho phép GitHub Copilot Agent kết nối với external tools và services. Điều này mở ra khả năng:
- Database interactions: Kết nối và query databases
- API calls: Gọi các external APIs
- File operations: Thao tác với file system
- Browser automation: Điều khiển web browsers thông qua Playwright
Giới thiệu về Demoblaze – Target website lý tưởng
Demoblaze vẫn là lựa chọn tuyệt vời cho việc thực hành browser automation với AI:
Ưu điểm của Demoblaze:
- Complete e-commerce features: Product catalog, shopping cart, user authentication
- Stable structure: Cấu trúc ổn định, phù hợp cho AI learning
- Realistic scenarios: Các tình huống giống thực tế
- Good accessibility: Accessibility tree rõ ràng, thuận lợi cho Playwright MCP
Các tính năng chính:
- Product browsing: Duyệt sản phẩm theo categories
- Shopping flow: Thêm vào giỏ hàng và checkout
- User registration: Đăng ký và đăng nhập
- Responsive design: Hoạt động tốt trên mobile và desktop

Cài đặt và cấu hình Playwright MCP
Bước 1: Chuẩn bị môi trường
Yêu cầu hệ thống:
- Node.js (LTS version)
- VS Code 1.99 hoặc mới hơn
- GitHub Copilot và GitHub Copilot Chat extensions
- Đăng nhập GitHub trong VS Code
Bước 2: Kích hoạt MCP support trong VS Code
- Mở VS Code Settings (
Ctrl+,
) - Tìm kiếm
chat.mcp.enabled
- Bật setting này để enable MCP support trong agent mode
Bước 3: Cài đặt Playwright MCP Server
Phương pháp 1: Sử dụng VS Code CLI
Cài đặt Playwright MCP server
# Cài đặt Playwright MCP server code --add-mcp '{"name":"playwright","command":"npx","args":["@playwright/mcp@latest"]}'
Phương pháp 2: Cấu hình manual trong workspace
Tạo file .vscode/mcp.json
trong workspace:
{ "mcpServers": { "playwright": { "command": "npx", "args": [ "@playwright/mcp@latest", "--browser", "chromium", "--headless" ] } } }
Phương pháp 3: Global settings
Thêm vào VS Code settings.json
:
{ "mcp": { "servers": { "playwright": { "command": "npx", "args": [ "@playwright/mcp@latest", "--browser", "msedge" ] } } } }
Bước 4: Verify MCP Server
- Sử dụng command palette (
Ctrl+Shift+P
) - Chạy
MCP: List Servers
- Kiểm tra và start Playwright MCP server nếu cần
Sử dụng GitHub Copilot Agent với Demoblaze
Kích hoạt Agent Mode
- Mở GitHub Copilot Chat (
Ctrl+Shift+I
) - Trong prompt box, chọn “Agent” mode từ dropdown
- Click vào tools button để select các tools muốn agent sử dụng
Ví dụ thực hành 1: Browse products trên Demoblaze
Prompt cho Agent:
Navigate to demoblaze.com, browse the Phones category, and give me a summary of the available phones with their prices.
Agent sẽ thực hiện:
- Mở browser với Demoblaze
- Click vào Phones category
- Thu thập thông tin sản phẩm
- Tổng hợp và báo cáo kết quả
Ví dụ thực hành 2: Shopping flow automation
Prompt cho Agent:
Go to demoblaze.com, add the first phone to cart, then navigate to cart and show me the details of the added product.
Quy trình Agent thực hiện:
- Navigate đến homepage
- Click vào sản phẩm đầu tiên trong Phones
- Add to cart và handle confirmation dialog
- Navigate đến cart page
- Extract và report product details
Ví dụ thực hành 3: Comparative analysis
Advanced prompt:
Visit demoblaze.com and compare the price range between Phones, Laptops, and Monitors categories. Create a summary table showing min, max, and average prices for each category.
Agent workflow:
- Browse từng category
- Collect price data
- Perform calculations
- Generate formatted comparison table
Advanced Configuration Options
Customizing Browser Behavior
{ "mcpServers": { "playwright": { "command": "npx", "args": [ "@playwright/mcp@latest", "--browser", "chromium", "--headless", "--user-data-dir", "./browser-profile" ] } } }
Vision Mode cho phức tạp interactions
Vision Mode sử dụng screenshots và hoạt động tốt với computer use models có thể tương tác dựa trên tọa độ X,Y:
{ "mcpServers": { "playwright": { "command": "npx", "args": [ "@playwright/mcp@latest", "--vision" ] } } }
Isolated vs Persistent Profiles
Isolated mode (mỗi session độc lập):
{ "args": [ "@playwright/mcp@latest", "--isolated" ] }
Persistent profile (giữ lại login state):
{ "args": [ "@playwright/mcp@latest", "--user-data-dir", "./persistent-profile" ] }
Các Use Cases thực tế với Demoblaze
1. E-commerce Testing với AI
Prompt:
Test the complete shopping flow on demoblaze.com: browse products, add multiple items to cart, and verify the cart total calculation is correct.
2. UI/UX Analysis
Prompt:
Analyze the user experience on demoblaze.com navigation. Check if all category links work properly and report any accessibility issues.
3. Data Extraction
Prompt:
Extract all product information from demoblaze.com including names, prices, and descriptions. Format the data as a JSON structure.
4. Performance Monitoring
Prompt:
Monitor the page load times for different sections of demoblaze.com and identify any performance bottlenecks.
Troubleshooting và Best Practices
Common Issues và Solutions
MCP Server không start:
- Kiểm tra Node.js installation
- Verify network connectivity
- Check VS Code permissions
Browser không mở:
- Trên Windows, cần cài đặt Chrome trước khi chạy tests
- Kiểm tra browser path configuration
- Try different browser options
Agent không sử dụng tools:
- Verify MCP server status
- Enable tools trong Agent mode interface
- Check tool permissions
Performance Optimization
Sử dụng headless mode cho performance:
{ "args": ["@playwright/mcp@latest", "--headless"] }
Configure timeout settings:
{ "args": [ "@playwright/mcp@latest", "--timeout", "30000" ] }
Security và Privacy Considerations
Data Protection
- Local execution: MCP server chạy local, không gửi data ra external services
- Controlled access: Có thể restrict tools được phép sử dụng
- Profile isolation: Sử dụng isolated mode để tránh leak data giữa sessions
Best Security Practices
- Review agent requests trước khi approve
- Limit tool permissions chỉ những gì cần thiết
- Monitor browser activity khi agent đang chạy
- Use isolated profiles cho testing purposes
Tương lai của Browser Automation với AI
Emerging Trends
MCP đang trở thành standard cho AI models tương tác với services và applications, đánh dấu kỷ nguyên mới của AI-driven automation. Những xu hướng đáng chú ý:
- Multi-agent collaboration: Nhiều agents làm việc cùng nhau
- Context-aware automation: AI hiểu context tốt hơn từ accessibility data
- Self-improving workflows: Agents học từ user feedback
Integration Opportunities
- CI/CD pipelines: Tích hợp automated testing với AI agents
- Monitoring và alerting: AI agents monitor website changes
- Content management: Automated content updates và validation
Tài nguyên học tập và mở rộng
Chính thức Documentation
Community Resources
- MCP Servers Repository: Khám phá các MCP servers khác
- Playwright Documentation: Tìm hiểu sâu về Playwright capabilities
- Danh sách website demo hay sử dụng cho thực hành automation test – Khám phá thêm target websites
Learning Path Suggestions
- Bắt đầu với basic prompts cho simple navigation
- Thực hành với complex scenarios như multi-step workflows
- Tùy chỉnh MCP configuration cho specific needs
- Kết hợp với other MCP servers để mở rộng capabilities
Playwright MCP đã mở ra một chương mới trong browser automation, cho phép GitHub Copilot Agent tương tác intelligently với web applications như Demoblaze. Khác với traditional testing frameworks, MCP mang đến khả năng tự động hóa thông qua natural language prompts, giúp developers và testers làm việc hiệu quả hơn.
Với việc sử dụng accessibility tree thay vì visual analysis, Playwright MCP cung cấp một phương pháp fast, reliable và LLM-friendly cho browser automation. Điều này đặc biệt phù hợp với các website có cấu trúc tốt như Demoblaze.
Tương lai của automation testing đang hướng tới sự kết hợp giữa AI intelligence và traditional tooling. VS Code với Playwright MCP và GitHub Copilot Agent chính là một ví dụ điển hình cho trend này.
Hãy bắt đầu khám phá khả năng của AI-powered browser automation ngay hôm nay và tìm hiểu thêm các kỹ thuật automation khác tại devopsify.co – nơi chia sẻ những kiến thức DevOps và automation testing chất lượng cao.