@guanzhu.me/pw-cli 0.0.20 → 0.0.22
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/bin/pw-cli.js +11 -3
- package/package.json +1 -1
- package/src/browser-manager.js +25 -17
package/bin/pw-cli.js
CHANGED
|
@@ -718,9 +718,17 @@ async function handleRunScript(rawArgv) {
|
|
|
718
718
|
break;
|
|
719
719
|
}
|
|
720
720
|
}
|
|
721
|
-
// Merge
|
|
722
|
-
|
|
723
|
-
|
|
721
|
+
// Merge only explicitly specified flags after run-script into options
|
|
722
|
+
// (avoid overwriting earlier options with defaults from parsePwCliGlobalOptions)
|
|
723
|
+
if (flags.length > 0) {
|
|
724
|
+
const defaults = parsePwCliGlobalOptions([]);
|
|
725
|
+
const afterOptions = parsePwCliGlobalOptions(flags);
|
|
726
|
+
for (const [key, value] of Object.entries(afterOptions)) {
|
|
727
|
+
if (value !== defaults[key]) {
|
|
728
|
+
options[key] = value;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
}
|
|
724
732
|
|
|
725
733
|
const positionals = afterRs.slice(restIdx);
|
|
726
734
|
const [scriptPath, ...scriptArgs] = positionals;
|
package/package.json
CHANGED
package/src/browser-manager.js
CHANGED
|
@@ -11,22 +11,34 @@ const { readState, writeState, clearState, getProfileDir } = require('./state');
|
|
|
11
11
|
const { probeCDP, findFreePort, sleep, fetchActivePageUrl } = require('./utils');
|
|
12
12
|
|
|
13
13
|
function loadPlaywrightUtilsBundle() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
// playwright-core's package.json "exports" blocks deep subpath requires, so
|
|
15
|
+
// we locate the package root via require.resolve on package.json, then load
|
|
16
|
+
// the internal module by absolute path.
|
|
17
|
+
const searchPaths = [
|
|
18
|
+
path.join(__dirname, '..'), // local dev
|
|
19
|
+
path.join(__dirname, '..', 'node_modules', '@playwright', 'cli'), // nested under pw-cli
|
|
17
20
|
];
|
|
18
21
|
|
|
19
|
-
|
|
22
|
+
// Also search from the global npm root where @playwright/cli might live
|
|
23
|
+
try {
|
|
24
|
+
const globalRoot = execSync('npm root -g', { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
|
25
|
+
searchPaths.push(path.join(globalRoot, '@playwright', 'cli'));
|
|
26
|
+
searchPaths.push(globalRoot);
|
|
27
|
+
} catch {}
|
|
28
|
+
|
|
29
|
+
for (const searchPath of searchPaths) {
|
|
20
30
|
try {
|
|
21
|
-
|
|
31
|
+
const pkgJson = require.resolve('playwright-core/package.json', { paths: [searchPath] });
|
|
32
|
+
const utilsBundle = path.join(path.dirname(pkgJson), 'lib', 'utilsBundleImpl');
|
|
33
|
+
return require(utilsBundle);
|
|
22
34
|
} catch (error) {
|
|
23
|
-
if (error.code !== 'MODULE_NOT_FOUND') {
|
|
35
|
+
if (error.code !== 'MODULE_NOT_FOUND' && error.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
|
|
24
36
|
throw error;
|
|
25
37
|
}
|
|
26
38
|
}
|
|
27
39
|
}
|
|
28
40
|
|
|
29
|
-
throw new Error('Unable to load playwright-core utilsBundleImpl
|
|
41
|
+
throw new Error('Unable to load playwright-core utilsBundleImpl. Reinstall @playwright/cli or playwright.');
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
const { ws, wsServer } = loadPlaywrightUtilsBundle();
|
|
@@ -310,11 +322,14 @@ class CDPRelayServer {
|
|
|
310
322
|
}
|
|
311
323
|
|
|
312
324
|
_connectBrowser(clientName) {
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
325
|
+
const mcpRelayEndpoint = `${this._wsHost}${this._extensionPath}`;
|
|
326
|
+
// Support both the new official extension ID and the legacy one
|
|
327
|
+
const extensionId = process.env.PLAYWRIGHT_MCP_EXTENSION_ID || 'mmlmfjhmonkocbjadbfplnigmagldckm';
|
|
328
|
+
const url = new URL(`chrome-extension://${extensionId}/connect.html`);
|
|
329
|
+
url.searchParams.set('mcpRelayUrl', mcpRelayEndpoint);
|
|
316
330
|
url.searchParams.set('client', JSON.stringify({ name: clientName }));
|
|
317
331
|
url.searchParams.set('protocolVersion', '1');
|
|
332
|
+
url.searchParams.set('newTab', 'true');
|
|
318
333
|
if (this._extensionToken) {
|
|
319
334
|
url.searchParams.set('token', this._extensionToken);
|
|
320
335
|
}
|
|
@@ -342,13 +357,6 @@ class CDPRelayServer {
|
|
|
342
357
|
return;
|
|
343
358
|
}
|
|
344
359
|
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
|
-
}
|
|
352
360
|
this._handleExtensionConnection(socket);
|
|
353
361
|
return;
|
|
354
362
|
}
|