如何在wsl2环境下给claude code cli 配置 playwright-mcp

前期准备:安装wsl(debian 或 unbuntu)和nodejs

安装Playwright包

  1. wsl内全局安装Playwright包(只需执行一次)
npm install -g playwright
  1. 安装浏览器
npx playwright install
或指定浏览器
npx playwright install chromium firefox chrome
  1. 检查全局安装的Playwright版本
playwright --version
  1. 尝试运行一个简单页面(测试浏览器)
npx playwright open 163.com

wsl本地安装chrome

不安装会报错 Error: browserType.launchPersistentContext: Chromium distribution 'chrome' is not found at /opt/google/chrome/chrome

# 下载chrome到当前目录
$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

# 执行安装(会自动安装到 /opt/google/chrome)
$ sudo apt install ./google-chrome-stable_current_amd64.deb



配置 playwright MCP

针对特定项目

# 进入项目目录
cd to/path/demo

# 添加mcp(运行结果是修改 ~/claude.json ,添加mcpServers一节内容)
claude mcp add playwright npx @playwright/mcp@latest

# 启动
claude

# claude内执行如下命令显示已配置的mcp及其状态,成功会显示:playwright · ✔ connected
/mcp

测试提示词:使用 playwright mcp 打开 163.com

posted @ 2026-01-19 20:34  悠哉大斌  阅读(1)  评论(0)    收藏  举报