playwright-mcp 安装使用的详细教程

大模型如何精确使用 Playwright-MCP 完成页面功能测试:从理论原理到实践应用 随着人工智能技术的快速发展,大语言模型(LLM)在自动化测试领域展现出巨大潜力。Playwright-MCP(模型上下文协议)作为连接大模型与浏览器自动化的桥梁,为页面功能测试带来了革命性的变化。本文将深入探讨 Playwright-MCP 的技术原理、实践应用,并提供精确控制大模型进行页面功能测试的提示词工程策略,帮助开发者和测试工程师掌握这一前沿技术。 阅读详情
AI摘要

本文详细介绍 Playwright MCP 的安装、配置及与 AI 客户端集成的方法。支持多种浏览器和运行模式,利用可访问性树实现高效网页交互,适用于 VS Code、Cursor 等主流编辑器,并提供 Docker 部署方案和常见问题排查建议。

好的,下面是基于 microsoft/playwright-mcp 官方文档(GitHub 仓库)所整理的 “从零到可用” 安装与使用教程。我会尽量写得详细、小白也能跟得上。

如果你遇到问题或某一步不清楚,随时可以问我。


一、Playwright MCP 是什么 & 特性简介

git 地址 https://github.com/microsoft/playwright-mcp

“Playwright MCP Server” 是一个把 Playwright 浏览器自动化能力暴露为 MCP(Model Context Protocol)工具的服务。这样 AI / Agent / LLM 客户端就可以通过结构化的方式(accessibility tree / DOM 等)来与网页交互,而不需要基于截图或视觉模型。 ([GitHub][1])

核心特点:

  • 使用可访问性树 (accessibility tree),不是基于像素的屏幕截图,速度快、资源占用低。 ([GitHub][1])
  • 支持多种浏览器(Chromium、Firefox、WebKit 等) ([GitHub][1])
  • 支持命令行 / 客户端启动方式 / Docker 等多种运行方式 ([GitHub][1])
  • 支持多种运行参数(端口、浏览器类型、隔离模式等) ([GitHub][1])
  • 可以持久化浏览器 profile(保存登录状态等),也可以运行在隔离模式(每次 session 是干净环境) ([GitHub][1])
  • 提供众多工具 (tools),如导航、点击、填表单、快照 (snapshot)、截图 (screenshot)、获取网络请求、关闭浏览器等 ([GitHub][1])

二、安装要求 / 先决条件

在开始之前,请确保你的环境满足以下条件:

  1. Node.js:必须是 18 或以上版本。官方文档指出需要 Node.js ≥ 18。 ([GitHub][1])
  2. 有一个支持 MCP 的客户端 / Agent / 编辑器(例如 VS Code 中的 Copilot Agent、Cursor、Claude Desktop 等)
  3. 有能力运行命令行(Terminal / PowerShell / bash)
  4. 如需在无头环境(headless / 服务器 / CI)中运行,需要合适的图形环境或 headless 浏览器支持

三、安装 Playwright MCP

下面是几种常用的安装方式。

3.1 通过 npx 调用(无需全局安装)

这是最简单的方式:在你客户端 / Agent 的 MCP 配置里,用 npx @playwright/mcp@latest 来启动。

例如:

{
   
   
  "mcpServers": {
   
   
    "playwright": {
   
   
      "command": "npx",
      "args": ["@playwright/mcp@latest"]
    }
  }
}

这个配置是官方文档里建议的标准配置。 ([GitHub][1])

优点:不需要你手动安装全局包,客户端启动时会自动安装和执行。

3.2 安装为项目依赖 / 全局安装

你也可以在你自己的项目里安装:

npm install @playwright/mcp

或者全局安装(不常见):

npm install -g @playwright/mcp

安装后你可以使用命令行来启动它,比如:

npx @playwright/mcp@latest --help

来查看它支持的命令行参数。 ([GitHub][1])


四、基本使用 / 配置参数

Playwright MCP 支持很多命令行参数,来控制浏览器类型、端口、是否隔离、是否保存状态、允许 / 阻止的域等。官方文档列出了这些参数。 ([GitHub][1])

