|
1 |
| -# Repository setup required :wave: |
2 |
| - |
3 |
| -Please visit the website URL :point_right: for this repository to complete the setup of this repository and configure access controls. |
| 1 | +## Playwright MCP |
| 2 | + |
| 3 | +This package is experimental and not yet ready for production use. |
| 4 | +It is a subject to change and will not respect semver versioning. |
| 5 | + |
| 6 | +### Example config |
| 7 | + |
| 8 | +```js |
| 9 | +{ |
| 10 | + "mcpServers": { |
| 11 | + "playwright": { |
| 12 | + "command": "npx", |
| 13 | + "args": [ |
| 14 | + "@playwright/mcp", |
| 15 | + "--headless" |
| 16 | + ] |
| 17 | + } |
| 18 | + } |
| 19 | +} |
| 20 | +``` |
| 21 | + |
| 22 | +### Running headed browser (Browser with GUI). |
| 23 | + |
| 24 | +```js |
| 25 | +{ |
| 26 | + "mcpServers": { |
| 27 | + "playwright": { |
| 28 | + "command": "npx", |
| 29 | + "args": [ |
| 30 | + "@playwright/mcp" |
| 31 | + ] |
| 32 | + } |
| 33 | + } |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +### Running headed browser on Linux |
| 38 | + |
| 39 | +When running headed browser on system w/o display or from worker processes of the IDEs, |
| 40 | +you can run Playwright in a client-server manner. You'll run the Playwright server |
| 41 | +from environment with the DISPLAY |
| 42 | + |
| 43 | +```sh |
| 44 | +npx playwright run-server |
| 45 | +``` |
| 46 | + |
| 47 | +And then in MCP config, add following to the `env`: |
| 48 | + |
| 49 | +```js |
| 50 | +{ |
| 51 | + "mcpServers": { |
| 52 | + "playwright": { |
| 53 | + "command": "npx", |
| 54 | + "args": [ |
| 55 | + "@playwright/mcp" |
| 56 | + ], |
| 57 | + "env": { |
| 58 | + // Use the endpoint from the output of the server above. |
| 59 | + "PLAYWRIGHT_WS_ENDPOINT": "ws://localhost:<port>/" |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +### Tool Modes |
| 67 | + |
| 68 | +The tools are available in two modes: |
| 69 | + |
| 70 | +1. **Snapshot Mode** (default): Uses accessibility snapshots for better performance and reliability |
| 71 | +2. **Vision Mode**: Uses screenshots for visual-based interactions |
| 72 | + |
| 73 | +To use Vision Mode, add the `--vision` flag when starting the server: |
| 74 | + |
| 75 | +```js |
| 76 | +{ |
| 77 | + "mcpServers": { |
| 78 | + "playwright": { |
| 79 | + "command": "npx", |
| 80 | + "args": [ |
| 81 | + "@playwright/mcp", |
| 82 | + "--vision" |
| 83 | + ] |
| 84 | + } |
| 85 | + } |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +Vision Mode works best with the computer use models that are able to interact with elements using |
| 90 | +X Y coordinate space, based on the provided screenshot. |
| 91 | + |
| 92 | +### Snapshot Mode |
| 93 | + |
| 94 | +The Playwright MCP provides a set of tools for browser automation. Here are all available tools: |
| 95 | + |
| 96 | +- **browser_navigate** |
| 97 | + - Description: Navigate to a URL |
| 98 | + - Parameters: |
| 99 | + - `url` (string): The URL to navigate to |
| 100 | + |
| 101 | +- **browser_go_back** |
| 102 | + - Description: Go back to the previous page |
| 103 | + - Parameters: None |
| 104 | + |
| 105 | +- **browser_go_forward** |
| 106 | + - Description: Go forward to the next page |
| 107 | + - Parameters: None |
| 108 | + |
| 109 | +- **browser_click** |
| 110 | + - Description: Perform click on a web page |
| 111 | + - Parameters: |
| 112 | + - `element` (string): Human-readable element description used to obtain permission to interact with the element |
| 113 | + - `ref` (string): Exact target element reference from the page snapshot |
| 114 | + |
| 115 | +- **browser_hover** |
| 116 | + - Description: Hover over element on page |
| 117 | + - Parameters: |
| 118 | + - `element` (string): Human-readable element description used to obtain permission to interact with the element |
| 119 | + - `ref` (string): Exact target element reference from the page snapshot |
| 120 | + |
| 121 | +- **browser_drag** |
| 122 | + - Description: Perform drag and drop between two elements |
| 123 | + - Parameters: |
| 124 | + - `startElement` (string): Human-readable source element description used to obtain permission to interact with the element |
| 125 | + - `startRef` (string): Exact source element reference from the page snapshot |
| 126 | + - `endElement` (string): Human-readable target element description used to obtain permission to interact with the element |
| 127 | + - `endRef` (string): Exact target element reference from the page snapshot |
| 128 | + |
| 129 | +- **browser_type** |
| 130 | + - Description: Type text into editable element |
| 131 | + - Parameters: |
| 132 | + - `element` (string): Human-readable element description used to obtain permission to interact with the element |
| 133 | + - `ref` (string): Exact target element reference from the page snapshot |
| 134 | + - `text` (string): Text to type into the element |
| 135 | + - `submit` (boolean): Whether to submit entered text (press Enter after) |
| 136 | + |
| 137 | +- **browser_press_key** |
| 138 | + - Description: Press a key on the keyboard |
| 139 | + - Parameters: |
| 140 | + - `key` (string): Name of the key to press or a character to generate, such as `ArrowLeft` or `a` |
| 141 | + |
| 142 | +- **browser_snapshot** |
| 143 | + - Description: Capture accessibility snapshot of the current page (better than screenshot) |
| 144 | + - Parameters: None |
| 145 | + |
| 146 | +- **browser_save_as_pdf** |
| 147 | + - Description: Save page as PDF |
| 148 | + - Parameters: None |
| 149 | + |
| 150 | +- **browser_wait** |
| 151 | + - Description: Wait for a specified time in seconds |
| 152 | + - Parameters: |
| 153 | + - `time` (number): The time to wait in seconds (capped at 10 seconds) |
| 154 | + |
| 155 | +- **browser_close** |
| 156 | + - Description: Close the page |
| 157 | + - Parameters: None |
| 158 | + |
| 159 | + |
| 160 | +### Vision Mode |
| 161 | + |
| 162 | +Vision Mode provides tools for visual-based interactions using screenshots. Here are all available tools: |
| 163 | + |
| 164 | +- **browser_navigate** |
| 165 | + - Description: Navigate to a URL |
| 166 | + - Parameters: |
| 167 | + - `url` (string): The URL to navigate to |
| 168 | + |
| 169 | +- **browser_go_back** |
| 170 | + - Description: Go back to the previous page |
| 171 | + - Parameters: None |
| 172 | + |
| 173 | +- **browser_go_forward** |
| 174 | + - Description: Go forward to the next page |
| 175 | + - Parameters: None |
| 176 | + |
| 177 | +- **browser_screenshot** |
| 178 | + - Description: Capture screenshot of the current page |
| 179 | + - Parameters: None |
| 180 | + |
| 181 | +- **browser_move_mouse** |
| 182 | + - Description: Move mouse to specified coordinates |
| 183 | + - Parameters: |
| 184 | + - `x` (number): X coordinate |
| 185 | + - `y` (number): Y coordinate |
| 186 | + |
| 187 | +- **browser_click** |
| 188 | + - Description: Click at specified coordinates |
| 189 | + - Parameters: |
| 190 | + - `x` (number): X coordinate to click at |
| 191 | + - `y` (number): Y coordinate to click at |
| 192 | + |
| 193 | +- **browser_drag** |
| 194 | + - Description: Perform drag and drop operation |
| 195 | + - Parameters: |
| 196 | + - `startX` (number): Start X coordinate |
| 197 | + - `startY` (number): Start Y coordinate |
| 198 | + - `endX` (number): End X coordinate |
| 199 | + - `endY` (number): End Y coordinate |
| 200 | + |
| 201 | +- **browser_type** |
| 202 | + - Description: Type text at specified coordinates |
| 203 | + - Parameters: |
| 204 | + - `text` (string): Text to type |
| 205 | + - `submit` (boolean): Whether to submit entered text (press Enter after) |
| 206 | + |
| 207 | +- **browser_press_key** |
| 208 | + - Description: Press a key on the keyboard |
| 209 | + - Parameters: |
| 210 | + - `key` (string): Name of the key to press or a character to generate, such as `ArrowLeft` or `a` |
| 211 | + |
| 212 | +- **browser_save_as_pdf** |
| 213 | + - Description: Save page as PDF |
| 214 | + - Parameters: None |
| 215 | + |
| 216 | +- **browser_wait** |
| 217 | + - Description: Wait for a specified time in seconds |
| 218 | + - Parameters: |
| 219 | + - `time` (number): The time to wait in seconds (capped at 10 seconds) |
| 220 | + |
| 221 | +- **browser_close** |
| 222 | + - Description: Close the page |
| 223 | + - Parameters: None |
0 commit comments