For AI agents: the complete documentation index is available at https://nhanbe.id.vn/llms.txt, the full documentation bundle is available at https://nhanbe.id.vn/llms-full.txt, and this page is available as Markdown at https://nhanbe.id.vn/ai/debug-web-copilot-browser-mcp.md.

Use browser tools with agents

Dùng agent của GitHub Copilot trong VS Code để tái hiện lỗi trên browser, đọc console, sửa và verify; khi nào cần thêm Playwright MCP.

Use browser tools with agents copilot

Browser tools cung cấp agent với giao diện tương tác để feedback loop cho phát triển web. Nó là tính năng built-in của của Vscode.

Start the application, open it in the browser, test the sign-up flow, and fix any issues you find. Verify the fix before finishing.

How the browser feedback loop works

alt text

Chọn đúng công cụ

CáchAi điều khiển browserDùng khi
Browser toolsAgent tự mở tab, tự thao tácVerify một luồng, tái hiện bug, kiểm tra responsive
Add to ChatBạn chọn element, screenshot, console logChỉ đúng chỗ sai, không muốn mô tả bằng lời
Share with AgentBạn mở tab, cấp quyền cho agentFlow cần login, cookie, state có sẵn
Playwright MCPAgent chạy Playwright qua MCPCần trace, nhiều tab, hoặc profile Chrome riêng
DevTools MCPAgent đọc performance/network traceDebug chậm, memory leak, request sai

What agents can do in the browser

Build-in browser tools include:

  • Page navigation: openBrowserPage, navigatePage.
  • Page content and appearance: readPage, screenshotPage.
  • User interaction: clickElement, hoverElement, dragElement, typeInPage, handleDialog.
  • Custom browser automation: runPlaywrightCode.

Prompt mẫu

Các prompt mẫu

  • Cách khởi động ứng dụng và mở URL nào
  • Hành trình người dùng cần follow.
  • Kết quả mong đợi
  • Agents có nên sửa các vấn đề đã phát hiện không.
  • Các kiểm tra mà agent nên lặp lại sau khi sửa lỗi.

Xây dựng là xác minh một tính năng

Implement the profile form from the requirements. Start the app and use the browser to verify that valid changes save, invalid input shows an error, and cancel restores the original values. Fix any issues and verify the complete flow again.

Tái hiện và sửa lỗi

Open http://localhost:3000 and reproduce this issue: submitting the checkout form twice creates duplicate orders. Find the cause, fix it, and repeat the same browser steps to verify that only one order is created.

Xem xét hành vi phản hồi

Open the dashboard and inspect it at desktop and mobile viewport sizes. Verify that the navigation remains usable and no content overflows. Fix layout issues and capture screenshots of the final result.

Tái hiện và sửa một bug

Chạy `npm run dev`, mở http://localhost:5173/checkout.
Giỏ hàng còn 1 sản phẩm, bấm "Áp mã" với mã SAVE10.
Kỳ vọng: tổng tiền giảm 10% và hiện dòng giảm giá.
Thực tế: nút quay vòng mãi không dừng.

Đọc console và network của trang, chỉ ra request nào treo.
Sửa nguyên nhân gốc, không chỉ thêm timeout.
Sau khi sửa, chạy lại đúng flow trên và báo kết quả từng bước.

Kiểm tra responsive

Mở trang chủ ở 1440, 768 và 375 px.
Ở mỗi kích thước, chụp screenshot phần header và lưới sản phẩm.
Menu phải thu thành nút hamburger dưới 768 px và mở/đóng được.
Liệt kê chỗ vỡ layout kèm kích thước, chưa sửa.

Audit accessibility

Review the sign-in page for accessible names, heading structure, and keyboard operation. Exercise the form without a mouse, fix issues you find, and verify the flow again.

Prompt tốt luôn có: cách chạy app, URL, hành động, kết quả mong đợi, và có sửa hay không.

Đưa context từ browser vào chat

Không phải lúc nào cũng muốn agent tự bấm. Khi bạn đã nhìn thấy chỗ sai, dùng Add to Chat trên toolbar của integrated browser:

  • Page elements — chọn một element, đính kèm HTML, CSS và screenshot.
  • Element comments — gắn một yêu cầu riêng cho từng element, gửi một lần.
  • Screenshots — viewport, vùng chọn, hoặc full page.
  • Console logs — đính kèm lỗi runtime.
1. Mở app trong integrated browser.
2. Add to Chat → Comment on Elements.
3. Chọn menu điều hướng: "Thu thành nút menu dưới 768px."
4. Chọn form: "Căn lại field, hiện lỗi ngay dưới input."
5. Gửi prompt, rồi yêu cầu agent verify ở cả desktop và mobile.

Tab đang đăng nhập

Agent chỉ thấy tab do chính nó mở. Tab bạn mở là session riêng, có cookie và login state — agent không đọc được cho tới khi bạn bấm Share with Agent trên toolbar. Bấm lần nữa để thu hồi ngay.

Đây là cách duy nhất để test flow sau đăng nhập mà không phải nhét credential vào prompt.

Warning