下面是一些常用参数和意义:

参数 作用 默认 / 可选值 /说明
--port <port> 指定 MCP Server 用于 SSE / HTTP 的端口 默认端口(如不指定) ([GitHub][1])
--host <host> 绑定的主机地址 默认是 localhost ([GitHub][1])
--browser <browser> 指定使用哪种浏览器引擎 可选值:chrome, firefox, webkit, msedge ([GitHub][1])
--headless 是否以无头 (headless) 模式运行 默认可能是有窗口模式(视环境) ([GitHub][1])
--isolated 是否使用隔离上下文,每次 session 是干净环境 如果加这个,每次打开都是新的状态,不会保存登录等状态 ([GitHub][1])
--storage-state <path>
Playwright + MCP:用AI对话重新定义浏览器自动化,效率提升300%! Playwright + MCP的结合,标志着自动化领域从“代码驱动”向“AI驱动”的革命性转变。无论是测试工程师、开发人员还是数据分析师,均可借助这一技术栈大幅提升效率。 阅读详情

相关推荐

Playwright MCP浏览器自动化教程

Playwright MCP是一个基于Model Context Protocol的服务器,它在大语言模型(LLM)和Playwright浏览器自动化框架之间架起了一座桥梁。简单来说,它让AI能够。

慕漓的博客 1051

一次搞定:Playwright MCP 从安装到上手的完整教程

MCP(模型上下文协议)犹如AI世界的“USB-C接口”,它统一了AI模型与外部工具之间的通信标准,让AI不仅能理解指令,更能真实调用工具完成任务。Playwright作为微软开源的浏览器自动化框架,凭借多浏览器支持、自动等待机制和强大的选择器引擎,成为实现浏览器操作的核心基础。当Playwright通过MCP协议封装为服务端,AI助手便获得了“操控浏览器的手”,能够完成点击、填表、处理动态iframe、监听网络请求等复杂操作。这一组合在AI Agent开发、自动化测试、动态页面数据提取等场景中展现出巨大价

weixin_29206669的博客 313

用 Cherry Studio 与 Playwright MCP 实现智能浏览器自动化

Playwright MCP 通过“自然语言 → 结构化指令”的转换,大幅降低了浏览器自动化的门槛。无论是与 Copilot 构建智能助手,还是集成到测试流水线,其核心优势在于精准性与可扩展性。后续可探索自定义 MCP 工具链(如邮件通知、数据库校验),打造更闭环的自动化生态。资源扩展官方 GitHub 案例库WSL 跨平台文件交互指南。

Ven%的博客 2325

playwright-mcp 项目全解析:从理论到实践

本文介绍了基于Playwright的增强型自动化工具playwright-mcp及其在AI代理中的应用。该工具支持多浏览器控制、可视化配置和批量任务调度,特别适合LLM驱动的网页自动化操作。

正经教主是个热衷于正经学习分享的教主。 3505

playwright mcp 介绍

介绍微软开源框架 playwright mcp

灵光通码的博客 1142

Playwright MCP:开启浏览器自动化的新篇章

在当今数字化时代,浏览器自动化技术在众多领域发挥着至关重要的作用,从简单的网页爬取到复杂的自动化测试,再到智能代理与网页的交互等场景,都离不开高效、可靠的浏览器自动化工具。而微软推出的项目,正是在这一领域的一次创新性探索,它为开发者带来了全新的视角和强大的功能支持。本文将深入探讨的概念、架构、代码示例、应用场景、注意事项以及未来发展方向,帮助读者全面了解这一前沿技术。

加入“Super Entity”,与全能开发团队共探AI智能体与数字人项目,开启前沿技术之旅。 5271

用Playwright MCP让AI帮你完成所有浏览器自动化

Playwright MCP(Model Context Protocol)是微软基于 Playwright 框架推出的 AI 浏览器自动化新协议。它通过结构化快照数据和自然语言指令结合大型语言模型(如 GPT),实现无需编码的网页交互。无论你是要测试登录流程、抓取价格数据,还是用 AI 远程控制浏览器,Playwright MCP 都能大幅降低门槛,让“说人话”也能驱动自动化脚本。本篇将从功能介绍、技术架构、使用方法到实际场景,带你全面理解这一自动化革命。

