@playwright/mcp 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -4,7 +4,7 @@ A Model Context Protocol (MCP) server that provides browser automation capabilit
4
4
 
5
5
  ### Key Features
6
6
 
7
- - **Fast and lightweight**: Uses Playwrights accessibility tree, not pixel-based input.
7
+ - **Fast and lightweight**: Uses Playwright's accessibility tree, not pixel-based input.
8
8
  - **LLM-friendly**: No vision models needed, operates purely on structured data.
9
9
  - **Deterministic tool application**: Avoids ambiguity common with screenshot-based approaches.
10
10
 
@@ -23,13 +23,31 @@ A Model Context Protocol (MCP) server that provides browser automation capabilit
23
23
  "playwright": {
24
24
  "command": "npx",
25
25
  "args": [
26
- "@playwright/mcp",
26
+ "@playwright/mcp@latest"
27
27
  ]
28
28
  }
29
29
  }
30
30
  }
31
31
  ```
32
32
 
33
+
34
+ #### Installation in VS Code
35
+
36
+ Install the Playwright MCP server using the VS Code CLI:
37
+
38
+ ```bash
39
+ # For VS Code
40
+ code --add-mcp '{"name":"playwright","command":"npx","args":["@playwright/mcp@latest"]}'
41
+ ```
42
+
43
+ ```bash
44
+ # For VS Code Insiders
45
+ code-insiders --add-mcp '{"name":"playwright","command":"npx","args":["@playwright/mcp@latest"]}'
46
+ ```
47
+
48
+ After installation, the Playwright MCP server will be available for use with your GitHub Copilot agent in VS Code.
49
+
50
+
33
51
  ### Running headless browser (Browser without GUI).
34
52
 
35
53
  This mode is useful for background or batch operations.
@@ -40,7 +58,7 @@ This mode is useful for background or batch operations.
40
58
  "playwright": {
41
59
  "command": "npx",
42
60
  "args": [
43
- "@playwright/mcp",
61
+ "@playwright/mcp@latest",
44
62
  "--headless"
45
63
  ]
46
64
  }
@@ -66,7 +84,7 @@ And then in MCP config, add following to the `env`:
66
84
  "playwright": {
67
85
  "command": "npx",
68
86
  "args": [
69
- "@playwright/mcp"
87
+ "@playwright/mcp@latest"
70
88
  ],
71
89
  "env": {
72
90
  // Use the endpoint from the output of the server above.
@@ -92,7 +110,7 @@ To use Vision Mode, add the `--vision` flag when starting the server:
92
110
  "playwright": {
93
111
  "command": "npx",
94
112
  "args": [
95
- "@playwright/mcp",
113
+ "@playwright/mcp@latest",
96
114
  "--vision"
97
115
  ]
98
116
  }
package/lib/context.js CHANGED
@@ -52,6 +52,7 @@ exports.Context = void 0;
52
52
  const playwright = __importStar(require("playwright"));
53
53
  class Context {
54
54
  _launchOptions;
55
+ _browser;
55
56
  _page;
56
57
  _console = [];
57
58
  _initializePromise;
@@ -69,29 +70,37 @@ class Context {
69
70
  async close() {
70
71
  const page = await this.ensurePage();
71
72
  await page.close();
72
- this._initializePromise = undefined;
73
73
  }
74
74
  async _initialize() {
75
75
  if (this._initializePromise)
76
76
  return this._initializePromise;
77
77
  this._initializePromise = (async () => {
78
- const browser = await this._createBrowser();
79
- this._page = await browser.newPage();
78
+ this._browser = await createBrowser(this._launchOptions);
79
+ this._page = await this._browser.newPage();
80
80
  this._page.on('console', event => this._console.push(event));
81
81
  this._page.on('framenavigated', frame => {
82
82
  if (!frame.parentFrame())
83
83
  this._console.length = 0;
84
84
  });
85
+ this._page.on('close', () => this._reset());
85
86
  })();
86
87
  return this._initializePromise;
87
88
  }
88
- async _createBrowser() {
89
- if (process.env.PLAYWRIGHT_WS_ENDPOINT) {
90
- const url = new URL(process.env.PLAYWRIGHT_WS_ENDPOINT);
91
- url.searchParams.set('launch-options', JSON.stringify(this._launchOptions));
92
- return await playwright.chromium.connect(String(url));
93
- }
94
- return await playwright.chromium.launch({ channel: 'chrome', ...this._launchOptions });
89
+ _reset() {
90
+ const browser = this._browser;
91
+ this._initializePromise = undefined;
92
+ this._browser = undefined;
93
+ this._page = undefined;
94
+ this._console.length = 0;
95
+ void browser?.close();
95
96
  }
96
97
  }
97
98
  exports.Context = Context;
99
+ async function createBrowser(launchOptions) {
100
+ if (process.env.PLAYWRIGHT_WS_ENDPOINT) {
101
+ const url = new URL(process.env.PLAYWRIGHT_WS_ENDPOINT);
102
+ url.searchParams.set('launch-options', JSON.stringify(launchOptions));
103
+ return await playwright.chromium.connect(String(url));
104
+ }
105
+ return await playwright.chromium.launch({ channel: 'chrome', ...launchOptions });
106
+ }
package/lib/server.js CHANGED
@@ -23,7 +23,6 @@ const context_1 = require("./context");
23
23
  class Server {
24
24
  _server;
25
25
  _tools;
26
- _page;
27
26
  _context;
28
27
  constructor(options, launchOptions) {
29
28
  const { name, version, tools, resources } = options;
@@ -74,7 +73,7 @@ class Server {
74
73
  }
75
74
  async stop() {
76
75
  await this._server.close();
77
- await this._page?.context()?.browser()?.close();
76
+ await this._context.close();
78
77
  }
79
78
  }
80
79
  exports.Server = Server;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playwright/mcp",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Playwright Tools for MCP",
5
5
  "repository": {
6
6
  "type": "git",