@jackwener/opencli 0.9.6 → 1.0.0
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/.github/ISSUE_TEMPLATE/bug_report.yml +83 -0
- package/.github/ISSUE_TEMPLATE/config.yml +8 -0
- package/.github/ISSUE_TEMPLATE/feature_request.yml +42 -0
- package/.github/ISSUE_TEMPLATE/new_site_adapter.yml +57 -0
- package/.github/dependabot.yml +27 -0
- package/.github/pull_request_template.md +24 -0
- package/.github/workflows/ci.yml +14 -8
- package/.github/workflows/e2e-headed.yml +6 -2
- package/.github/workflows/pkg-pr-new.yml +2 -2
- package/.github/workflows/release-please.yml +25 -0
- package/.github/workflows/release.yml +2 -2
- package/.github/workflows/security.yml +36 -0
- package/CDP.md +1 -1
- package/CDP.zh-CN.md +1 -1
- package/CLI-ELECTRON.md +89 -36
- package/CLI-EXPLORER.md +4 -4
- package/CONTRIBUTING.md +167 -0
- package/README.md +113 -89
- package/README.zh-CN.md +114 -91
- package/SKILL.md +10 -8
- package/TESTING.md +7 -7
- package/dist/browser/daemon-client.d.ts +37 -0
- package/dist/browser/daemon-client.js +82 -0
- package/dist/browser/discover.d.ts +11 -34
- package/dist/browser/discover.js +15 -190
- package/dist/browser/errors.d.ts +6 -20
- package/dist/browser/errors.js +24 -63
- package/dist/browser/index.d.ts +2 -11
- package/dist/browser/index.js +5 -11
- package/dist/browser/mcp.d.ts +9 -18
- package/dist/browser/mcp.js +70 -284
- package/dist/browser/page.d.ts +28 -6
- package/dist/browser/page.js +210 -85
- package/dist/browser.test.js +4 -202
- package/dist/build-manifest.d.ts +26 -0
- package/dist/build-manifest.js +132 -60
- package/dist/build-manifest.test.d.ts +1 -0
- package/dist/build-manifest.test.js +26 -0
- package/dist/cli-manifest.json +1582 -29
- package/dist/clis/bilibili/download.d.ts +10 -0
- package/dist/clis/bilibili/download.js +135 -0
- package/dist/clis/chatwise/ask.d.ts +1 -0
- package/dist/clis/chatwise/ask.js +76 -0
- package/dist/clis/chatwise/export.d.ts +1 -0
- package/dist/clis/chatwise/export.js +46 -0
- package/dist/clis/chatwise/history.d.ts +1 -0
- package/dist/clis/chatwise/history.js +43 -0
- package/dist/clis/chatwise/model.d.ts +1 -0
- package/dist/clis/chatwise/model.js +81 -0
- package/dist/clis/chatwise/new.d.ts +1 -0
- package/dist/clis/chatwise/new.js +18 -0
- package/dist/clis/chatwise/read.d.ts +1 -0
- package/dist/clis/chatwise/read.js +39 -0
- package/dist/clis/chatwise/screenshot.d.ts +1 -0
- package/dist/clis/chatwise/screenshot.js +27 -0
- package/dist/clis/chatwise/send.d.ts +1 -0
- package/dist/clis/chatwise/send.js +45 -0
- package/dist/clis/chatwise/status.d.ts +1 -0
- package/dist/clis/chatwise/status.js +22 -0
- package/dist/clis/discord-app/channels.d.ts +1 -0
- package/dist/clis/discord-app/channels.js +45 -0
- package/dist/clis/discord-app/members.d.ts +1 -0
- package/dist/clis/discord-app/members.js +38 -0
- package/dist/clis/discord-app/read.d.ts +1 -0
- package/dist/clis/discord-app/read.js +45 -0
- package/dist/clis/discord-app/search.d.ts +1 -0
- package/dist/clis/discord-app/search.js +56 -0
- package/dist/clis/discord-app/send.d.ts +1 -0
- package/dist/clis/discord-app/send.js +27 -0
- package/dist/clis/discord-app/servers.d.ts +1 -0
- package/dist/clis/discord-app/servers.js +36 -0
- package/dist/clis/discord-app/status.d.ts +1 -0
- package/dist/clis/discord-app/status.js +16 -0
- package/dist/clis/feishu/new.d.ts +1 -0
- package/dist/clis/feishu/new.js +27 -0
- package/dist/clis/feishu/read.d.ts +1 -0
- package/dist/clis/feishu/read.js +40 -0
- package/dist/clis/feishu/search.d.ts +1 -0
- package/dist/clis/feishu/search.js +30 -0
- package/dist/clis/feishu/send.d.ts +1 -0
- package/dist/clis/feishu/send.js +39 -0
- package/dist/clis/feishu/status.d.ts +1 -0
- package/dist/clis/feishu/status.js +28 -0
- package/dist/clis/grok/ask.d.ts +1 -0
- package/dist/clis/grok/ask.js +82 -0
- package/dist/clis/grok/debug.d.ts +1 -0
- package/dist/clis/grok/debug.js +45 -0
- package/dist/clis/jimeng/generate.yaml +84 -0
- package/dist/clis/jimeng/history.yaml +47 -0
- package/dist/clis/linux-do/categories.yaml +41 -0
- package/dist/clis/linux-do/category.yaml +49 -0
- package/dist/clis/linux-do/hot.yaml +50 -0
- package/dist/clis/linux-do/latest.yaml +40 -0
- package/dist/clis/linux-do/search.yaml +45 -0
- package/dist/clis/linux-do/topic.yaml +38 -0
- package/dist/clis/neteasemusic/like.d.ts +1 -0
- package/dist/clis/neteasemusic/like.js +25 -0
- package/dist/clis/neteasemusic/lyrics.d.ts +1 -0
- package/dist/clis/neteasemusic/lyrics.js +47 -0
- package/dist/clis/neteasemusic/next.d.ts +1 -0
- package/dist/clis/neteasemusic/next.js +26 -0
- package/dist/clis/neteasemusic/play.d.ts +1 -0
- package/dist/clis/neteasemusic/play.js +26 -0
- package/dist/clis/neteasemusic/playing.d.ts +1 -0
- package/dist/clis/neteasemusic/playing.js +59 -0
- package/dist/clis/neteasemusic/playlist.d.ts +1 -0
- package/dist/clis/neteasemusic/playlist.js +46 -0
- package/dist/clis/neteasemusic/prev.d.ts +1 -0
- package/dist/clis/neteasemusic/prev.js +25 -0
- package/dist/clis/neteasemusic/search.d.ts +1 -0
- package/dist/clis/neteasemusic/search.js +52 -0
- package/dist/clis/neteasemusic/status.d.ts +1 -0
- package/dist/clis/neteasemusic/status.js +16 -0
- package/dist/clis/neteasemusic/volume.d.ts +1 -0
- package/dist/clis/neteasemusic/volume.js +54 -0
- package/dist/clis/notion/export.d.ts +1 -0
- package/dist/clis/notion/export.js +31 -0
- package/dist/clis/notion/favorites.d.ts +1 -0
- package/dist/clis/notion/favorites.js +84 -0
- package/dist/clis/notion/new.d.ts +1 -0
- package/dist/clis/notion/new.js +34 -0
- package/dist/clis/notion/read.d.ts +1 -0
- package/dist/clis/notion/read.js +30 -0
- package/dist/clis/notion/search.d.ts +1 -0
- package/dist/clis/notion/search.js +46 -0
- package/dist/clis/notion/sidebar.d.ts +1 -0
- package/dist/clis/notion/sidebar.js +41 -0
- package/dist/clis/notion/status.d.ts +1 -0
- package/dist/clis/notion/status.js +16 -0
- package/dist/clis/notion/write.d.ts +1 -0
- package/dist/clis/notion/write.js +40 -0
- package/dist/clis/twitter/download.d.ts +8 -0
- package/dist/clis/twitter/download.js +204 -0
- package/dist/clis/wechat/chats.d.ts +1 -0
- package/dist/clis/wechat/chats.js +28 -0
- package/dist/clis/wechat/contacts.d.ts +1 -0
- package/dist/clis/wechat/contacts.js +28 -0
- package/dist/clis/wechat/read.d.ts +1 -0
- package/dist/clis/wechat/read.js +58 -0
- package/dist/clis/wechat/search.d.ts +1 -0
- package/dist/clis/wechat/search.js +31 -0
- package/dist/clis/wechat/send.d.ts +1 -0
- package/dist/clis/wechat/send.js +42 -0
- package/dist/clis/wechat/status.d.ts +1 -0
- package/dist/clis/wechat/status.js +29 -0
- package/dist/clis/xiaohongshu/creator-note-detail.d.ts +10 -0
- package/dist/clis/xiaohongshu/creator-note-detail.js +88 -0
- package/dist/clis/xiaohongshu/creator-notes.d.ts +11 -0
- package/dist/clis/xiaohongshu/creator-notes.js +109 -0
- package/dist/clis/xiaohongshu/creator-profile.d.ts +10 -0
- package/dist/clis/xiaohongshu/creator-profile.js +54 -0
- package/dist/clis/xiaohongshu/creator-stats.d.ts +10 -0
- package/dist/clis/xiaohongshu/creator-stats.js +74 -0
- package/dist/clis/xiaohongshu/download.d.ts +7 -0
- package/dist/clis/xiaohongshu/download.js +155 -0
- package/dist/clis/xiaohongshu/search.js +1 -1
- package/dist/clis/xiaohongshu/user-helpers.d.ts +15 -0
- package/dist/clis/xiaohongshu/user-helpers.js +67 -0
- package/dist/clis/xiaohongshu/user-helpers.test.d.ts +1 -0
- package/dist/clis/xiaohongshu/user-helpers.test.js +81 -0
- package/dist/clis/xiaohongshu/user.js +46 -29
- package/dist/clis/zhihu/download.d.ts +11 -0
- package/dist/clis/zhihu/download.js +186 -0
- package/dist/clis/zhihu/download.test.d.ts +1 -0
- package/dist/clis/zhihu/download.test.js +10 -0
- package/dist/daemon.d.ts +13 -0
- package/dist/daemon.js +187 -0
- package/dist/doctor.d.ts +27 -61
- package/dist/doctor.js +70 -601
- package/dist/doctor.test.js +30 -170
- package/dist/download/index.d.ts +79 -0
- package/dist/download/index.js +325 -0
- package/dist/download/progress.d.ts +36 -0
- package/dist/download/progress.js +111 -0
- package/dist/engine.test.js +15 -0
- package/dist/main.js +22 -28
- package/dist/pipeline/executor.test.js +1 -0
- package/dist/pipeline/registry.js +2 -0
- package/dist/pipeline/steps/browser.js +2 -2
- package/dist/pipeline/steps/download.d.ts +34 -0
- package/dist/pipeline/steps/download.js +251 -0
- package/dist/pipeline/steps/intercept.js +1 -2
- package/dist/pipeline/template.js +28 -0
- package/dist/setup.d.ts +6 -0
- package/dist/setup.js +46 -160
- package/dist/types.d.ts +6 -0
- package/extension/icons/icon-128.png +0 -0
- package/extension/icons/icon-16.png +0 -0
- package/extension/icons/icon-32.png +0 -0
- package/extension/icons/icon-48.png +0 -0
- package/extension/manifest.json +31 -0
- package/extension/package.json +16 -0
- package/extension/src/background.ts +293 -0
- package/extension/src/cdp.ts +125 -0
- package/extension/src/protocol.ts +57 -0
- package/extension/store-assets/screenshot-1280x800.png +0 -0
- package/extension/tsconfig.json +15 -0
- package/extension/vite.config.ts +18 -0
- package/package.json +8 -7
- package/scripts/test-site.mjs +70 -0
- package/src/browser/daemon-client.ts +113 -0
- package/src/browser/discover.ts +18 -216
- package/src/browser/errors.ts +30 -100
- package/src/browser/index.ts +6 -12
- package/src/browser/mcp.ts +78 -278
- package/src/browser/page.ts +222 -88
- package/src/browser.test.ts +3 -210
- package/src/build-manifest.test.ts +28 -0
- package/src/build-manifest.ts +147 -57
- package/src/clis/bilibili/download.ts +161 -0
- package/src/clis/chatgpt/README.md +1 -1
- package/src/clis/chatgpt/README.zh-CN.md +1 -1
- package/src/clis/chatwise/README.md +38 -0
- package/src/clis/chatwise/README.zh-CN.md +38 -0
- package/src/clis/chatwise/ask.ts +87 -0
- package/src/clis/chatwise/export.ts +51 -0
- package/src/clis/chatwise/history.ts +47 -0
- package/src/clis/chatwise/model.ts +87 -0
- package/src/clis/chatwise/new.ts +21 -0
- package/src/clis/chatwise/read.ts +42 -0
- package/src/clis/chatwise/screenshot.ts +33 -0
- package/src/clis/chatwise/send.ts +50 -0
- package/src/clis/chatwise/status.ts +25 -0
- package/src/clis/discord-app/README.md +28 -0
- package/src/clis/discord-app/README.zh-CN.md +28 -0
- package/src/clis/discord-app/channels.ts +48 -0
- package/src/clis/discord-app/members.ts +41 -0
- package/src/clis/discord-app/read.ts +49 -0
- package/src/clis/discord-app/search.ts +64 -0
- package/src/clis/discord-app/send.ts +32 -0
- package/src/clis/discord-app/servers.ts +39 -0
- package/src/clis/discord-app/status.ts +18 -0
- package/src/clis/feishu/README.md +20 -0
- package/src/clis/feishu/README.zh-CN.md +20 -0
- package/src/clis/feishu/new.ts +32 -0
- package/src/clis/feishu/read.ts +48 -0
- package/src/clis/feishu/search.ts +35 -0
- package/src/clis/feishu/send.ts +46 -0
- package/src/clis/feishu/status.ts +34 -0
- package/src/clis/grok/ask.ts +90 -0
- package/src/clis/grok/debug.ts +49 -0
- package/src/clis/jimeng/generate.yaml +84 -0
- package/src/clis/jimeng/history.yaml +47 -0
- package/src/clis/linux-do/categories.yaml +41 -0
- package/src/clis/linux-do/category.yaml +49 -0
- package/src/clis/linux-do/hot.yaml +50 -0
- package/src/clis/linux-do/latest.yaml +40 -0
- package/src/clis/linux-do/search.yaml +45 -0
- package/src/clis/linux-do/topic.yaml +38 -0
- package/src/clis/neteasemusic/README.md +31 -0
- package/src/clis/neteasemusic/README.zh-CN.md +31 -0
- package/src/clis/neteasemusic/like.ts +28 -0
- package/src/clis/neteasemusic/lyrics.ts +53 -0
- package/src/clis/neteasemusic/next.ts +30 -0
- package/src/clis/neteasemusic/play.ts +30 -0
- package/src/clis/neteasemusic/playing.ts +62 -0
- package/src/clis/neteasemusic/playlist.ts +51 -0
- package/src/clis/neteasemusic/prev.ts +29 -0
- package/src/clis/neteasemusic/search.ts +58 -0
- package/src/clis/neteasemusic/status.ts +18 -0
- package/src/clis/neteasemusic/volume.ts +61 -0
- package/src/clis/notion/README.md +29 -0
- package/src/clis/notion/README.zh-CN.md +29 -0
- package/src/clis/notion/export.ts +36 -0
- package/src/clis/notion/favorites.ts +87 -0
- package/src/clis/notion/new.ts +39 -0
- package/src/clis/notion/read.ts +33 -0
- package/src/clis/notion/search.ts +54 -0
- package/src/clis/notion/sidebar.ts +44 -0
- package/src/clis/notion/status.ts +18 -0
- package/src/clis/notion/write.ts +45 -0
- package/src/clis/twitter/download.ts +227 -0
- package/src/clis/wechat/README.md +28 -0
- package/src/clis/wechat/README.zh-CN.md +28 -0
- package/src/clis/wechat/chats.ts +33 -0
- package/src/clis/wechat/contacts.ts +33 -0
- package/src/clis/wechat/read.ts +72 -0
- package/src/clis/wechat/search.ts +36 -0
- package/src/clis/wechat/send.ts +49 -0
- package/src/clis/wechat/status.ts +35 -0
- package/src/clis/xiaohongshu/creator-note-detail.ts +95 -0
- package/src/clis/xiaohongshu/creator-notes.ts +116 -0
- package/src/clis/xiaohongshu/creator-profile.ts +60 -0
- package/src/clis/xiaohongshu/creator-stats.ts +81 -0
- package/src/clis/xiaohongshu/download.ts +173 -0
- package/src/clis/xiaohongshu/search.ts +1 -1
- package/src/clis/xiaohongshu/user-helpers.test.ts +106 -0
- package/src/clis/xiaohongshu/user-helpers.ts +85 -0
- package/src/clis/xiaohongshu/user.ts +52 -32
- package/src/clis/zhihu/download.test.ts +12 -0
- package/src/clis/zhihu/download.ts +223 -0
- package/src/daemon.ts +217 -0
- package/src/doctor.test.ts +32 -193
- package/src/doctor.ts +74 -668
- package/src/download/index.ts +395 -0
- package/src/download/progress.ts +125 -0
- package/src/engine.test.ts +17 -0
- package/src/main.ts +18 -26
- package/src/pipeline/executor.test.ts +1 -0
- package/src/pipeline/registry.ts +2 -0
- package/src/pipeline/steps/browser.ts +2 -2
- package/src/pipeline/steps/download.ts +310 -0
- package/src/pipeline/steps/intercept.ts +1 -2
- package/src/pipeline/template.ts +26 -0
- package/src/setup.ts +47 -183
- package/src/types.ts +1 -0
- package/tests/e2e/browser-auth.test.ts +25 -0
package/dist/browser/page.js
CHANGED
|
@@ -1,68 +1,70 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Page abstraction
|
|
2
|
+
* Page abstraction — implements IPage by sending commands to the daemon.
|
|
3
|
+
*
|
|
4
|
+
* All browser operations are ultimately 'exec' (JS evaluation via CDP)
|
|
5
|
+
* plus a few native Chrome Extension APIs (tabs, cookies, navigate).
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: After goto(), we remember the tabId returned by the navigate
|
|
8
|
+
* action and pass it to all subsequent commands. This avoids the issue
|
|
9
|
+
* where resolveTabId() in the extension picks a chrome:// or
|
|
10
|
+
* chrome-extension:// tab that can't be debugged.
|
|
3
11
|
*/
|
|
4
12
|
import { formatSnapshot } from '../snapshotFormatter.js';
|
|
5
|
-
import {
|
|
6
|
-
import { generateInterceptorJs, generateReadInterceptedJs } from '../interceptor.js';
|
|
7
|
-
import { BrowserConnectError } from '../errors.js';
|
|
13
|
+
import { sendCommand } from './daemon-client.js';
|
|
8
14
|
/**
|
|
9
|
-
* Page
|
|
15
|
+
* Page — implements IPage by talking to the daemon via HTTP.
|
|
10
16
|
*/
|
|
11
17
|
export class Page {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const resp = await this._request(method, params);
|
|
18
|
-
if (resp.error)
|
|
19
|
-
throw new Error(`page.${method}: ${resp.error.message ?? JSON.stringify(resp.error)}`);
|
|
20
|
-
// Extract text content from MCP result
|
|
21
|
-
const result = resp.result;
|
|
22
|
-
if (result?.isError) {
|
|
23
|
-
const errorText = result.content?.find((c) => c.type === 'text')?.text || 'Unknown MCP Error';
|
|
24
|
-
throw new BrowserConnectError(errorText, 'Please check if the browser is running or if the Playwright MCP / CDP connection is configured correctly.');
|
|
25
|
-
}
|
|
26
|
-
if (result?.content) {
|
|
27
|
-
const textParts = result.content.filter((c) => c.type === 'text');
|
|
28
|
-
if (textParts.length >= 1) {
|
|
29
|
-
let text = textParts[textParts.length - 1].text; // Usually the main output is in the last text block
|
|
30
|
-
// Some versions of the MCP return error text without the `isError` boolean flag
|
|
31
|
-
if (typeof text === 'string' && text.trim().startsWith('### Error')) {
|
|
32
|
-
throw new BrowserConnectError(text.trim(), 'Please check if the browser is running or if the Playwright MCP / CDP connection is configured correctly.');
|
|
33
|
-
}
|
|
34
|
-
// MCP browser_evaluate returns: "[JSON]\n### Ran Playwright code\n```js\n...\n```"
|
|
35
|
-
// Strip the "### Ran Playwright code" suffix to get clean JSON
|
|
36
|
-
const codeMarker = text.indexOf('### Ran Playwright code');
|
|
37
|
-
if (codeMarker !== -1) {
|
|
38
|
-
text = text.slice(0, codeMarker).trim();
|
|
39
|
-
}
|
|
40
|
-
// Also handle "### Result\n[JSON]" format (some MCP versions)
|
|
41
|
-
const resultMarker = text.indexOf('### Result\n');
|
|
42
|
-
if (resultMarker !== -1) {
|
|
43
|
-
text = text.slice(resultMarker + '### Result\n'.length).trim();
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
return JSON.parse(text);
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return text;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return result;
|
|
18
|
+
/** Active tab ID, set after navigate and used in all subsequent commands */
|
|
19
|
+
_tabId;
|
|
20
|
+
/** Helper: spread tabId into command params if we have one */
|
|
21
|
+
_tabOpt() {
|
|
22
|
+
return this._tabId !== undefined ? { tabId: this._tabId } : {};
|
|
54
23
|
}
|
|
55
|
-
// --- High-level methods ---
|
|
56
24
|
async goto(url) {
|
|
57
|
-
|
|
25
|
+
const result = await sendCommand('navigate', {
|
|
26
|
+
url,
|
|
27
|
+
...this._tabOpt(),
|
|
28
|
+
});
|
|
29
|
+
// Remember the tabId for subsequent exec calls
|
|
30
|
+
if (result?.tabId) {
|
|
31
|
+
this._tabId = result.tabId;
|
|
32
|
+
}
|
|
58
33
|
}
|
|
59
34
|
async evaluate(js) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return this.call('tools/call', { name: 'browser_evaluate', arguments: { function: normalized } });
|
|
35
|
+
const code = wrapForEval(js);
|
|
36
|
+
return sendCommand('exec', { code, ...this._tabOpt() });
|
|
63
37
|
}
|
|
64
38
|
async snapshot(opts = {}) {
|
|
65
|
-
const
|
|
39
|
+
const maxDepth = Math.max(1, Math.min(Number(opts.maxDepth) || 50, 200));
|
|
40
|
+
const code = `
|
|
41
|
+
(async () => {
|
|
42
|
+
function buildTree(node, depth) {
|
|
43
|
+
if (depth > ${maxDepth}) return '';
|
|
44
|
+
const role = node.getAttribute?.('role') || node.tagName?.toLowerCase() || 'generic';
|
|
45
|
+
const name = node.getAttribute?.('aria-label') || node.getAttribute?.('alt') || node.textContent?.trim().slice(0, 80) || '';
|
|
46
|
+
const isInteractive = ['a', 'button', 'input', 'select', 'textarea'].includes(node.tagName?.toLowerCase()) || node.getAttribute?.('tabindex') != null;
|
|
47
|
+
|
|
48
|
+
${opts.interactive ? 'if (!isInteractive && !node.children?.length) return "";' : ''}
|
|
49
|
+
|
|
50
|
+
let indent = ' '.repeat(depth);
|
|
51
|
+
let line = indent + role;
|
|
52
|
+
if (name) line += ' "' + name.replace(/"/g, '\\\\"') + '"';
|
|
53
|
+
if (node.tagName?.toLowerCase() === 'a' && node.href) line += ' [' + node.href + ']';
|
|
54
|
+
if (node.tagName?.toLowerCase() === 'input') line += ' [' + (node.type || 'text') + ']';
|
|
55
|
+
|
|
56
|
+
let result = line + '\\n';
|
|
57
|
+
if (node.children) {
|
|
58
|
+
for (const child of node.children) {
|
|
59
|
+
result += buildTree(child, depth + 1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
return buildTree(document.body, 0);
|
|
65
|
+
})()
|
|
66
|
+
`;
|
|
67
|
+
const raw = await sendCommand('exec', { code, ...this._tabOpt() });
|
|
66
68
|
if (opts.raw)
|
|
67
69
|
return raw;
|
|
68
70
|
if (typeof raw === 'string')
|
|
@@ -70,52 +72,147 @@ export class Page {
|
|
|
70
72
|
return raw;
|
|
71
73
|
}
|
|
72
74
|
async click(ref) {
|
|
73
|
-
|
|
75
|
+
const safeRef = JSON.stringify(ref);
|
|
76
|
+
const code = `
|
|
77
|
+
(() => {
|
|
78
|
+
const ref = ${safeRef};
|
|
79
|
+
const el = document.querySelector('[data-ref="' + ref + '"]')
|
|
80
|
+
|| document.querySelectorAll('a, button, input, [role="button"], [tabindex]')[parseInt(ref, 10) || 0];
|
|
81
|
+
if (!el) throw new Error('Element not found: ' + ref);
|
|
82
|
+
el.scrollIntoView({ behavior: 'instant', block: 'center' });
|
|
83
|
+
el.click();
|
|
84
|
+
return 'clicked';
|
|
85
|
+
})()
|
|
86
|
+
`;
|
|
87
|
+
await sendCommand('exec', { code, ...this._tabOpt() });
|
|
74
88
|
}
|
|
75
89
|
async typeText(ref, text) {
|
|
76
|
-
|
|
90
|
+
const safeRef = JSON.stringify(ref);
|
|
91
|
+
const safeText = JSON.stringify(text);
|
|
92
|
+
const code = `
|
|
93
|
+
(() => {
|
|
94
|
+
const ref = ${safeRef};
|
|
95
|
+
const el = document.querySelector('[data-ref="' + ref + '"]')
|
|
96
|
+
|| document.querySelectorAll('input, textarea, [contenteditable]')[parseInt(ref, 10) || 0];
|
|
97
|
+
if (!el) throw new Error('Element not found: ' + ref);
|
|
98
|
+
el.focus();
|
|
99
|
+
el.value = ${safeText};
|
|
100
|
+
el.dispatchEvent(new Event('input', { bubbles: true }));
|
|
101
|
+
el.dispatchEvent(new Event('change', { bubbles: true }));
|
|
102
|
+
return 'typed';
|
|
103
|
+
})()
|
|
104
|
+
`;
|
|
105
|
+
await sendCommand('exec', { code, ...this._tabOpt() });
|
|
77
106
|
}
|
|
78
107
|
async pressKey(key) {
|
|
79
|
-
|
|
108
|
+
const code = `
|
|
109
|
+
(() => {
|
|
110
|
+
const el = document.activeElement || document.body;
|
|
111
|
+
el.dispatchEvent(new KeyboardEvent('keydown', { key: ${JSON.stringify(key)}, bubbles: true }));
|
|
112
|
+
el.dispatchEvent(new KeyboardEvent('keyup', { key: ${JSON.stringify(key)}, bubbles: true }));
|
|
113
|
+
return 'pressed';
|
|
114
|
+
})()
|
|
115
|
+
`;
|
|
116
|
+
await sendCommand('exec', { code, ...this._tabOpt() });
|
|
80
117
|
}
|
|
81
118
|
async wait(options) {
|
|
82
119
|
if (typeof options === 'number') {
|
|
83
|
-
await
|
|
120
|
+
await new Promise(resolve => setTimeout(resolve, options * 1000));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (options.time) {
|
|
124
|
+
await new Promise(resolve => setTimeout(resolve, options.time * 1000));
|
|
125
|
+
return;
|
|
84
126
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
127
|
+
if (options.text) {
|
|
128
|
+
const timeout = (options.timeout ?? 30) * 1000;
|
|
129
|
+
const code = `
|
|
130
|
+
new Promise((resolve, reject) => {
|
|
131
|
+
const deadline = Date.now() + ${timeout};
|
|
132
|
+
const check = () => {
|
|
133
|
+
if (document.body.innerText.includes(${JSON.stringify(options.text)})) return resolve('found');
|
|
134
|
+
if (Date.now() > deadline) return reject(new Error('Text not found: ' + ${JSON.stringify(options.text)}));
|
|
135
|
+
setTimeout(check, 200);
|
|
136
|
+
};
|
|
137
|
+
check();
|
|
138
|
+
})
|
|
139
|
+
`;
|
|
140
|
+
await sendCommand('exec', { code, ...this._tabOpt() });
|
|
88
141
|
}
|
|
89
142
|
}
|
|
90
143
|
async tabs() {
|
|
91
|
-
return
|
|
144
|
+
return sendCommand('tabs', { op: 'list' });
|
|
92
145
|
}
|
|
93
146
|
async closeTab(index) {
|
|
94
|
-
await
|
|
147
|
+
await sendCommand('tabs', { op: 'close', ...(index !== undefined ? { index } : {}) });
|
|
95
148
|
}
|
|
96
149
|
async newTab() {
|
|
97
|
-
await
|
|
150
|
+
await sendCommand('tabs', { op: 'new' });
|
|
98
151
|
}
|
|
99
152
|
async selectTab(index) {
|
|
100
|
-
await
|
|
153
|
+
await sendCommand('tabs', { op: 'select', index });
|
|
101
154
|
}
|
|
102
155
|
async networkRequests(includeStatic = false) {
|
|
103
|
-
|
|
156
|
+
const code = `
|
|
157
|
+
(() => {
|
|
158
|
+
const entries = performance.getEntriesByType('resource');
|
|
159
|
+
return entries
|
|
160
|
+
${includeStatic ? '' : '.filter(e => !["img", "font", "css", "script"].some(t => e.initiatorType === t))'}
|
|
161
|
+
.map(e => ({
|
|
162
|
+
url: e.name,
|
|
163
|
+
type: e.initiatorType,
|
|
164
|
+
duration: Math.round(e.duration),
|
|
165
|
+
size: e.transferSize || 0,
|
|
166
|
+
}));
|
|
167
|
+
})()
|
|
168
|
+
`;
|
|
169
|
+
return sendCommand('exec', { code, ...this._tabOpt() });
|
|
104
170
|
}
|
|
105
171
|
async consoleMessages(level = 'info') {
|
|
106
|
-
|
|
172
|
+
// Console messages can't be retrospectively read via CDP Runtime.evaluate.
|
|
173
|
+
// Would need Runtime.consoleAPICalled event listener, which is not yet implemented.
|
|
174
|
+
if (process.env.OPENCLI_VERBOSE) {
|
|
175
|
+
console.error('[page] consoleMessages() not supported in lightweight mode — returning empty');
|
|
176
|
+
}
|
|
177
|
+
return [];
|
|
107
178
|
}
|
|
108
|
-
|
|
109
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Capture a screenshot via CDP Page.captureScreenshot.
|
|
181
|
+
* @param options.format - 'png' (default) or 'jpeg'
|
|
182
|
+
* @param options.quality - JPEG quality 0-100
|
|
183
|
+
* @param options.fullPage - capture full scrollable page
|
|
184
|
+
* @param options.path - save to file path (returns base64 if omitted)
|
|
185
|
+
*/
|
|
186
|
+
async screenshot(options = {}) {
|
|
187
|
+
const base64 = await sendCommand('screenshot', {
|
|
188
|
+
format: options.format,
|
|
189
|
+
quality: options.quality,
|
|
190
|
+
fullPage: options.fullPage,
|
|
191
|
+
...this._tabOpt(),
|
|
192
|
+
});
|
|
193
|
+
if (options.path) {
|
|
194
|
+
const fs = await import('node:fs');
|
|
195
|
+
const path = await import('node:path');
|
|
196
|
+
const dir = path.dirname(options.path);
|
|
197
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
198
|
+
fs.writeFileSync(options.path, Buffer.from(base64, 'base64'));
|
|
199
|
+
}
|
|
200
|
+
return base64;
|
|
201
|
+
}
|
|
202
|
+
async scroll(direction = 'down', amount = 500) {
|
|
203
|
+
const dx = direction === 'left' ? -amount : direction === 'right' ? amount : 0;
|
|
204
|
+
const dy = direction === 'up' ? -amount : direction === 'down' ? amount : 0;
|
|
205
|
+
await sendCommand('exec', {
|
|
206
|
+
code: `window.scrollBy(${dx}, ${dy})`,
|
|
207
|
+
...this._tabOpt(),
|
|
208
|
+
});
|
|
110
209
|
}
|
|
111
210
|
async autoScroll(options = {}) {
|
|
112
211
|
const times = options.times ?? 3;
|
|
113
212
|
const delayMs = options.delayMs ?? 2000;
|
|
114
|
-
const
|
|
115
|
-
async () => {
|
|
116
|
-
|
|
117
|
-
const maxWaitMs = ${delayMs};
|
|
118
|
-
for (let i = 0; i < maxTimes; i++) {
|
|
213
|
+
const code = `
|
|
214
|
+
(async () => {
|
|
215
|
+
for (let i = 0; i < ${times}; i++) {
|
|
119
216
|
const lastHeight = document.body.scrollHeight;
|
|
120
217
|
window.scrollTo(0, lastHeight);
|
|
121
218
|
await new Promise(resolve => {
|
|
@@ -124,28 +221,56 @@ export class Page {
|
|
|
124
221
|
if (document.body.scrollHeight > lastHeight) {
|
|
125
222
|
clearTimeout(timeoutId);
|
|
126
223
|
observer.disconnect();
|
|
127
|
-
setTimeout(resolve, 100);
|
|
224
|
+
setTimeout(resolve, 100);
|
|
128
225
|
}
|
|
129
226
|
});
|
|
130
227
|
observer.observe(document.body, { childList: true, subtree: true });
|
|
131
|
-
timeoutId = setTimeout(() => {
|
|
132
|
-
observer.disconnect();
|
|
133
|
-
resolve(null);
|
|
134
|
-
}, maxWaitMs);
|
|
228
|
+
timeoutId = setTimeout(() => { observer.disconnect(); resolve(null); }, ${delayMs});
|
|
135
229
|
});
|
|
136
230
|
}
|
|
137
|
-
}
|
|
231
|
+
})()
|
|
138
232
|
`;
|
|
139
|
-
await this.
|
|
233
|
+
await sendCommand('exec', { code, ...this._tabOpt() });
|
|
140
234
|
}
|
|
141
235
|
async installInterceptor(pattern) {
|
|
142
|
-
await
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
236
|
+
const { generateInterceptorJs } = await import('../interceptor.js');
|
|
237
|
+
await sendCommand('exec', {
|
|
238
|
+
code: generateInterceptorJs(JSON.stringify(pattern), {
|
|
239
|
+
arrayName: '__opencli_xhr',
|
|
240
|
+
patchGuard: '__opencli_interceptor_patched',
|
|
241
|
+
}),
|
|
242
|
+
...this._tabOpt(),
|
|
243
|
+
});
|
|
146
244
|
}
|
|
147
245
|
async getInterceptedRequests() {
|
|
148
|
-
const
|
|
246
|
+
const { generateReadInterceptedJs } = await import('../interceptor.js');
|
|
247
|
+
const result = await sendCommand('exec', {
|
|
248
|
+
code: generateReadInterceptedJs('__opencli_xhr'),
|
|
249
|
+
...this._tabOpt(),
|
|
250
|
+
});
|
|
149
251
|
return result || [];
|
|
150
252
|
}
|
|
151
253
|
}
|
|
254
|
+
// ─── Helpers ─────────────────────────────────────────────────────────
|
|
255
|
+
/**
|
|
256
|
+
* Wrap JS code for CDP Runtime.evaluate:
|
|
257
|
+
* - Already an IIFE `(...)()` → send as-is
|
|
258
|
+
* - Arrow/function literal → wrap as IIFE `(code)()`
|
|
259
|
+
* - `new Promise(...)` or raw expression → send as-is (expression)
|
|
260
|
+
*/
|
|
261
|
+
function wrapForEval(js) {
|
|
262
|
+
const code = js.trim();
|
|
263
|
+
if (!code)
|
|
264
|
+
return 'undefined';
|
|
265
|
+
// Already an IIFE: `(async () => { ... })()` or `(function() {...})()`
|
|
266
|
+
if (/^\([\s\S]*\)\s*\(.*\)\s*$/.test(code))
|
|
267
|
+
return code;
|
|
268
|
+
// Arrow function: `() => ...` or `async () => ...`
|
|
269
|
+
if (/^(async\s+)?(\([^)]*\)|[A-Za-z_]\w*)\s*=>/.test(code))
|
|
270
|
+
return `(${code})()`;
|
|
271
|
+
// Function declaration: `function ...` or `async function ...`
|
|
272
|
+
if (/^(async\s+)?function[\s(]/.test(code))
|
|
273
|
+
return `(${code})()`;
|
|
274
|
+
// Everything else: bare expression, `new Promise(...)`, etc. → evaluate directly
|
|
275
|
+
return code;
|
|
276
|
+
}
|
package/dist/browser.test.js
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
2
|
import { PlaywrightMCP, __test__ } from './browser/index.js';
|
|
3
|
-
afterEach(() => {
|
|
4
|
-
__test__.resetMcpServerPathCache();
|
|
5
|
-
__test__.setMcpDiscoveryTestHooks();
|
|
6
|
-
delete process.env.OPENCLI_MCP_SERVER_PATH;
|
|
7
|
-
});
|
|
8
3
|
describe('browser helpers', () => {
|
|
9
|
-
it('creates JSON-RPC requests with unique ids', () => {
|
|
10
|
-
const first = __test__.createJsonRpcRequest('tools/call', { name: 'browser_tabs' });
|
|
11
|
-
const second = __test__.createJsonRpcRequest('tools/call', { name: 'browser_snapshot' });
|
|
12
|
-
expect(second.id).toBe(first.id + 1);
|
|
13
|
-
expect(first.message).toContain(`"id":${first.id}`);
|
|
14
|
-
expect(second.message).toContain(`"id":${second.id}`);
|
|
15
|
-
});
|
|
16
4
|
it('extracts tab entries from string snapshots', () => {
|
|
17
5
|
const entries = __test__.extractTabEntries('Tab 0 https://example.com\nTab 1 Chrome Extension');
|
|
18
6
|
expect(entries).toEqual([
|
|
@@ -39,195 +27,9 @@ describe('browser helpers', () => {
|
|
|
39
27
|
it('keeps only the tail of stderr buffers', () => {
|
|
40
28
|
expect(__test__.appendLimited('12345', '67890', 8)).toBe('34567890');
|
|
41
29
|
});
|
|
42
|
-
it('builds extension MCP args in local mode (no CI)', () => {
|
|
43
|
-
const savedCI = process.env.CI;
|
|
44
|
-
delete process.env.CI;
|
|
45
|
-
try {
|
|
46
|
-
expect(__test__.buildMcpArgs({
|
|
47
|
-
mcpPath: '/tmp/cli.js',
|
|
48
|
-
executablePath: '/mnt/c/Program Files/Google/Chrome/Application/chrome.exe',
|
|
49
|
-
})).toEqual([
|
|
50
|
-
'/tmp/cli.js',
|
|
51
|
-
'--extension',
|
|
52
|
-
'--executable-path',
|
|
53
|
-
'/mnt/c/Program Files/Google/Chrome/Application/chrome.exe',
|
|
54
|
-
]);
|
|
55
|
-
expect(__test__.buildMcpArgs({
|
|
56
|
-
mcpPath: '/tmp/cli.js',
|
|
57
|
-
})).toEqual([
|
|
58
|
-
'/tmp/cli.js',
|
|
59
|
-
'--extension',
|
|
60
|
-
]);
|
|
61
|
-
}
|
|
62
|
-
finally {
|
|
63
|
-
if (savedCI !== undefined) {
|
|
64
|
-
process.env.CI = savedCI;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
delete process.env.CI;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
it('builds standalone MCP args in CI mode', () => {
|
|
72
|
-
const savedCI = process.env.CI;
|
|
73
|
-
process.env.CI = 'true';
|
|
74
|
-
try {
|
|
75
|
-
// CI mode: no --extension — browser launches in standalone headed mode
|
|
76
|
-
expect(__test__.buildMcpArgs({
|
|
77
|
-
mcpPath: '/tmp/cli.js',
|
|
78
|
-
})).toEqual([
|
|
79
|
-
'/tmp/cli.js',
|
|
80
|
-
]);
|
|
81
|
-
expect(__test__.buildMcpArgs({
|
|
82
|
-
mcpPath: '/tmp/cli.js',
|
|
83
|
-
executablePath: '/usr/bin/chromium',
|
|
84
|
-
})).toEqual([
|
|
85
|
-
'/tmp/cli.js',
|
|
86
|
-
'--executable-path',
|
|
87
|
-
'/usr/bin/chromium',
|
|
88
|
-
]);
|
|
89
|
-
}
|
|
90
|
-
finally {
|
|
91
|
-
if (savedCI !== undefined) {
|
|
92
|
-
process.env.CI = savedCI;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
delete process.env.CI;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
it('builds a direct node launch spec when a local MCP path is available', () => {
|
|
100
|
-
const savedCI = process.env.CI;
|
|
101
|
-
delete process.env.CI;
|
|
102
|
-
try {
|
|
103
|
-
expect(__test__.buildMcpLaunchSpec({
|
|
104
|
-
mcpPath: '/tmp/cli.js',
|
|
105
|
-
executablePath: '/usr/bin/google-chrome',
|
|
106
|
-
})).toEqual({
|
|
107
|
-
command: 'node',
|
|
108
|
-
args: ['/tmp/cli.js', '--extension', '--executable-path', '/usr/bin/google-chrome'],
|
|
109
|
-
usedNpxFallback: false,
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
finally {
|
|
113
|
-
if (savedCI !== undefined) {
|
|
114
|
-
process.env.CI = savedCI;
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
delete process.env.CI;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
it('falls back to npx bootstrap when no MCP path is available', () => {
|
|
122
|
-
const savedCI = process.env.CI;
|
|
123
|
-
delete process.env.CI;
|
|
124
|
-
try {
|
|
125
|
-
expect(__test__.buildMcpLaunchSpec({
|
|
126
|
-
mcpPath: null,
|
|
127
|
-
})).toEqual({
|
|
128
|
-
command: 'npx',
|
|
129
|
-
args: ['-y', '@playwright/mcp@latest', '--extension'],
|
|
130
|
-
usedNpxFallback: true,
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
finally {
|
|
134
|
-
if (savedCI !== undefined) {
|
|
135
|
-
process.env.CI = savedCI;
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
delete process.env.CI;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
30
|
it('times out slow promises', async () => {
|
|
143
31
|
await expect(__test__.withTimeoutMs(new Promise(() => { }), 10, 'timeout')).rejects.toThrow('timeout');
|
|
144
32
|
});
|
|
145
|
-
it('prefers OPENCLI_MCP_SERVER_PATH over discovered locations', () => {
|
|
146
|
-
process.env.OPENCLI_MCP_SERVER_PATH = '/env/mcp/cli.js';
|
|
147
|
-
const existsSync = vi.fn((candidate) => candidate === '/env/mcp/cli.js');
|
|
148
|
-
const execSync = vi.fn();
|
|
149
|
-
__test__.setMcpDiscoveryTestHooks({ existsSync, execSync: execSync });
|
|
150
|
-
expect(__test__.findMcpServerPath()).toBe('/env/mcp/cli.js');
|
|
151
|
-
expect(execSync).not.toHaveBeenCalled();
|
|
152
|
-
expect(existsSync).toHaveBeenCalledWith('/env/mcp/cli.js');
|
|
153
|
-
});
|
|
154
|
-
it('discovers global @playwright/mcp from the current Node runtime prefix', () => {
|
|
155
|
-
const originalExecPath = process.execPath;
|
|
156
|
-
const runtimeExecPath = '/opt/homebrew/Cellar/node/25.2.1/bin/node';
|
|
157
|
-
const runtimeGlobalMcp = '/opt/homebrew/Cellar/node/25.2.1/lib/node_modules/@playwright/mcp/cli.js';
|
|
158
|
-
Object.defineProperty(process, 'execPath', {
|
|
159
|
-
value: runtimeExecPath,
|
|
160
|
-
configurable: true,
|
|
161
|
-
});
|
|
162
|
-
const existsSync = vi.fn((candidate) => candidate === runtimeGlobalMcp);
|
|
163
|
-
const execSync = vi.fn();
|
|
164
|
-
__test__.setMcpDiscoveryTestHooks({ existsSync, execSync: execSync });
|
|
165
|
-
try {
|
|
166
|
-
expect(__test__.findMcpServerPath()).toBe(runtimeGlobalMcp);
|
|
167
|
-
expect(execSync).not.toHaveBeenCalled();
|
|
168
|
-
expect(existsSync).toHaveBeenCalledWith(runtimeGlobalMcp);
|
|
169
|
-
}
|
|
170
|
-
finally {
|
|
171
|
-
Object.defineProperty(process, 'execPath', {
|
|
172
|
-
value: originalExecPath,
|
|
173
|
-
configurable: true,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
it('falls back to npm root -g when runtime prefix lookup misses', () => {
|
|
178
|
-
const originalExecPath = process.execPath;
|
|
179
|
-
const runtimeExecPath = '/opt/homebrew/Cellar/node/25.2.1/bin/node';
|
|
180
|
-
const runtimeGlobalMcp = '/opt/homebrew/Cellar/node/25.2.1/lib/node_modules/@playwright/mcp/cli.js';
|
|
181
|
-
const npmRootGlobal = '/Users/jakevin/.nvm/versions/node/v22.14.0/lib/node_modules';
|
|
182
|
-
const npmGlobalMcp = '/Users/jakevin/.nvm/versions/node/v22.14.0/lib/node_modules/@playwright/mcp/cli.js';
|
|
183
|
-
Object.defineProperty(process, 'execPath', {
|
|
184
|
-
value: runtimeExecPath,
|
|
185
|
-
configurable: true,
|
|
186
|
-
});
|
|
187
|
-
const existsSync = vi.fn((candidate) => candidate === npmGlobalMcp);
|
|
188
|
-
const execSync = vi.fn((command) => {
|
|
189
|
-
if (String(command).includes('npm root -g'))
|
|
190
|
-
return `${npmRootGlobal}\n`;
|
|
191
|
-
throw new Error(`unexpected command: ${String(command)}`);
|
|
192
|
-
});
|
|
193
|
-
__test__.setMcpDiscoveryTestHooks({ existsSync, execSync: execSync });
|
|
194
|
-
try {
|
|
195
|
-
expect(__test__.findMcpServerPath()).toBe(npmGlobalMcp);
|
|
196
|
-
expect(execSync).toHaveBeenCalledOnce();
|
|
197
|
-
expect(existsSync).toHaveBeenCalledWith(runtimeGlobalMcp);
|
|
198
|
-
expect(existsSync).toHaveBeenCalledWith(npmGlobalMcp);
|
|
199
|
-
}
|
|
200
|
-
finally {
|
|
201
|
-
Object.defineProperty(process, 'execPath', {
|
|
202
|
-
value: originalExecPath,
|
|
203
|
-
configurable: true,
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
it('returns null when new global discovery paths are unavailable', () => {
|
|
208
|
-
const originalExecPath = process.execPath;
|
|
209
|
-
const runtimeExecPath = '/opt/homebrew/Cellar/node/25.2.1/bin/node';
|
|
210
|
-
Object.defineProperty(process, 'execPath', {
|
|
211
|
-
value: runtimeExecPath,
|
|
212
|
-
configurable: true,
|
|
213
|
-
});
|
|
214
|
-
const existsSync = vi.fn(() => false);
|
|
215
|
-
const execSync = vi.fn((command) => {
|
|
216
|
-
if (String(command).includes('npm root -g'))
|
|
217
|
-
return '/missing/global/node_modules\n';
|
|
218
|
-
throw new Error(`missing command: ${String(command)}`);
|
|
219
|
-
});
|
|
220
|
-
__test__.setMcpDiscoveryTestHooks({ existsSync, execSync: execSync });
|
|
221
|
-
try {
|
|
222
|
-
expect(__test__.findMcpServerPath()).toBeNull();
|
|
223
|
-
}
|
|
224
|
-
finally {
|
|
225
|
-
Object.defineProperty(process, 'execPath', {
|
|
226
|
-
value: originalExecPath,
|
|
227
|
-
configurable: true,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
33
|
});
|
|
232
34
|
describe('PlaywrightMCP state', () => {
|
|
233
35
|
it('transitions to closed after close()', async () => {
|
|
@@ -239,16 +41,16 @@ describe('PlaywrightMCP state', () => {
|
|
|
239
41
|
it('rejects connect() after the session has been closed', async () => {
|
|
240
42
|
const mcp = new PlaywrightMCP();
|
|
241
43
|
await mcp.close();
|
|
242
|
-
await expect(mcp.connect()).rejects.toThrow('
|
|
44
|
+
await expect(mcp.connect()).rejects.toThrow('Session is closed');
|
|
243
45
|
});
|
|
244
46
|
it('rejects connect() while already connecting', async () => {
|
|
245
47
|
const mcp = new PlaywrightMCP();
|
|
246
48
|
mcp._state = 'connecting';
|
|
247
|
-
await expect(mcp.connect()).rejects.toThrow('
|
|
49
|
+
await expect(mcp.connect()).rejects.toThrow('Already connecting');
|
|
248
50
|
});
|
|
249
51
|
it('rejects connect() while closing', async () => {
|
|
250
52
|
const mcp = new PlaywrightMCP();
|
|
251
53
|
mcp._state = 'closing';
|
|
252
|
-
await expect(mcp.connect()).rejects.toThrow('
|
|
54
|
+
await expect(mcp.connect()).rejects.toThrow('Session is closing');
|
|
253
55
|
});
|
|
254
56
|
});
|
package/dist/build-manifest.d.ts
CHANGED
|
@@ -8,4 +8,30 @@
|
|
|
8
8
|
* Usage: npx tsx src/build-manifest.ts
|
|
9
9
|
* Output: dist/cli-manifest.json
|
|
10
10
|
*/
|
|
11
|
+
interface ManifestEntry {
|
|
12
|
+
site: string;
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
domain?: string;
|
|
16
|
+
strategy: string;
|
|
17
|
+
browser: boolean;
|
|
18
|
+
args: Array<{
|
|
19
|
+
name: string;
|
|
20
|
+
type?: string;
|
|
21
|
+
default?: any;
|
|
22
|
+
required?: boolean;
|
|
23
|
+
positional?: boolean;
|
|
24
|
+
help?: string;
|
|
25
|
+
choices?: string[];
|
|
26
|
+
}>;
|
|
27
|
+
columns?: string[];
|
|
28
|
+
pipeline?: any[];
|
|
29
|
+
timeout?: number;
|
|
30
|
+
/** 'yaml' or 'ts' — determines how executeCommand loads the handler */
|
|
31
|
+
type: 'yaml' | 'ts';
|
|
32
|
+
/** Relative path from clis/ dir, e.g. 'bilibili/hot.yaml' or 'bilibili/search.js' */
|
|
33
|
+
modulePath?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare function parseTsArgsBlock(argsBlock: string): ManifestEntry['args'];
|
|
36
|
+
export declare function buildManifest(): ManifestEntry[];
|
|
11
37
|
export {};
|