todoitbo的博客 3万+

嵌入式统一消息机制:模块解耦与零拷贝通信设计

在嵌入式系统开发中,模块间通信(IMC)是影响可维护性与实时性的关键环节。传统IPC方式如全局变量、信号量或Socket易导致高耦合、调试困难及跨平台适配成本高。统一消息机制通过逻辑地址抽象、标签/实体分离、路由表驱动等原理,实现控制流与数据流解耦,在裸机、RTOS及Linux用户态保持一致接口。其技术价值在于降低模块依赖复杂度、支持动态增删与分布式迁移,并通过零拷贝优化显著减少CPU与内存开销。典型应用场景涵盖工业网关、城域交换机、多核ARM边缘设备等资源受限环境,尤其适用于需长期稳定运行、快速迭代与混合

weixin_35257663的博客 303

Ubuntu终端接入Codex:一行脚本搞定AI编程助手安装与配置

在开发者日常工作中,命令行终端是最高频的操作环境,而AI编程助手的出现正在改变传统的编码方式。通过将大模型能力与终端工具链结合,开发者无需切换窗口即可完成命令查询、代码生成、项目理解和自动执行等任务。Ubuntu作为服务器和开发机的主流系统,搭配Node.js生态和API Key认证,即可在本地闭环运行AI助手。本文从环境准备、密钥配置、权限管理到自动化脚本封装,系统拆解在终端中接入Codex的完整流程,并分享高频用法与实测排障经验,帮助开发者安全、高效地让AI融入命令行工作流。

weixin_29061041的博客 329

Sony SLVS-EC接口实战:如何用Xilinx K7 FPGA接收IMX421传感器数据(附电气特性匹配技巧)

本文详细介绍了在Xilinx Kintex-7 FPGA平台上实现Sony IMX421图像传感器SLVS-EC接口数据接收的完整实战方案。内容涵盖从硬件选型、PCB布局的电气特性匹配技巧,到FPGA内部GTX收发器配置、多通道绑定以及SLVS-EC协议数据解析与图像重组的关键步骤,为高速视觉系统开发提供了宝贵的调试经验和系统集成指导。

efc12345678的博客 268

从零开始学DAG:用dagitty软件快速构建因果图的5个步骤

本文为初学者提供了使用dagitty软件快速构建因果图的5个实用步骤。通过一个公共卫生研究实例,详细演示了如何从定义核心变量开始,逐步引入混杂、中介和碰撞变量,最终利用dagitty的自动分析功能识别最小充分调整集,从而科学指导研究设计与统计分析,有效提升因果推断的严谨性。

ii567的博客 803

深度学习中 Internal Covariate Shift 问题以及 Batch Normalization 的作用

深度学习中 Internal Covariate Shift 问题以及 Batch Normalization 的作用前言一、Batch Normalization是什么?1.1 Internal Covariate Shift1.2 Internal Covariate Shift 带来的影响1.3 如何减缓 Internal Covariate Shift 问题带来的影响白化(Whitening)白化存在的问题二、Batch Normalization2.1 传统 Normalization2.2 改进

一扣解千愁的博客 4297

使用freesurfer和3Dslicer进行脑区分割和电极定点(详细版)

1、安装好matlab和freesurfer2、在目标位置创建文件夹3、开放权限4、将需要计算的nii文件放入文件夹。

zQIANYUN的博客 5648

地平线J6的基础简介

地平线J6M芯片:面向中阶辅助驾驶市场的高性价比芯片

weixin_43084908的博客 4484

安川机器人外部轴添加

本文详细介绍了如何在安川机器人本体上添加第7轴以及如何设置动作,本文以添加点焊枪为例进行讲解。

haier123888的博客 7895

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: Chrome MCP Server 的安装与使用
下一篇: Cherry Studio配置使用mcp
时空旅行者666
博客等级 码龄16年 320粉丝 213原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

时空旅行者666

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值