Agent mở tab dùng session in-memory riêng

Không chia sẻ cookie với tab khác của bạn. Ngược lại, tab đã share thì agent thấy đúng những gì bạn đang thấy, gồm cả token trong localStorage. Share xong nhớ thu hồi.

Khi browser tools chưa đủ: MCP

Ba trường hợp thường gặp:

  1. Cần trace performance hoặc đọc network chi tiết — browser tools chỉ đọc console, không có waterfall.
  2. Cần chạy trên profile Chrome thật với extension, proxy, certificate nội bộ.
  3. Cần nhiều tab song song hoặc flow dài mà runPlaywrightCode không đủ.

Cấu hình workspace

Copilot đọc file .mcp.json ở root workspace:

.mcp.json
{
  "mcpServers": {
    "playwright": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@playwright/mcp@latest"],
      "tools": ["*"]
    }
  }
}

Cấu hình dùng chung mọi workspace thì đặt ở ~/.copilot/mcp-config.json (hoặc $COPILOT_HOME/mcp-config.json). Cùng schema mcpServers.

Thêm bằng UI: MCP: Add Server, chọn Copilot Global hoặc workspace root. Sau đó mở một tool call thử — thêm config không có nghĩa là server đã chạy.

[Đừng nhầm hai format]

.vscode/mcp.json và profile mcp.json dùng format cũ servers, thuộc harness Local đã deprecated. Copilot không đọc trực tiếp. Config mới thì dùng mcpServers.

DevTools MCP cho performance

Browser tools đọc được console nhưng không có waterfall hay trace. Thêm Chrome DevTools MCP khi cần nhìn thời gian request, long task, layout shift:

Nen cai bang UI Vscode

Mở /checkout, ghi một performance trace cho tới khi trang ổn định.
Liệt kê 3 long task dài nhất và request chậm nhất, kèm file:line nếu suy ra được.

Playwright MCP hay browser tools?

ViệcBrowser toolsPlaywright MCP
Bấm, đọc DOM, screenshotCóCó
Trace, video, nhiều browserKhôngCó
Dùng profile Chrome của bạnKhôngCó (--channel chrome)
Cài đặtKhông cầnNode 18+, npx
Tốn token mỗi lần gọiÍtNhiều hơn (snapshot lớn)

Mặc định cứ dùng browser tools. Chỉ thêm Playwright MCP khi đã gặp giới hạn cụ thể, vì mỗi MCP server là thêm một process chạy code trên máy bạn.

Danger

MCP server chạy với quyền của bạn

Chỉ cài server từ nguồn tin được. Đừng commit token vào .mcp.json — dùng ${VAR} và để biến môi trường ở máy chạy.

Các feature agent nên dùng kèm

Plan trước khi sửa. Bug lạ thì bảo agent đọc code và ra giả thuyết trước, chưa đụng file. Plan sai thì sửa plan rẻ hơn review diff.

Chưa sửa gì. Đọc #codebase và cho tôi 3 giả thuyết về lỗi hydration này,
kèm cách kiểm chứng từng cái trên browser.

Subagent cho phần thăm dò. Agent chính giao việc "tìm component nào render ra cái nút này" cho subagent. Log tìm kiếm không làm đầy chat chính, còn agent chính giữ context để sửa.

Custom agent chỉ đọc. Tạo agent chỉ có tool đọc để review thay đổi sau khi sửa. Không có tool ghi thì không sợ nó tự sửa thêm.

Instructions cho cách chạy app. Agent đoán sai lệnh dev server là mất một lượt. Ghi thẳng vào .github/copilot-instructions.md:

## Chạy app
- Dev server: `npm run dev` (port 5173).
- Test account: dùng biến môi trường `E2E_USER`, không hard-code.
- Sau khi sửa UI: verify bằng browser tools ở 375px và 1440px.

Checkpoint. Mỗi lần agent sửa file đều có checkpoint. Hướng sửa sai thì quay lại ngay trong hội thoại, không cần git checkout.

Agent Debug Logs khi agent làm sai. Bật github.copilot.chat.agentDebugLog.enabled, rồi hỏi lại log bằng /troubleshoot. Chi tiết xem GitHub Copilot trong VS Code.

Lỗi thường gặp

Hiện tượngNguyên nhânCách xử lý
Không thấy browser toolsSetting tắt hoặc policy chặnBật workbench.browser.enableChatTools, kiểm tra Tools
Agent mở tab mới thay vì tab của bạnTab chưa shareBấm Share with Agent
Không vào được trang login nội bộSession cô lậpShare tab đã đăng nhập
Agent không truy cập được domainNetwork filtering của agentKiểm tra allowlist của tổ chức
Agent báo "đã sửa" nhưng lỗi vẫn cònPrompt thiếu bước verifyThêm "chạy lại flow và báo kết quả"

Kết

Browser tools xử lý 90% việc debug frontend: mở app, bấm, đọc console, sửa, verify. Chỉ kéo MCP vào khi cần trace hoặc profile trình duyệt riêng. Phần còn lại là prompt — nêu rõ acceptance criteria và luôn bắt agent verify lại.

Tham khảo