@xcanwin/manyoyo 5.11.9 → 5.11.10
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/lib/plugin/playwright.js +62 -2
- package/package.json +1 -1
package/lib/plugin/playwright.js
CHANGED
|
@@ -437,6 +437,58 @@ class PlaywrightPlugin {
|
|
|
437
437
|
this.writeStdout('}');
|
|
438
438
|
}
|
|
439
439
|
|
|
440
|
+
remoteDebuggingPageUrl() {
|
|
441
|
+
return 'chrome://inspect/#remote-debugging';
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
openChromeRemoteDebuggingPage() {
|
|
445
|
+
const url = this.remoteDebuggingPageUrl();
|
|
446
|
+
const platform = process.platform;
|
|
447
|
+
let commands = [];
|
|
448
|
+
|
|
449
|
+
if (platform === 'darwin') {
|
|
450
|
+
commands = [
|
|
451
|
+
['open', '-a', 'Google Chrome', url],
|
|
452
|
+
['open', url]
|
|
453
|
+
];
|
|
454
|
+
} else if (platform === 'win32') {
|
|
455
|
+
commands = [
|
|
456
|
+
['cmd', '/c', 'start', '', 'chrome', url]
|
|
457
|
+
];
|
|
458
|
+
} else {
|
|
459
|
+
commands = [
|
|
460
|
+
['google-chrome', url],
|
|
461
|
+
['google-chrome-stable', url],
|
|
462
|
+
['chromium', url],
|
|
463
|
+
['chromium-browser', url]
|
|
464
|
+
];
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
for (const args of commands) {
|
|
468
|
+
const result = this.runCmd(args, { check: false, captureOutput: true });
|
|
469
|
+
if (result.returncode === 0) {
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
remindDevHostCliSessionScene() {
|
|
477
|
+
this.writeStdout(`[tip] 已尝试用 Chrome 打开 ${this.remoteDebuggingPageUrl()},请在页面中确认 remote debugging 相关勾选项已启用。`);
|
|
478
|
+
this.writeStdout('[tip] 如果希望容器内 manyoyo run 自动附着到宿主机正在运行的 Chrome,请在 ~/.manyoyo/manyoyo.json 中设置:');
|
|
479
|
+
this.writeStdout('{');
|
|
480
|
+
this.writeStdout(' "volumes": [');
|
|
481
|
+
this.writeStdout(' "~/.manyoyo/.cache/ms-playwright:/root/.cache/ms-playwright",');
|
|
482
|
+
this.writeStdout(' "~/Library/Application Support/Google/Chrome/DevToolsActivePort:/root/Library/Application Support/Google/Chrome/DevToolsActivePort"');
|
|
483
|
+
this.writeStdout(' ],');
|
|
484
|
+
this.writeStdout(' "plugins": {');
|
|
485
|
+
this.writeStdout(' "playwright": {');
|
|
486
|
+
this.writeStdout(' "cliSessionScene": "dev-host-headed"');
|
|
487
|
+
this.writeStdout(' }');
|
|
488
|
+
this.writeStdout(' }');
|
|
489
|
+
this.writeStdout('}');
|
|
490
|
+
}
|
|
491
|
+
|
|
440
492
|
randomAlnum(length = 16) {
|
|
441
493
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
442
494
|
let out = '';
|
|
@@ -1447,13 +1499,19 @@ class PlaywrightPlugin {
|
|
|
1447
1499
|
return 1;
|
|
1448
1500
|
}
|
|
1449
1501
|
|
|
1450
|
-
startDevHost(sceneName) {
|
|
1502
|
+
async startDevHost(sceneName) {
|
|
1503
|
+
this.openChromeRemoteDebuggingPage();
|
|
1451
1504
|
try {
|
|
1452
1505
|
const endpoint = this.readDevToolsActivePort();
|
|
1506
|
+
if (!(await this.portReady(endpoint.port))) {
|
|
1507
|
+
throw new Error(`DevToolsActivePort 指向 127.0.0.1:${endpoint.port},但该端口不可连接;请确认 Chrome remote debugging 已启用,或重新打开 Chrome 后再试。`);
|
|
1508
|
+
}
|
|
1453
1509
|
this.writeStdout(`[up] ${sceneName} ready via DevToolsActivePort (${endpoint.filePath}, 127.0.0.1:${endpoint.port})`);
|
|
1510
|
+
this.remindDevHostCliSessionScene();
|
|
1454
1511
|
return 0;
|
|
1455
1512
|
} catch (error) {
|
|
1456
1513
|
this.writeStderr(`[up] ${sceneName} failed: ${error.message || String(error)}`);
|
|
1514
|
+
this.remindDevHostCliSessionScene();
|
|
1457
1515
|
return 1;
|
|
1458
1516
|
}
|
|
1459
1517
|
}
|
|
@@ -1736,6 +1794,7 @@ class PlaywrightPlugin {
|
|
|
1736
1794
|
}
|
|
1737
1795
|
|
|
1738
1796
|
const scenes = this.resolveTargets('all').filter(sceneName => isMcpScene(sceneName));
|
|
1797
|
+
this.writeStdout('# 在容器中执行');
|
|
1739
1798
|
for (const sceneName of scenes) {
|
|
1740
1799
|
const url = `http://${host}:${this.scenePort(sceneName)}/mcp`;
|
|
1741
1800
|
this.writeStdout(`claude mcp add -t http -s user playwright-${sceneName} ${url}`);
|
|
@@ -1756,6 +1815,7 @@ class PlaywrightPlugin {
|
|
|
1756
1815
|
|
|
1757
1816
|
printCliAdd() {
|
|
1758
1817
|
const lines = [
|
|
1818
|
+
'# 在宿主机中执行',
|
|
1759
1819
|
'PLAYWRIGHT_CLI_INSTALL_DIR="${TMPDIR:-/tmp}/manyoyo-playwright-cli-install-$$"',
|
|
1760
1820
|
'mkdir -p "$PLAYWRIGHT_CLI_INSTALL_DIR/.playwright"',
|
|
1761
1821
|
'cd "$PLAYWRIGHT_CLI_INSTALL_DIR"',
|
|
@@ -1783,7 +1843,7 @@ class PlaywrightPlugin {
|
|
|
1783
1843
|
const def = SCENE_DEFS[sceneName];
|
|
1784
1844
|
if (isDevScene(sceneName)) {
|
|
1785
1845
|
if (action === 'up') {
|
|
1786
|
-
return this.startDevHost(sceneName);
|
|
1846
|
+
return await this.startDevHost(sceneName);
|
|
1787
1847
|
}
|
|
1788
1848
|
if (action === 'down') {
|
|
1789
1849
|
return this.stopDevHost(sceneName);
|