@guanzhu.me/pw-cli 0.0.19 → 0.0.20

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guanzhu.me/pw-cli",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "Persistent Playwright browser CLI with headed defaults, profile support, queueing, and script execution",
5
5
  "bin": {
6
6
  "pw-cli": "./bin/pw-cli.js"
@@ -262,13 +262,14 @@ class ExtensionConnection {
262
262
  }
263
263
 
264
264
  class CDPRelayServer {
265
- constructor(server, browserChannel, userDataDir, executablePath) {
265
+ constructor(server, browserChannel, userDataDir, executablePath, extensionToken) {
266
266
  this._playwrightConnection = null;
267
267
  this._extensionConnection = null;
268
268
  this._nextSessionId = 1;
269
269
  this._browserChannel = browserChannel;
270
270
  this._userDataDir = userDataDir;
271
271
  this._executablePath = executablePath;
272
+ this._extensionToken = extensionToken || null;
272
273
  const uuid = crypto.randomUUID();
273
274
  const address = server.address();
274
275
  this._wsHost = `ws://127.0.0.1:${address.port}`;
@@ -314,6 +315,9 @@ class CDPRelayServer {
314
315
  url.searchParams.set('mcpRelayUrl', relayUrl);
315
316
  url.searchParams.set('client', JSON.stringify({ name: clientName }));
316
317
  url.searchParams.set('protocolVersion', '1');
318
+ if (this._extensionToken) {
319
+ url.searchParams.set('token', this._extensionToken);
320
+ }
317
321
 
318
322
  const executablePath = this._executablePath || resolveExtensionExecutablePath(this._browserChannel);
319
323
  const args = [];
@@ -338,6 +342,13 @@ class CDPRelayServer {
338
342
  return;
339
343
  }
340
344
  if (url.pathname === this._extensionPath) {
345
+ if (this._extensionToken) {
346
+ const token = url.searchParams.get('token');
347
+ if (token !== this._extensionToken) {
348
+ socket.close(4003, 'Invalid token');
349
+ return;
350
+ }
351
+ }
341
352
  this._handleExtensionConnection(socket);
342
353
  return;
343
354
  }
@@ -479,7 +490,8 @@ async function startExtensionRelay(extension) {
479
490
  server.once('error', reject);
480
491
  server.listen(0, '127.0.0.1', resolve);
481
492
  });
482
- const relay = new CDPRelayServer(server, browser, null, null);
493
+ const extensionToken = process.env.PLAYWRIGHT_MCP_EXTENSION_TOKEN || null;
494
+ const relay = new CDPRelayServer(server, browser, null, null, extensionToken);
483
495
  await relay.ensureExtensionConnectionForMCPContext('pw-cli');
484
496
  return { relay, server };
485
497
  }