@tontoko/fast-playwright-mcp 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +1047 -0
- package/cli.js +18 -0
- package/config.d.ts +124 -0
- package/index.d.ts +25 -0
- package/index.js +18 -0
- package/lib/actions.d.js +0 -0
- package/lib/batch/batch-executor.js +137 -0
- package/lib/browser-context-factory.js +252 -0
- package/lib/browser-server-backend.js +139 -0
- package/lib/config/constants.js +80 -0
- package/lib/config.js +405 -0
- package/lib/context.js +274 -0
- package/lib/diagnostics/common/diagnostic-base.js +63 -0
- package/lib/diagnostics/common/error-enrichment-utils.js +212 -0
- package/lib/diagnostics/common/index.js +56 -0
- package/lib/diagnostics/common/initialization-manager.js +210 -0
- package/lib/diagnostics/common/performance-tracker.js +132 -0
- package/lib/diagnostics/diagnostic-error.js +140 -0
- package/lib/diagnostics/diagnostic-level.js +123 -0
- package/lib/diagnostics/diagnostic-thresholds.js +347 -0
- package/lib/diagnostics/element-discovery.js +441 -0
- package/lib/diagnostics/enhanced-error-handler.js +376 -0
- package/lib/diagnostics/error-enrichment.js +157 -0
- package/lib/diagnostics/frame-reference-manager.js +179 -0
- package/lib/diagnostics/page-analyzer.js +639 -0
- package/lib/diagnostics/parallel-page-analyzer.js +129 -0
- package/lib/diagnostics/resource-manager.js +134 -0
- package/lib/diagnostics/smart-config.js +482 -0
- package/lib/diagnostics/smart-handle.js +118 -0
- package/lib/diagnostics/unified-system.js +717 -0
- package/lib/extension/cdp-relay.js +486 -0
- package/lib/extension/extension-context-factory.js +74 -0
- package/lib/extension/main.js +41 -0
- package/lib/file-utils.js +42 -0
- package/lib/generate-keys.js +75 -0
- package/lib/http-server.js +50 -0
- package/lib/in-process-client.js +64 -0
- package/lib/index.js +48 -0
- package/lib/javascript.js +90 -0
- package/lib/log.js +33 -0
- package/lib/loop/loop-claude.js +247 -0
- package/lib/loop/loop-open-ai.js +222 -0
- package/lib/loop/loop.js +174 -0
- package/lib/loop/main.js +46 -0
- package/lib/loopTools/context.js +76 -0
- package/lib/loopTools/main.js +65 -0
- package/lib/loopTools/perform.js +40 -0
- package/lib/loopTools/snapshot.js +37 -0
- package/lib/loopTools/tool.js +26 -0
- package/lib/manual-promise.js +125 -0
- package/lib/mcp/in-process-transport.js +91 -0
- package/lib/mcp/proxy-backend.js +127 -0
- package/lib/mcp/server.js +123 -0
- package/lib/mcp/transport.js +159 -0
- package/lib/package.js +28 -0
- package/lib/program.js +82 -0
- package/lib/response.js +493 -0
- package/lib/schemas/expectation.js +152 -0
- package/lib/session-log.js +210 -0
- package/lib/tab.js +417 -0
- package/lib/tools/base-tool-handler.js +141 -0
- package/lib/tools/batch-execute.js +150 -0
- package/lib/tools/common.js +65 -0
- package/lib/tools/console.js +60 -0
- package/lib/tools/diagnose/diagnose-analysis-runner.js +101 -0
- package/lib/tools/diagnose/diagnose-config-handler.js +130 -0
- package/lib/tools/diagnose/diagnose-report-builder.js +394 -0
- package/lib/tools/diagnose.js +147 -0
- package/lib/tools/dialogs.js +57 -0
- package/lib/tools/evaluate.js +67 -0
- package/lib/tools/files.js +53 -0
- package/lib/tools/find-elements.js +307 -0
- package/lib/tools/install.js +60 -0
- package/lib/tools/keyboard.js +93 -0
- package/lib/tools/mouse.js +110 -0
- package/lib/tools/navigate.js +82 -0
- package/lib/tools/network.js +50 -0
- package/lib/tools/pdf.js +46 -0
- package/lib/tools/screenshot.js +113 -0
- package/lib/tools/snapshot.js +158 -0
- package/lib/tools/tabs.js +97 -0
- package/lib/tools/tool.js +47 -0
- package/lib/tools/utils.js +131 -0
- package/lib/tools/wait.js +64 -0
- package/lib/tools.js +65 -0
- package/lib/types/batch.js +47 -0
- package/lib/types/diff.js +0 -0
- package/lib/types/performance.js +0 -0
- package/lib/types/threshold-base.js +0 -0
- package/lib/utils/array-utils.js +44 -0
- package/lib/utils/code-deduplication-utils.js +141 -0
- package/lib/utils/common-formatters.js +252 -0
- package/lib/utils/console-filter.js +64 -0
- package/lib/utils/diagnostic-report-utils.js +178 -0
- package/lib/utils/diff-formatter.js +126 -0
- package/lib/utils/disposable-manager.js +135 -0
- package/lib/utils/error-handler-middleware.js +77 -0
- package/lib/utils/image-processor.js +137 -0
- package/lib/utils/index.js +92 -0
- package/lib/utils/report-builder.js +189 -0
- package/lib/utils/request-logger.js +82 -0
- package/lib/utils/response-diff-detector.js +150 -0
- package/lib/utils/section-builder.js +62 -0
- package/lib/utils/tool-patterns.js +153 -0
- package/lib/utils.js +46 -0
- package/package.json +77 -0
package/README.md
ADDED
|
@@ -0,0 +1,1047 @@
|
|
|
1
|
+
## Playwright MCP
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol (MCP) server that provides browser automation capabilities using [Playwright](https://playwright.dev). This server enables LLMs to interact with web pages through structured accessibility snapshots, bypassing the need for screenshots or visually-tuned models.
|
|
4
|
+
|
|
5
|
+
### Key Features
|
|
6
|
+
|
|
7
|
+
- **Fast and lightweight**. Uses Playwright's accessibility tree, not pixel-based input.
|
|
8
|
+
- **LLM-friendly**. No vision models needed, operates purely on structured data.
|
|
9
|
+
- **Deterministic tool application**. Avoids ambiguity common with screenshot-based approaches.
|
|
10
|
+
|
|
11
|
+
### Fast Server Features (This Fork)
|
|
12
|
+
|
|
13
|
+
- **Token Optimization**. All tools support an `expectation` parameter to control response content:
|
|
14
|
+
- `includeCode: false` - Suppress Playwright code generation to reduce tokens
|
|
15
|
+
- `includeSnapshot: false` - Skip page snapshot for minimal responses (70-80% token reduction)
|
|
16
|
+
- `includeConsole: false` - Exclude console messages
|
|
17
|
+
- `includeTabs: false` - Hide tab information
|
|
18
|
+
- **Ultra-Compact Tool Descriptions**. One-line tool descriptions with full parameter details:
|
|
19
|
+
- 70-80% reduction in tool description tokens
|
|
20
|
+
- All expectation parameters inline without formatting overhead
|
|
21
|
+
- Smart tips for efficient usage (e.g., "Use selector to focus on specific area")
|
|
22
|
+
- **Image Compression**. Screenshot tool supports `imageOptions`:
|
|
23
|
+
- `format: 'jpeg'` - Use JPEG instead of PNG
|
|
24
|
+
- `quality: 1-100` - Compress images (e.g., 50 for 50% quality)
|
|
25
|
+
- `maxWidth: number` - Resize images to max width
|
|
26
|
+
- **Batch Execution**. Use `browser_batch_execute` for multiple operations:
|
|
27
|
+
- Significant token reduction by eliminating redundant responses
|
|
28
|
+
- Per-step and global expectation configuration
|
|
29
|
+
- Error handling with `continueOnError` and `stopOnFirstError` options
|
|
30
|
+
- **Snapshot Control**. Limit snapshot size with `snapshotOptions`:
|
|
31
|
+
- `selector: string` - Capture only specific page sections (recommended over maxLength)
|
|
32
|
+
- `format: "aria"` - Accessibility tree format for LLM processing
|
|
33
|
+
- **Diff Detection**. Track only changes with `diffOptions`:
|
|
34
|
+
- `enabled: true` - Show only what changed from previous state (massive token saver)
|
|
35
|
+
- `format: "minimal"` - Ultra-compact diff output
|
|
36
|
+
- Perfect for monitoring state changes during navigation or interactions
|
|
37
|
+
- **Diagnostic System**. Advanced debugging and element discovery tools:
|
|
38
|
+
- `browser_find_elements` - Find elements using multiple search criteria (text, role, attributes)
|
|
39
|
+
- `browser_diagnose` - Comprehensive page analysis with performance metrics and troubleshooting
|
|
40
|
+
- Enhanced error handling with alternative element suggestions
|
|
41
|
+
- Page structure analysis (iframes, modals, accessibility metrics)
|
|
42
|
+
- Performance monitoring with execution time under 300ms
|
|
43
|
+
|
|
44
|
+
### Requirements
|
|
45
|
+
- Node.js 18 or newer
|
|
46
|
+
- VS Code, Cursor, Windsurf, Claude Desktop, Goose or any other MCP client
|
|
47
|
+
|
|
48
|
+
<!--
|
|
49
|
+
// Generate using:
|
|
50
|
+
node utils/generate-links.js
|
|
51
|
+
-->
|
|
52
|
+
|
|
53
|
+
### Getting started
|
|
54
|
+
|
|
55
|
+
First, install the Playwright MCP server with your client.
|
|
56
|
+
|
|
57
|
+
**Standard config** works in most of the tools:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
{
|
|
61
|
+
"mcpServers": {
|
|
62
|
+
"playwright": {
|
|
63
|
+
"command": "npx",
|
|
64
|
+
"args": [
|
|
65
|
+
"@tontoko/fast-playwright-mcp@latest"
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
[<img src="https://img.shields.io/badge/VS_Code-VS_Code?style=flat-square&label=Install%20Server&color=0098FF" alt="Install in VS Code">](https://insiders.vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522playwright%2522%252C%2522command%2522%253A%2522npx%2522%252C%2522args%2522%253A%255B%2522%2540playwright%252Fmcp%2540latest%2522%255D%257D) [<img alt="Install in VS Code Insiders" src="https://img.shields.io/badge/VS_Code_Insiders-VS_Code_Insiders?style=flat-square&label=Install%20Server&color=24bfa5">](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522playwright%2522%252C%2522command%2522%253A%2522npx%2522%252C%2522args%2522%253A%255B%2522%2540playwright%252Fmcp%2540latest%2522%255D%257D)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
<details>
|
|
76
|
+
<summary>Claude Code</summary>
|
|
77
|
+
|
|
78
|
+
Use the Claude Code CLI to add the Playwright MCP server:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
claude mcp add fast-playwright npx @tontoko/fast-playwright-mcp@latest
|
|
82
|
+
```
|
|
83
|
+
</details>
|
|
84
|
+
|
|
85
|
+
<details>
|
|
86
|
+
<summary>Claude Desktop</summary>
|
|
87
|
+
|
|
88
|
+
Follow the MCP install [guide](https://modelcontextprotocol.io/quickstart/user), use the standard config above.
|
|
89
|
+
|
|
90
|
+
</details>
|
|
91
|
+
|
|
92
|
+
<details>
|
|
93
|
+
<summary>Cursor</summary>
|
|
94
|
+
|
|
95
|
+
#### Click the button to install:
|
|
96
|
+
|
|
97
|
+
[](cursor://anysphere.cursor-deeplink/mcp/install?name=Playwright&config=eyJjb21tYW5kIjoibnB4IEBwbGF5d3JpZ2h0L21jcEBsYXRlc3QifQ%3D%3D)
|
|
98
|
+
|
|
99
|
+
#### Or install manually:
|
|
100
|
+
|
|
101
|
+
Go to `Cursor Settings` -> `MCP` -> `Add new MCP Server`. Name to your liking, use `command` type with the command `npx @tontoko/fast-playwright-mcp`. You can also verify config or add command like arguments via clicking `Edit`.
|
|
102
|
+
|
|
103
|
+
</details>
|
|
104
|
+
|
|
105
|
+
<details>
|
|
106
|
+
<summary>Gemini CLI</summary>
|
|
107
|
+
|
|
108
|
+
Follow the MCP install [guide](https://github.com/google-gemini/gemini-cli/blob/main/docs/tools/mcp-server.md#configure-the-mcp-server-in-settingsjson), use the standard config above.
|
|
109
|
+
|
|
110
|
+
</details>
|
|
111
|
+
|
|
112
|
+
<details>
|
|
113
|
+
<summary>Goose</summary>
|
|
114
|
+
|
|
115
|
+
#### Click the button to install:
|
|
116
|
+
|
|
117
|
+
[](https://block.github.io/goose/extension?cmd=npx&arg=%40playwright%2Fmcp%40latest&id=playwright&name=Playwright&description=Interact%20with%20web%20pages%20through%20structured%20accessibility%20snapshots%20using%20Playwright)
|
|
118
|
+
|
|
119
|
+
#### Or install manually:
|
|
120
|
+
|
|
121
|
+
Go to `Advanced settings` -> `Extensions` -> `Add custom extension`. Name to your liking, use type `STDIO`, and set the `command` to `npx @tontoko/fast-playwright-mcp`. Click "Add Extension".
|
|
122
|
+
</details>
|
|
123
|
+
|
|
124
|
+
<details>
|
|
125
|
+
<summary>LM Studio</summary>
|
|
126
|
+
|
|
127
|
+
#### Click the button to install:
|
|
128
|
+
|
|
129
|
+
[](https://lmstudio.ai/install-mcp?name=playwright&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyJAcGxheXdyaWdodC9tY3BAbGF0ZXN0Il19)
|
|
130
|
+
|
|
131
|
+
#### Or install manually:
|
|
132
|
+
|
|
133
|
+
Go to `Program` in the right sidebar -> `Install` -> `Edit mcp.json`. Use the standard config above.
|
|
134
|
+
</details>
|
|
135
|
+
|
|
136
|
+
<details>
|
|
137
|
+
<summary>Qodo Gen</summary>
|
|
138
|
+
|
|
139
|
+
Open [Qodo Gen](https://docs.qodo.ai/qodo-documentation/qodo-gen) chat panel in VSCode or IntelliJ → Connect more tools → + Add new MCP → Paste the standard config above.
|
|
140
|
+
|
|
141
|
+
Click <code>Save</code>.
|
|
142
|
+
</details>
|
|
143
|
+
|
|
144
|
+
<details>
|
|
145
|
+
<summary>VS Code</summary>
|
|
146
|
+
|
|
147
|
+
#### Click the button to install:
|
|
148
|
+
|
|
149
|
+
[<img src="https://img.shields.io/badge/VS_Code-VS_Code?style=flat-square&label=Install%20Server&color=0098FF" alt="Install in VS Code">](https://insiders.vscode.dev/redirect?url=vscode%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522playwright%2522%252C%2522command%2522%253A%2522npx%2522%252C%2522args%2522%253A%255B%2522%2540playwright%252Fmcp%2540latest%2522%255D%257D) [<img alt="Install in VS Code Insiders" src="https://img.shields.io/badge/VS_Code_Insiders-VS_Code_Insiders?style=flat-square&label=Install%20Server&color=24bfa5">](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522playwright%2522%252C%2522command%2522%253A%2522npx%2522%252C%2522args%2522%253A%255B%2522%2540playwright%252Fmcp%2540latest%2522%255D%257D)
|
|
150
|
+
|
|
151
|
+
#### Or install manually:
|
|
152
|
+
|
|
153
|
+
Follow the MCP install [guide](https://code.visualstudio.com/docs/copilot/chat/mcp-servers#_add-an-mcp-server), use the standard config above. You can also install the Playwright MCP server using the VS Code CLI:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# For VS Code
|
|
157
|
+
code --add-mcp '{"name":"fast-playwright","command":"npx","args":["@tontoko/fast-playwright-mcp@latest"]}'
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
After installation, the Playwright MCP server will be available for use with your GitHub Copilot agent in VS Code.
|
|
161
|
+
</details>
|
|
162
|
+
|
|
163
|
+
<details>
|
|
164
|
+
<summary>Windsurf</summary>
|
|
165
|
+
|
|
166
|
+
Follow Windsurf MCP [documentation](https://docs.windsurf.com/windsurf/cascade/mcp). Use the standard config above.
|
|
167
|
+
|
|
168
|
+
</details>
|
|
169
|
+
|
|
170
|
+
### Configuration
|
|
171
|
+
|
|
172
|
+
Playwright MCP server supports following arguments. They can be provided in the JSON configuration above, as a part of the `"args"` list:
|
|
173
|
+
|
|
174
|
+
<!--- Options generated by update-readme.js -->
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
> npx @tontoko/fast-playwright-mcp@latest --help
|
|
178
|
+
--allowed-origins <origins> semicolon-separated list of origins to allow the
|
|
179
|
+
browser to request. Default is to allow all.
|
|
180
|
+
--blocked-origins <origins> semicolon-separated list of origins to block the
|
|
181
|
+
browser from requesting. Blocklist is evaluated
|
|
182
|
+
before allowlist. If used without the allowlist,
|
|
183
|
+
requests not matching the blocklist are still
|
|
184
|
+
allowed.
|
|
185
|
+
--block-service-workers block service workers
|
|
186
|
+
--browser <browser> browser or chrome channel to use, possible
|
|
187
|
+
values: chrome, firefox, webkit, msedge.
|
|
188
|
+
--caps <caps> comma-separated list of additional capabilities
|
|
189
|
+
to enable, possible values: vision, pdf.
|
|
190
|
+
--cdp-endpoint <endpoint> CDP endpoint to connect to.
|
|
191
|
+
--config <path> path to the configuration file.
|
|
192
|
+
--device <device> device to emulate, for example: "iPhone 15"
|
|
193
|
+
--executable-path <path> path to the browser executable.
|
|
194
|
+
--headless run browser in headless mode, headed by default
|
|
195
|
+
--host <host> host to bind server to. Default is localhost. Use
|
|
196
|
+
0.0.0.0 to bind to all interfaces.
|
|
197
|
+
--ignore-https-errors ignore https errors
|
|
198
|
+
--isolated keep the browser profile in memory, do not save
|
|
199
|
+
it to disk.
|
|
200
|
+
--image-responses <mode> whether to send image responses to the client.
|
|
201
|
+
Can be "allow" or "omit", Defaults to "allow".
|
|
202
|
+
--no-sandbox disable the sandbox for all process types that
|
|
203
|
+
are normally sandboxed.
|
|
204
|
+
--output-dir <path> path to the directory for output files.
|
|
205
|
+
--port <port> port to listen on for SSE transport.
|
|
206
|
+
--proxy-bypass <bypass> comma-separated domains to bypass proxy, for
|
|
207
|
+
example ".com,chromium.org,.domain.com"
|
|
208
|
+
--proxy-server <proxy> specify proxy server, for example
|
|
209
|
+
"http://myproxy:3128" or "socks5://myproxy:8080"
|
|
210
|
+
--save-session Whether to save the Playwright MCP session into
|
|
211
|
+
the output directory.
|
|
212
|
+
--save-trace Whether to save the Playwright Trace of the
|
|
213
|
+
session into the output directory.
|
|
214
|
+
--storage-state <path> path to the storage state file for isolated
|
|
215
|
+
sessions.
|
|
216
|
+
--user-agent <ua string> specify user agent string
|
|
217
|
+
--user-data-dir <path> path to the user data directory. If not
|
|
218
|
+
specified, a temporary directory will be created.
|
|
219
|
+
--viewport-size <size> specify browser viewport size in pixels, for
|
|
220
|
+
example "1280, 720"
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
<!--- End of options generated section -->
|
|
224
|
+
|
|
225
|
+
### User profile
|
|
226
|
+
|
|
227
|
+
You can run Playwright MCP with persistent profile like a regular browser (default), or in the isolated contexts for the testing sessions.
|
|
228
|
+
|
|
229
|
+
**Persistent profile**
|
|
230
|
+
|
|
231
|
+
All the logged in information will be stored in the persistent profile, you can delete it between sessions if you'd like to clear the offline state.
|
|
232
|
+
Persistent profile is located at the following locations and you can override it with the `--user-data-dir` argument.
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
# Windows
|
|
236
|
+
%USERPROFILE%\AppData\Local\ms-playwright\mcp-{channel}-profile
|
|
237
|
+
|
|
238
|
+
# macOS
|
|
239
|
+
- ~/Library/Caches/ms-playwright/mcp-{channel}-profile
|
|
240
|
+
|
|
241
|
+
# Linux
|
|
242
|
+
- ~/.cache/ms-playwright/mcp-{channel}-profile
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
**Isolated**
|
|
246
|
+
|
|
247
|
+
In the isolated mode, each session is started in the isolated profile. Every time you ask MCP to close the browser,
|
|
248
|
+
the session is closed and all the storage state for this session is lost. You can provide initial storage state
|
|
249
|
+
to the browser via the config's `contextOptions` or via the `--storage-state` argument. Learn more about the storage
|
|
250
|
+
state [here](https://playwright.dev/docs/auth).
|
|
251
|
+
|
|
252
|
+
```js
|
|
253
|
+
{
|
|
254
|
+
"mcpServers": {
|
|
255
|
+
"playwright": {
|
|
256
|
+
"command": "npx",
|
|
257
|
+
"args": [
|
|
258
|
+
"@tontoko/fast-playwright-mcp@latest",
|
|
259
|
+
"--isolated",
|
|
260
|
+
"--storage-state={path/to/storage.json}"
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Configuration file
|
|
268
|
+
|
|
269
|
+
The Playwright MCP server can be configured using a JSON configuration file. You can specify the configuration file
|
|
270
|
+
using the `--config` command line option:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
npx @tontoko/fast-playwright-mcp@latest --config path/to/config.json
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
<details>
|
|
277
|
+
<summary>Configuration file schema</summary>
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
{
|
|
281
|
+
// Browser configuration
|
|
282
|
+
browser?: {
|
|
283
|
+
// Browser type to use (chromium, firefox, or webkit)
|
|
284
|
+
browserName?: 'chromium' | 'firefox' | 'webkit';
|
|
285
|
+
|
|
286
|
+
// Keep the browser profile in memory, do not save it to disk.
|
|
287
|
+
isolated?: boolean;
|
|
288
|
+
|
|
289
|
+
// Path to user data directory for browser profile persistence
|
|
290
|
+
userDataDir?: string;
|
|
291
|
+
|
|
292
|
+
// Browser launch options (see Playwright docs)
|
|
293
|
+
// @see https://playwright.dev/docs/api/class-browsertype#browser-type-launch
|
|
294
|
+
launchOptions?: {
|
|
295
|
+
channel?: string; // Browser channel (e.g. 'chrome')
|
|
296
|
+
headless?: boolean; // Run in headless mode
|
|
297
|
+
executablePath?: string; // Path to browser executable
|
|
298
|
+
// ... other Playwright launch options
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
// Browser context options
|
|
302
|
+
// @see https://playwright.dev/docs/api/class-browser#browser-new-context
|
|
303
|
+
contextOptions?: {
|
|
304
|
+
viewport?: { width: number, height: number };
|
|
305
|
+
// ... other Playwright context options
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
// CDP endpoint for connecting to existing browser
|
|
309
|
+
cdpEndpoint?: string;
|
|
310
|
+
|
|
311
|
+
// Remote Playwright server endpoint
|
|
312
|
+
remoteEndpoint?: string;
|
|
313
|
+
},
|
|
314
|
+
|
|
315
|
+
// Server configuration
|
|
316
|
+
server?: {
|
|
317
|
+
port?: number; // Port to listen on
|
|
318
|
+
host?: string; // Host to bind to (default: localhost)
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
// List of additional capabilities
|
|
322
|
+
capabilities?: Array<
|
|
323
|
+
'tabs' | // Tab management
|
|
324
|
+
'install' | // Browser installation
|
|
325
|
+
'pdf' | // PDF generation
|
|
326
|
+
'vision' | // Coordinate-based interactions
|
|
327
|
+
>;
|
|
328
|
+
|
|
329
|
+
// Directory for output files
|
|
330
|
+
outputDir?: string;
|
|
331
|
+
|
|
332
|
+
// Network configuration
|
|
333
|
+
network?: {
|
|
334
|
+
// List of origins to allow the browser to request. Default is to allow all. Origins matching both `allowedOrigins` and `blockedOrigins` will be blocked.
|
|
335
|
+
allowedOrigins?: string[];
|
|
336
|
+
|
|
337
|
+
// List of origins to block the browser to request. Origins matching both `allowedOrigins` and `blockedOrigins` will be blocked.
|
|
338
|
+
blockedOrigins?: string[];
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Whether to send image responses to the client. Can be "allow" or "omit".
|
|
343
|
+
* Defaults to "allow".
|
|
344
|
+
*/
|
|
345
|
+
imageResponses?: 'allow' | 'omit';
|
|
346
|
+
}
|
|
347
|
+
```
|
|
348
|
+
</details>
|
|
349
|
+
|
|
350
|
+
### Standalone MCP server
|
|
351
|
+
|
|
352
|
+
When running headed browser on system w/o display or from worker processes of the IDEs,
|
|
353
|
+
run the MCP server from environment with the DISPLAY and pass the `--port` flag to enable HTTP transport.
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
npx @tontoko/fast-playwright-mcp@latest --port 8931
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
And then in MCP client config, set the `url` to the HTTP endpoint:
|
|
360
|
+
|
|
361
|
+
```js
|
|
362
|
+
{
|
|
363
|
+
"mcpServers": {
|
|
364
|
+
"playwright": {
|
|
365
|
+
"url": "http://localhost:8931/mcp"
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
<details>
|
|
372
|
+
<summary><b>Docker</b></summary>
|
|
373
|
+
|
|
374
|
+
**NOTE:** The Docker implementation only supports headless chromium at the moment.
|
|
375
|
+
|
|
376
|
+
```js
|
|
377
|
+
{
|
|
378
|
+
"mcpServers": {
|
|
379
|
+
"playwright": {
|
|
380
|
+
"command": "docker",
|
|
381
|
+
"args": ["run", "-i", "--rm", "--init", "--pull=always", "mcr.microsoft.com/playwright/mcp"]
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
You can build the Docker image yourself.
|
|
388
|
+
|
|
389
|
+
```
|
|
390
|
+
docker build -t mcr.microsoft.com/playwright/mcp .
|
|
391
|
+
```
|
|
392
|
+
</details>
|
|
393
|
+
|
|
394
|
+
<details>
|
|
395
|
+
<summary><b>Programmatic usage</b></summary>
|
|
396
|
+
|
|
397
|
+
```js
|
|
398
|
+
import http from 'http';
|
|
399
|
+
|
|
400
|
+
import { createConnection } from '@tontoko/fast-playwright-mcp';
|
|
401
|
+
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
402
|
+
|
|
403
|
+
http.createServer(async (req, res) => {
|
|
404
|
+
// ...
|
|
405
|
+
|
|
406
|
+
// Creates a headless Playwright MCP server with SSE transport
|
|
407
|
+
const connection = await createConnection({ browser: { launchOptions: { headless: true } } });
|
|
408
|
+
const transport = new SSEServerTransport('/messages', res);
|
|
409
|
+
await connection.sever.connect(transport);
|
|
410
|
+
|
|
411
|
+
// ...
|
|
412
|
+
});
|
|
413
|
+
```
|
|
414
|
+
</details>
|
|
415
|
+
|
|
416
|
+
### Tools
|
|
417
|
+
|
|
418
|
+
<!--- Tools generated by update-readme.js -->
|
|
419
|
+
|
|
420
|
+
<details><summary><b>Core automation</b></summary>
|
|
421
|
+
|
|
422
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
423
|
+
|
|
424
|
+
- **browser_batch_execute**
|
|
425
|
+
- Title: Batch Execute Browser Actions
|
|
426
|
+
- Description: Execute multiple browser actions in sequence with optimized response handling.RECOMMENDED:Use this tool instead of individual actions when performing multiple operations to significantly reduce token usage and improve performance.BY DEFAULT use for:form filling(multiple type→click),multi-step navigation,any workflow with 2+ known steps.Saves 90% tokens vs individual calls.globalExpectation:{includeSnapshot:false,snapshotOptions:{selector:"#app"},diffOptions:{enabled:true}}.Per-step override:steps[].expectation.Example:[{tool:"browser_navigate",arguments:{url:"https://example.com"}},{tool:"browser_type",arguments:{element:"username",ref:"#user",text:"john"}},{tool:"browser_click",arguments:{element:"submit",ref:"#btn"}}].
|
|
427
|
+
- Parameters:
|
|
428
|
+
- `steps` (array): Array of steps to execute in sequence
|
|
429
|
+
- `stopOnFirstError` (boolean, optional): Stop entire batch on first error
|
|
430
|
+
- `globalExpectation` (optional): Default expectation for all steps
|
|
431
|
+
- Read-only: **false**
|
|
432
|
+
|
|
433
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
434
|
+
|
|
435
|
+
- **browser_click**
|
|
436
|
+
- Title: Click
|
|
437
|
+
- Description: Perform click on web page.USE batch_execute for multi-click workflows.expectation:{includeSnapshot:false} when next action follows immediately,true to verify result.diffOptions:{enabled:true,format:"minimal"} shows only changes(saves 80% tokens).snapshotOptions:{selector:".result"} to focus on result area.doubleClick:true for double-click,button:"right" for context menu.
|
|
438
|
+
- Parameters:
|
|
439
|
+
- `element` (string): Human-readable element description used to obtain permission to interact with the element
|
|
440
|
+
- `ref` (string): Exact target element reference from the page snapshot
|
|
441
|
+
- `doubleClick` (boolean, optional): Whether to perform a double click instead of a single click
|
|
442
|
+
- `button` (string, optional): Button to click, defaults to left
|
|
443
|
+
- `expectation` (object, optional): undefined
|
|
444
|
+
- Read-only: **false**
|
|
445
|
+
|
|
446
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
447
|
+
|
|
448
|
+
- **browser_close**
|
|
449
|
+
- Title: Close browser
|
|
450
|
+
- Description: Close the page
|
|
451
|
+
- Parameters: None
|
|
452
|
+
- Read-only: **true**
|
|
453
|
+
|
|
454
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
455
|
+
|
|
456
|
+
- **browser_console_messages**
|
|
457
|
+
- Title: Get console messages
|
|
458
|
+
- Description: Returns all console messages
|
|
459
|
+
- Parameters: None
|
|
460
|
+
- Read-only: **true**
|
|
461
|
+
|
|
462
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
463
|
+
|
|
464
|
+
- **browser_diagnose**
|
|
465
|
+
- Title: Diagnose page
|
|
466
|
+
- Description: Analyze page complexity and performance characteristics. Reports on: iframe count, DOM size, modal states, element statistics. Use for: debugging slow pages, understanding page structure, or monitoring page complexity.
|
|
467
|
+
- Parameters:
|
|
468
|
+
- `searchForElements` (object, optional): Search for specific elements and include them in the report
|
|
469
|
+
- `includePerformanceMetrics` (boolean, optional): Include performance metrics in the report
|
|
470
|
+
- `includeAccessibilityInfo` (boolean, optional): Include accessibility information
|
|
471
|
+
- `includeTroubleshootingSuggestions` (boolean, optional): Include troubleshooting suggestions
|
|
472
|
+
- `diagnosticLevel` (string, optional): Level of diagnostic detail: none (no diagnostics), basic (critical only), standard (default), detailed (with metrics), full (all info)
|
|
473
|
+
- `useParallelAnalysis` (boolean, optional): Use Phase 2 parallel analysis for improved performance and resource monitoring
|
|
474
|
+
- `useUnifiedSystem` (boolean, optional): Use Phase 3 unified diagnostic system with enhanced error handling and monitoring
|
|
475
|
+
- `configOverrides` (object, optional): Runtime configuration overrides for diagnostic system
|
|
476
|
+
- `includeSystemStats` (boolean, optional): Include unified system statistics and health information
|
|
477
|
+
- `expectation` (object, optional): undefined
|
|
478
|
+
- Read-only: **true**
|
|
479
|
+
|
|
480
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
481
|
+
|
|
482
|
+
- **browser_drag**
|
|
483
|
+
- Title: Drag mouse
|
|
484
|
+
- Description: Perform drag and drop between two elements.expectation:{includeSnapshot:true,snapshotOptions:{selector:".drop-zone"}} to verify drop result.diffOptions:{enabled:true} shows only what moved.CONSIDER batch_execute if part of larger workflow.
|
|
485
|
+
- Parameters:
|
|
486
|
+
- `startElement` (string): Human-readable source element description used to obtain the permission to interact with the element
|
|
487
|
+
- `startRef` (string): Exact source element reference from the page snapshot
|
|
488
|
+
- `endElement` (string): Human-readable target element description used to obtain the permission to interact with the element
|
|
489
|
+
- `endRef` (string): Exact target element reference from the page snapshot
|
|
490
|
+
- `expectation` (object, optional): undefined
|
|
491
|
+
- Read-only: **false**
|
|
492
|
+
|
|
493
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
494
|
+
|
|
495
|
+
- **browser_evaluate**
|
|
496
|
+
- Title: Evaluate JavaScript
|
|
497
|
+
- Description: Evaluate JavaScript expression on page or element.Returns evaluation result.USE CASES:extract data,modify DOM,trigger events.expectation:{includeSnapshot:false} for data extraction,true if modifying page.element+ref to run on specific element.CONSIDER batch_execute for multiple evaluations.
|
|
498
|
+
- Parameters:
|
|
499
|
+
- `function` (string): () => { /* code */ } or (element) => { /* code */ } when element is provided
|
|
500
|
+
- `element` (string, optional): Human-readable element description used to obtain permission to interact with the element
|
|
501
|
+
- `ref` (string, optional): Exact target element reference from the page snapshot
|
|
502
|
+
- `expectation` (object, optional): undefined
|
|
503
|
+
- Read-only: **false**
|
|
504
|
+
|
|
505
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
506
|
+
|
|
507
|
+
- **browser_file_upload**
|
|
508
|
+
- Title: Upload files
|
|
509
|
+
- Description: Upload one or multiple files to file input.paths:["/path/file1.jpg","/path/file2.pdf"] for multiple files.expectation:{includeSnapshot:true,snapshotOptions:{selector:"form"}} to verify upload.Must be triggered after file input interaction.USE batch_execute for click→upload workflows.
|
|
510
|
+
- Parameters:
|
|
511
|
+
- `paths` (array): The absolute paths to the files to upload. Can be a single file or multiple files.
|
|
512
|
+
- `expectation` (object, optional): undefined
|
|
513
|
+
- Read-only: **false**
|
|
514
|
+
|
|
515
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
516
|
+
|
|
517
|
+
- **browser_find_elements**
|
|
518
|
+
- Title: Find elements
|
|
519
|
+
- Description: Find elements on the page using multiple search criteria such as text, role, tag name, or attributes. Returns matching elements sorted by confidence.
|
|
520
|
+
- Parameters:
|
|
521
|
+
- `searchCriteria` (object): Search criteria for finding elements
|
|
522
|
+
- `maxResults` (number, optional): Maximum number of results to return
|
|
523
|
+
- `includeDiagnosticInfo` (boolean, optional): Include diagnostic information about the page
|
|
524
|
+
- `useUnifiedSystem` (boolean, optional): Use unified diagnostic system for enhanced error handling
|
|
525
|
+
- `enableEnhancedDiscovery` (boolean, optional): Enable enhanced element discovery with contextual suggestions
|
|
526
|
+
- `performanceThreshold` (number, optional): Performance threshold in milliseconds for element discovery
|
|
527
|
+
- `expectation` (object, optional): undefined
|
|
528
|
+
- Read-only: **true**
|
|
529
|
+
|
|
530
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
531
|
+
|
|
532
|
+
- **browser_handle_dialog**
|
|
533
|
+
- Title: Handle a dialog
|
|
534
|
+
- Description: Handle a dialog(alert,confirm,prompt).accept:true to accept,false to dismiss.promptText:"answer" for prompt dialogs.expectation:{includeSnapshot:true} to see page after dialog handling.USE batch_execute if dialog appears during workflow.
|
|
535
|
+
- Parameters:
|
|
536
|
+
- `accept` (boolean): Whether to accept the dialog.
|
|
537
|
+
- `promptText` (string, optional): The text of the prompt in case of a prompt dialog.
|
|
538
|
+
- `expectation` (object, optional): undefined
|
|
539
|
+
- Read-only: **false**
|
|
540
|
+
|
|
541
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
542
|
+
|
|
543
|
+
- **browser_hover**
|
|
544
|
+
- Title: Hover mouse
|
|
545
|
+
- Description: Hover over element on page.expectation:{includeSnapshot:true} to capture tooltips/dropdown menus,false for simple hover.snapshotOptions:{selector:".tooltip"} to focus on tooltip area.Often followed by click - use batch_execute for hover→click sequences.
|
|
546
|
+
- Parameters:
|
|
547
|
+
- `element` (string): Human-readable element description used to obtain permission to interact with the element
|
|
548
|
+
- `ref` (string): Exact target element reference from the page snapshot
|
|
549
|
+
- `expectation` (object, optional): undefined
|
|
550
|
+
- Read-only: **true**
|
|
551
|
+
|
|
552
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
553
|
+
|
|
554
|
+
- **browser_navigate**
|
|
555
|
+
- Title: Navigate to a URL
|
|
556
|
+
- Description: Navigate to a URL.expectation:{includeSnapshot:true} to see what loaded,false if you know what to do next.snapshotOptions:{selector:"#content"} to focus on main content(saves 50% tokens).diffOptions:{enabled:true} when revisiting pages to see only changes.CONSIDER batch_execute for navigate→interact workflows.
|
|
557
|
+
- Parameters:
|
|
558
|
+
- `url` (string): The URL to navigate to
|
|
559
|
+
- `expectation` (object, optional): undefined
|
|
560
|
+
- Read-only: **false**
|
|
561
|
+
|
|
562
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
563
|
+
|
|
564
|
+
- **browser_navigate_back**
|
|
565
|
+
- Title: Go back
|
|
566
|
+
- Description: Go back to previous page.expectation:{includeSnapshot:true} to see previous page,false if continuing workflow.diffOptions:{enabled:true} shows only what changed from forward page.USE batch_execute for back→interact sequences.
|
|
567
|
+
- Parameters:
|
|
568
|
+
- `expectation` (object, optional): undefined
|
|
569
|
+
- Read-only: **true**
|
|
570
|
+
|
|
571
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
572
|
+
|
|
573
|
+
- **browser_navigate_forward**
|
|
574
|
+
- Title: Go forward
|
|
575
|
+
- Description: Go forward to next page.expectation:{includeSnapshot:true} to see next page,false if continuing workflow.diffOptions:{enabled:true} shows only what changed from previous page.USE batch_execute for forward→interact sequences.
|
|
576
|
+
- Parameters:
|
|
577
|
+
- `expectation` (object, optional): undefined
|
|
578
|
+
- Read-only: **true**
|
|
579
|
+
|
|
580
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
581
|
+
|
|
582
|
+
- **browser_network_requests**
|
|
583
|
+
- Title: List network requests
|
|
584
|
+
- Description: Returns all network requests since loading the page
|
|
585
|
+
- Parameters: None
|
|
586
|
+
- Read-only: **true**
|
|
587
|
+
|
|
588
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
589
|
+
|
|
590
|
+
- **browser_press_key**
|
|
591
|
+
- Title: Press a key
|
|
592
|
+
- Description: Press a key on the keyboard.Common keys:Enter,Escape,ArrowUp/Down/Left/Right,Tab,Backspace.expectation:{includeSnapshot:false} for navigation keys,true for content changes.CONSIDER batch_execute for multiple key presses.
|
|
593
|
+
- Parameters:
|
|
594
|
+
- `key` (string): Name of the key to press or a character to generate, such as `ArrowLeft` or `a`
|
|
595
|
+
- `expectation` (object, optional): undefined
|
|
596
|
+
- Read-only: **false**
|
|
597
|
+
|
|
598
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
599
|
+
|
|
600
|
+
- **browser_resize**
|
|
601
|
+
- Title: Resize browser window
|
|
602
|
+
- Description: Resize the browser window
|
|
603
|
+
- Parameters:
|
|
604
|
+
- `width` (number): Width of the browser window
|
|
605
|
+
- `height` (number): Height of the browser window
|
|
606
|
+
- `expectation` (object, optional): undefined
|
|
607
|
+
- Read-only: **true**
|
|
608
|
+
|
|
609
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
610
|
+
|
|
611
|
+
- **browser_select_option**
|
|
612
|
+
- Title: Select option
|
|
613
|
+
- Description: Select option in dropdown.values:["option1","option2"] for multi-select.expectation:{includeSnapshot:false} when part of form filling(use batch),true to verify selection.snapshotOptions:{selector:"form"} for form context.USE batch_execute for form workflows with multiple selects.
|
|
614
|
+
- Parameters:
|
|
615
|
+
- `element` (string): Human-readable element description used to obtain permission to interact with the element
|
|
616
|
+
- `ref` (string): Exact target element reference from the page snapshot
|
|
617
|
+
- `values` (array): Array of values to select in the dropdown. This can be a single value or multiple values.
|
|
618
|
+
- `expectation` (object, optional): undefined
|
|
619
|
+
- Read-only: **false**
|
|
620
|
+
|
|
621
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
622
|
+
|
|
623
|
+
- **browser_snapshot**
|
|
624
|
+
- Title: Page snapshot
|
|
625
|
+
- Description: Capture accessibility snapshot of current page.AVOID calling directly - use expectation:{includeSnapshot:true} on other tools instead.USE CASES:Initial page inspection,debugging when other tools didn't capture needed info.snapshotOptions:{selector:"#content"} to focus on specific area.
|
|
626
|
+
- Parameters:
|
|
627
|
+
- `expectation` (object, optional): undefined
|
|
628
|
+
- Read-only: **true**
|
|
629
|
+
|
|
630
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
631
|
+
|
|
632
|
+
- **browser_take_screenshot**
|
|
633
|
+
- Title: Take a screenshot
|
|
634
|
+
- Description: Take a screenshot of current page.Returns image data.expectation:{includeSnapshot:false} to avoid redundant accessibility tree(screenshot≠snapshot).imageOptions:{quality:50,format:"jpeg"} for 70% size reduction.fullPage:true for entire page,element+ref for specific element.USE CASES:visual verification,documentation,error capture.
|
|
635
|
+
- Parameters:
|
|
636
|
+
- `type` (string, optional): Image format for the screenshot. Default is png.
|
|
637
|
+
- `filename` (string, optional): File name to save the screenshot to. Defaults to `page-{timestamp}.{png|jpeg}` if not specified.
|
|
638
|
+
- `element` (string, optional): Human-readable element description used to obtain permission to screenshot the element. If not provided, the screenshot will be taken of viewport. If element is provided, ref must be provided too.
|
|
639
|
+
- `ref` (string, optional): Exact target element reference from the page snapshot. If not provided, the screenshot will be taken of viewport. If ref is provided, element must be provided too.
|
|
640
|
+
- `fullPage` (boolean, optional): When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Cannot be used with element screenshots.
|
|
641
|
+
- `expectation` (object, optional): undefined
|
|
642
|
+
- Read-only: **true**
|
|
643
|
+
|
|
644
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
645
|
+
|
|
646
|
+
- **browser_type**
|
|
647
|
+
- Title: Type text
|
|
648
|
+
- Description: Type text into editable element.FOR FORMS:Use batch_execute to fill multiple fields efficiently.slowly:true for auto-complete fields,submit:true to press Enter after.expectation:{includeSnapshot:false} when filling multiple fields(use batch),true for final verification.snapshotOptions:{selector:"form"} to focus on form only.diffOptions:{enabled:true} shows only what changed in form.
|
|
649
|
+
- Parameters:
|
|
650
|
+
- `element` (string): Human-readable element description used to obtain permission to interact with the element
|
|
651
|
+
- `ref` (string): Exact target element reference from the page snapshot
|
|
652
|
+
- `text` (string): Text to type into the element
|
|
653
|
+
- `submit` (boolean, optional): Whether to submit entered text (press Enter after)
|
|
654
|
+
- `slowly` (boolean, optional): Whether type one character at a time. Useful for triggering key handlers in the page. By default entire text is filled in at once.
|
|
655
|
+
- `expectation` (object, optional): undefined
|
|
656
|
+
- Read-only: **false**
|
|
657
|
+
|
|
658
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
659
|
+
|
|
660
|
+
- **browser_wait_for**
|
|
661
|
+
- Title: Wait for
|
|
662
|
+
- Description: Wait for text to appear/disappear or time to pass.PREFER text-based wait over time for reliability.For loading states:wait for text:"Loading..." textGone:true.For dynamic content:wait for specific text to appear.expectation:{includeSnapshot:true,snapshotOptions:{selector:"#status"},diffOptions:{enabled:true}} shows only what changed.AVOID:fixed time waits unless necessary.
|
|
663
|
+
- Parameters:
|
|
664
|
+
- `time` (number, optional): The time to wait in seconds
|
|
665
|
+
- `text` (string, optional): The text to wait for
|
|
666
|
+
- `textGone` (string, optional): The text to wait for to disappear
|
|
667
|
+
- `expectation` (object, optional): undefined
|
|
668
|
+
- Read-only: **true**
|
|
669
|
+
|
|
670
|
+
</details>
|
|
671
|
+
|
|
672
|
+
<details><summary><b>Tab management</b></summary>
|
|
673
|
+
|
|
674
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
675
|
+
|
|
676
|
+
- **browser_tab_close**
|
|
677
|
+
- Title: Close a tab
|
|
678
|
+
- Description: Close a tab.index:N to close specific tab,omit to close current.expectation:{includeSnapshot:false} usually sufficient,true to verify remaining tabs.USE batch_execute for multi-tab cleanup.
|
|
679
|
+
- Parameters:
|
|
680
|
+
- `index` (number, optional): The index of the tab to close. Closes current tab if not provided.
|
|
681
|
+
- `expectation` (object, optional): undefined
|
|
682
|
+
- Read-only: **false**
|
|
683
|
+
|
|
684
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
685
|
+
|
|
686
|
+
- **browser_tab_list**
|
|
687
|
+
- Title: List tabs
|
|
688
|
+
- Description: List browser tabs.Always returns tab list with titles and URLs.expectation:{includeSnapshot:false} for just tab info,true to also see current tab content.USE before tab_select to find right tab.
|
|
689
|
+
- Parameters:
|
|
690
|
+
- `expectation` (object, optional): undefined
|
|
691
|
+
- Read-only: **true**
|
|
692
|
+
|
|
693
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
694
|
+
|
|
695
|
+
- **browser_tab_new**
|
|
696
|
+
- Title: Open a new tab
|
|
697
|
+
- Description: Open a new tab.url:"https://example.com" to navigate immediately,omit for blank tab.expectation:{includeSnapshot:true} to see new tab,false if opening for later use.CONSIDER batch_execute for new_tab→navigate→interact.
|
|
698
|
+
- Parameters:
|
|
699
|
+
- `url` (string, optional): The URL to navigate to in the new tab. If not provided, the new tab will be blank.
|
|
700
|
+
- `expectation` (object, optional): undefined
|
|
701
|
+
- Read-only: **true**
|
|
702
|
+
|
|
703
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
704
|
+
|
|
705
|
+
- **browser_tab_select**
|
|
706
|
+
- Title: Select a tab
|
|
707
|
+
- Description: Select a tab by index.expectation:{includeSnapshot:true} to see selected tab content,false if you know what's there.USE batch_execute for tab_select→interact workflows.
|
|
708
|
+
- Parameters:
|
|
709
|
+
- `index` (number): The index of the tab to select
|
|
710
|
+
- `expectation` (object, optional): undefined
|
|
711
|
+
- Read-only: **true**
|
|
712
|
+
|
|
713
|
+
</details>
|
|
714
|
+
|
|
715
|
+
<details><summary><b>Browser installation</b></summary>
|
|
716
|
+
|
|
717
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
718
|
+
|
|
719
|
+
- **browser_install**
|
|
720
|
+
- Title: Install the browser specified in the config
|
|
721
|
+
- Description: Install the browser specified in the config. Call this if you get an error about the browser not being installed.
|
|
722
|
+
- Parameters: None
|
|
723
|
+
- Read-only: **false**
|
|
724
|
+
|
|
725
|
+
</details>
|
|
726
|
+
|
|
727
|
+
<details><summary><b>Coordinate-based (opt-in via --caps=vision)</b></summary>
|
|
728
|
+
|
|
729
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
730
|
+
|
|
731
|
+
- **browser_mouse_click_xy**
|
|
732
|
+
- Title: Click
|
|
733
|
+
- Description: Click at specific coordinates.Requires --caps=vision.x,y:click position.expectation:{includeSnapshot:true} to verify result.PREFER browser_click with element ref over coordinates.USE batch_execute for coordinate-based workflows.
|
|
734
|
+
- Parameters:
|
|
735
|
+
- `element` (string): undefined
|
|
736
|
+
- `x` (number): X coordinate
|
|
737
|
+
- `y` (number): Y coordinate
|
|
738
|
+
- `expectation` (object, optional): undefined
|
|
739
|
+
- Read-only: **false**
|
|
740
|
+
|
|
741
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
742
|
+
|
|
743
|
+
- **browser_mouse_drag_xy**
|
|
744
|
+
- Title: Drag mouse
|
|
745
|
+
- Description: Drag from one coordinate to another.Requires --caps=vision.startX,startY→endX,endY.expectation:{includeSnapshot:true,snapshotOptions:{selector:".drop-zone"}} to verify.PREFER browser_drag with element refs over coordinates.
|
|
746
|
+
- Parameters:
|
|
747
|
+
- `element` (string): undefined
|
|
748
|
+
- `startX` (number): Start X coordinate
|
|
749
|
+
- `startY` (number): Start Y coordinate
|
|
750
|
+
- `endX` (number): End X coordinate
|
|
751
|
+
- `endY` (number): End Y coordinate
|
|
752
|
+
- `expectation` (object, optional): undefined
|
|
753
|
+
- Read-only: **false**
|
|
754
|
+
|
|
755
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
756
|
+
|
|
757
|
+
- **browser_mouse_move_xy**
|
|
758
|
+
- Title: Move mouse
|
|
759
|
+
- Description: Move mouse to specific coordinates.Requires --caps=vision.x,y:coordinates.expectation:{includeSnapshot:false} for simple move,true to see hover effects.PREFER element-based interactions over coordinates when possible.
|
|
760
|
+
- Parameters:
|
|
761
|
+
- `element` (string): undefined
|
|
762
|
+
- `x` (number): X coordinate
|
|
763
|
+
- `y` (number): Y coordinate
|
|
764
|
+
- `expectation` (object, optional): undefined
|
|
765
|
+
- Read-only: **true**
|
|
766
|
+
|
|
767
|
+
</details>
|
|
768
|
+
|
|
769
|
+
<details><summary><b>PDF generation (opt-in via --caps=pdf)</b></summary>
|
|
770
|
+
|
|
771
|
+
<!-- NOTE: This has been generated via update-readme.js -->
|
|
772
|
+
|
|
773
|
+
- **browser_pdf_save**
|
|
774
|
+
- Title: Save as PDF
|
|
775
|
+
- Description: Save page as PDF
|
|
776
|
+
- Parameters:
|
|
777
|
+
- `filename` (string, optional): File name to save the pdf to. Defaults to `page-{timestamp}.pdf` if not specified.
|
|
778
|
+
- Read-only: **true**
|
|
779
|
+
|
|
780
|
+
</details>
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
<!--- End of tools generated section -->
|
|
784
|
+
|
|
785
|
+
## Token Optimization Features
|
|
786
|
+
|
|
787
|
+
Playwright MCP server includes advanced token optimization features to reduce token usage and improve performance through response filtering and batch execution.
|
|
788
|
+
|
|
789
|
+
### Response Filtering with Expectation Parameter
|
|
790
|
+
|
|
791
|
+
All browser tools support an optional `expectation` parameter that controls what information is included in the response. This can significantly reduce token usage by excluding unnecessary data.
|
|
792
|
+
|
|
793
|
+
#### Basic Usage
|
|
794
|
+
|
|
795
|
+
```javascript
|
|
796
|
+
// Standard call - includes all information (snapshot, console, tabs, etc.)
|
|
797
|
+
await browser_navigate({ url: 'https://example.com' });
|
|
798
|
+
|
|
799
|
+
// Optimized call - only includes essential information
|
|
800
|
+
await browser_navigate({
|
|
801
|
+
url: 'https://example.com',
|
|
802
|
+
expectation: {
|
|
803
|
+
includeSnapshot: false, // Skip page snapshot
|
|
804
|
+
includeConsole: false, // Skip console messages
|
|
805
|
+
includeTabs: false // Skip tab information
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
#### Expectation Options
|
|
811
|
+
|
|
812
|
+
- **`includeSnapshot`** (boolean, default: varies by tool): Include page accessibility snapshot
|
|
813
|
+
- **`includeConsole`** (boolean, default: varies by tool): Include browser console messages
|
|
814
|
+
- **`includeDownloads`** (boolean, default: true): Include download information
|
|
815
|
+
- **`includeTabs`** (boolean, default: varies by tool): Include tab information
|
|
816
|
+
- **`includeCode`** (boolean, default: true): Include executed code in response
|
|
817
|
+
|
|
818
|
+
#### Advanced Snapshot Options
|
|
819
|
+
|
|
820
|
+
```javascript
|
|
821
|
+
await browser_click({
|
|
822
|
+
element: 'Login button',
|
|
823
|
+
ref: '#login-btn',
|
|
824
|
+
expectation: {
|
|
825
|
+
includeSnapshot: true,
|
|
826
|
+
snapshotOptions: {
|
|
827
|
+
selector: '.dashboard', // Only capture dashboard area
|
|
828
|
+
maxLength: 1000, // Limit snapshot length
|
|
829
|
+
format: 'text' // Use text format instead of aria
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
});
|
|
833
|
+
```
|
|
834
|
+
|
|
835
|
+
#### Console Filtering Options
|
|
836
|
+
|
|
837
|
+
```javascript
|
|
838
|
+
await browser_navigate({
|
|
839
|
+
url: 'https://example.com',
|
|
840
|
+
expectation: {
|
|
841
|
+
includeConsole: true,
|
|
842
|
+
consoleOptions: {
|
|
843
|
+
levels: ['error', 'warn'], // Only errors and warnings
|
|
844
|
+
maxMessages: 5, // Limit to 5 messages
|
|
845
|
+
patterns: ['^Error:'], // Filter by regex patterns
|
|
846
|
+
removeDuplicates: true // Remove duplicate messages
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
```
|
|
851
|
+
|
|
852
|
+
### Batch Execution
|
|
853
|
+
|
|
854
|
+
Execute multiple browser actions in a single request with optimized response handling and flexible error control.
|
|
855
|
+
|
|
856
|
+
#### Basic Batch Execution
|
|
857
|
+
|
|
858
|
+
```javascript
|
|
859
|
+
await browser_batch_execute({
|
|
860
|
+
steps: [
|
|
861
|
+
{
|
|
862
|
+
tool: 'browser_navigate',
|
|
863
|
+
arguments: { url: 'https://example.com/login' }
|
|
864
|
+
},
|
|
865
|
+
{
|
|
866
|
+
tool: 'browser_type',
|
|
867
|
+
arguments: {
|
|
868
|
+
element: 'username field',
|
|
869
|
+
ref: '#username',
|
|
870
|
+
text: 'testuser'
|
|
871
|
+
}
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
tool: 'browser_type',
|
|
875
|
+
arguments: {
|
|
876
|
+
element: 'password field',
|
|
877
|
+
ref: '#password',
|
|
878
|
+
text: 'password'
|
|
879
|
+
}
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
tool: 'browser_click',
|
|
883
|
+
arguments: { element: 'login button', ref: '#login-btn' }
|
|
884
|
+
}
|
|
885
|
+
]
|
|
886
|
+
});
|
|
887
|
+
```
|
|
888
|
+
|
|
889
|
+
#### Advanced Batch Configuration
|
|
890
|
+
|
|
891
|
+
```javascript
|
|
892
|
+
await browser_batch_execute({
|
|
893
|
+
steps: [
|
|
894
|
+
{
|
|
895
|
+
tool: 'browser_navigate',
|
|
896
|
+
arguments: { url: 'https://example.com' },
|
|
897
|
+
expectation: { includeSnapshot: false }, // Step-specific optimization
|
|
898
|
+
continueOnError: true // Continue if this step fails
|
|
899
|
+
},
|
|
900
|
+
{
|
|
901
|
+
tool: 'browser_click',
|
|
902
|
+
arguments: { element: 'button', ref: '#submit' },
|
|
903
|
+
expectation: {
|
|
904
|
+
includeSnapshot: true,
|
|
905
|
+
snapshotOptions: { selector: '.result-area' }
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
],
|
|
909
|
+
stopOnFirstError: false, // Continue executing remaining steps
|
|
910
|
+
globalExpectation: { // Default for all steps
|
|
911
|
+
includeConsole: false,
|
|
912
|
+
includeTabs: false
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
```
|
|
916
|
+
|
|
917
|
+
#### Error Handling Options
|
|
918
|
+
|
|
919
|
+
- **`continueOnError`** (per step): Continue batch execution even if this step fails
|
|
920
|
+
- **`stopOnFirstError`** (global): Stop entire batch on first error
|
|
921
|
+
- Flexible combination allows for robust automation workflows
|
|
922
|
+
|
|
923
|
+
### Tool-Specific Defaults
|
|
924
|
+
|
|
925
|
+
Each tool has optimized defaults based on typical usage patterns:
|
|
926
|
+
|
|
927
|
+
- **Navigation tools** (`browser_navigate`): Include full context for verification
|
|
928
|
+
- **Interactive tools** (`browser_click`, `browser_type`): Include snapshot but minimal logging
|
|
929
|
+
- **Screenshot/snapshot tools**: Exclude additional context
|
|
930
|
+
- **Code evaluation**: Include console output but minimal other info
|
|
931
|
+
- **Wait operations**: Minimal output for efficiency
|
|
932
|
+
|
|
933
|
+
### Performance Benefits
|
|
934
|
+
|
|
935
|
+
- **Token Reduction**: 50-80% reduction in token usage with optimized expectations
|
|
936
|
+
- **Faster Execution**: 2-5x speed improvement with batch execution
|
|
937
|
+
- **Reduced Latency**: Fewer round trips between client and server
|
|
938
|
+
- **Cost Optimization**: Lower API costs due to reduced token consumption
|
|
939
|
+
|
|
940
|
+
### Response Diff Detection
|
|
941
|
+
|
|
942
|
+
The Fast Server includes automatic diff detection to efficiently track changes between consecutive tool executions:
|
|
943
|
+
|
|
944
|
+
```javascript
|
|
945
|
+
// Enable diff detection for any tool
|
|
946
|
+
await browser_click({
|
|
947
|
+
element: 'Load more button',
|
|
948
|
+
ref: '#load-more',
|
|
949
|
+
expectation: {
|
|
950
|
+
includeSnapshot: true,
|
|
951
|
+
diffOptions: {
|
|
952
|
+
enabled: true,
|
|
953
|
+
threshold: 0.1, // Show diff if >10% changed
|
|
954
|
+
format: 'unified', // or 'split', 'minimal'
|
|
955
|
+
maxDiffLines: 50, // Limit diff output size
|
|
956
|
+
context: 3 // Lines of context around changes
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
});
|
|
960
|
+
```
|
|
961
|
+
|
|
962
|
+
#### Diff Detection Benefits
|
|
963
|
+
|
|
964
|
+
- **Minimal token usage**: Only changed content is shown instead of full snapshots
|
|
965
|
+
- **Change tracking**: Automatically detects what changed after actions
|
|
966
|
+
- **Flexible formats**: Choose between unified, split, or minimal diff formats
|
|
967
|
+
- **Smart caching**: Compares against previous response from the same tool
|
|
968
|
+
|
|
969
|
+
#### When to Use Diff Detection
|
|
970
|
+
|
|
971
|
+
1. **UI interactions without navigation**: Clicks, typing, hover effects
|
|
972
|
+
2. **Dynamic content updates**: Loading more items, real-time updates
|
|
973
|
+
3. **Form interactions**: Track changes as users fill forms
|
|
974
|
+
4. **Selective monitoring**: Use with CSS selectors to track specific areas
|
|
975
|
+
|
|
976
|
+
```javascript
|
|
977
|
+
// Example: Track only search results changes
|
|
978
|
+
await browser_type({
|
|
979
|
+
element: 'Search input',
|
|
980
|
+
ref: '#search',
|
|
981
|
+
text: 'playwright',
|
|
982
|
+
expectation: {
|
|
983
|
+
includeSnapshot: true,
|
|
984
|
+
snapshotOptions: {
|
|
985
|
+
selector: '#search-results' // Only monitor results area
|
|
986
|
+
},
|
|
987
|
+
diffOptions: {
|
|
988
|
+
enabled: true,
|
|
989
|
+
format: 'minimal' // Just show what changed
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
});
|
|
993
|
+
```
|
|
994
|
+
|
|
995
|
+
### Best Practices
|
|
996
|
+
|
|
997
|
+
1. **Use batch execution** for multi-step workflows
|
|
998
|
+
2. **Enable diff detection** for actions without page navigation
|
|
999
|
+
3. **Disable snapshots** for intermediate steps that don't need verification
|
|
1000
|
+
4. **Use selective snapshots** with CSS selectors for large pages
|
|
1001
|
+
5. **Filter console messages** to relevant levels only
|
|
1002
|
+
6. **Combine global and step-specific expectations** for fine-grained control
|
|
1003
|
+
7. **Use minimal diff format** for maximum token savings
|
|
1004
|
+
|
|
1005
|
+
### Diagnostic System Examples
|
|
1006
|
+
|
|
1007
|
+
**Find alternative elements when selectors fail:**
|
|
1008
|
+
```json
|
|
1009
|
+
{
|
|
1010
|
+
"name": "browser_find_elements",
|
|
1011
|
+
"arguments": {
|
|
1012
|
+
"searchCriteria": {
|
|
1013
|
+
"text": "Submit",
|
|
1014
|
+
"role": "button"
|
|
1015
|
+
},
|
|
1016
|
+
"maxResults": 5
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
```
|
|
1020
|
+
|
|
1021
|
+
**Generate comprehensive page diagnostics:**
|
|
1022
|
+
```json
|
|
1023
|
+
{
|
|
1024
|
+
"name": "browser_diagnose",
|
|
1025
|
+
"arguments": {
|
|
1026
|
+
"includePerformanceMetrics": true,
|
|
1027
|
+
"includeAccessibilityInfo": true,
|
|
1028
|
+
"includeTroubleshootingSuggestions": true
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
```
|
|
1032
|
+
|
|
1033
|
+
**Debug automation failures with enhanced errors:**
|
|
1034
|
+
All tools automatically provide enhanced error messages with:
|
|
1035
|
+
- Alternative element suggestions
|
|
1036
|
+
- Page structure analysis
|
|
1037
|
+
- Context-aware troubleshooting tips
|
|
1038
|
+
- Performance insights
|
|
1039
|
+
|
|
1040
|
+
### Migration Guide
|
|
1041
|
+
|
|
1042
|
+
Existing code continues to work without changes. To optimize:
|
|
1043
|
+
|
|
1044
|
+
1. Start by adding `expectation: { includeSnapshot: false }` to intermediate steps
|
|
1045
|
+
2. Use batch execution for sequences of 3+ operations
|
|
1046
|
+
3. Gradually fine-tune expectations based on your specific needs
|
|
1047
|
+
4. Use diagnostic tools when automation fails or needs debugging
|