@jackwener/opencli 0.4.6 → 0.5.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.
@@ -11,7 +11,7 @@ cli({
11
11
  domain: 'www.v2ex.com',
12
12
  strategy: Strategy.COOKIE,
13
13
  browser: true,
14
- forceExtension: true,
14
+
15
15
  args: [],
16
16
  columns: ['status', 'message'],
17
17
  func: async (page: IPage | null) => {
@@ -11,7 +11,7 @@ cli({
11
11
  domain: 'www.v2ex.com',
12
12
  strategy: Strategy.COOKIE,
13
13
  browser: true,
14
- forceExtension: true,
14
+
15
15
  args: [],
16
16
  columns: ['username', 'balance', 'unread_notifications', 'daily_reward_ready'],
17
17
  func: async (page: IPage | null) => {
@@ -11,7 +11,7 @@ cli({
11
11
  domain: 'www.v2ex.com',
12
12
  strategy: Strategy.COOKIE,
13
13
  browser: true,
14
- forceExtension: true,
14
+
15
15
  args: [
16
16
  { name: 'limit', type: 'int', default: 20, help: 'Number of notifications' }
17
17
  ],
@@ -92,18 +92,12 @@ describe('doctor report rendering', () => {
92
92
  envFingerprint: 'fp1',
93
93
  shellFiles: [{ path: '/tmp/.zshrc', exists: true, token: 'abc123', fingerprint: 'fp1' }],
94
94
  configs: [{ path: '/tmp/mcp.json', exists: true, format: 'json', token: 'abc123', fingerprint: 'fp1', writable: true }],
95
- remoteDebuggingEnabled: true,
96
- remoteDebuggingEndpoint: 'ws://127.0.0.1:9222/devtools/browser/test',
97
- cdpEnabled: false,
98
- cdpToken: null,
99
- cdpFingerprint: null,
100
95
  recommendedToken: 'abc123',
101
96
  recommendedFingerprint: 'fp1',
102
97
  warnings: [],
103
98
  issues: [],
104
99
  });
105
100
 
106
- expect(text).toContain('[OK] Chrome remote debugging: enabled');
107
101
  expect(text).toContain('[OK] Environment token: configured (fp1)');
108
102
  expect(text).toContain('[OK] MCP config /tmp/mcp.json: configured (fp1)');
109
103
  });
@@ -114,18 +108,12 @@ describe('doctor report rendering', () => {
114
108
  envFingerprint: 'fp1',
115
109
  shellFiles: [{ path: '/tmp/.zshrc', exists: true, token: 'def456', fingerprint: 'fp2' }],
116
110
  configs: [{ path: '/tmp/mcp.json', exists: true, format: 'json', token: 'abc123', fingerprint: 'fp1', writable: true }],
117
- remoteDebuggingEnabled: false,
118
- remoteDebuggingEndpoint: null,
119
- cdpEnabled: false,
120
- cdpToken: null,
121
- cdpFingerprint: null,
122
111
  recommendedToken: 'abc123',
123
112
  recommendedFingerprint: 'fp1',
124
- warnings: ['Chrome remote debugging appears to be disabled or Chrome is not currently exposing a DevTools endpoint.'],
113
+ warnings: [],
125
114
  issues: ['Detected inconsistent Playwright MCP tokens across env/config files.'],
126
115
  });
127
116
 
128
- expect(text).toContain('[WARN] Chrome remote debugging: disabled');
129
117
  expect(text).toContain('[MISMATCH] Environment token: configured (fp1)');
130
118
  expect(text).toContain('[MISMATCH] Shell file /tmp/.zshrc: configured (fp2)');
131
119
  expect(text).toContain('[MISMATCH] Recommended token fingerprint: fp1');
package/src/doctor.ts CHANGED
@@ -4,7 +4,7 @@ import * as path from 'node:path';
4
4
  import { createInterface } from 'node:readline/promises';
5
5
  import { stdin as input, stdout as output } from 'node:process';
6
6
  import type { IPage } from './types.js';
7
- import { PlaywrightMCP, discoverChromeEndpoint, getTokenFingerprint } from './browser.js';
7
+ import { PlaywrightMCP, getTokenFingerprint } from './browser.js';
8
8
  import { browserSession } from './runtime.js';
9
9
 
10
10
  const PLAYWRIGHT_SERVER_NAME = 'playwright';
@@ -45,11 +45,6 @@ export type DoctorReport = {
45
45
  envFingerprint: string | null;
46
46
  shellFiles: ShellFileStatus[];
47
47
  configs: McpConfigStatus[];
48
- remoteDebuggingEnabled: boolean;
49
- remoteDebuggingEndpoint: string | null;
50
- cdpEnabled: boolean;
51
- cdpToken: string | null;
52
- cdpFingerprint: string | null;
53
48
  recommendedToken: string | null;
54
49
  recommendedFingerprint: string | null;
55
50
  warnings: string[];
@@ -225,45 +220,10 @@ function readConfigStatus(filePath: string): McpConfigStatus {
225
220
  }
226
221
  }
227
222
 
228
- async function extractTokenViaCdp(): Promise<string | null> {
229
- if (!(process.env.OPENCLI_USE_CDP === '1' || process.env.OPENCLI_CDP_ENDPOINT))
230
- return null;
231
- const candidates = [
232
- `chrome-extension://${PLAYWRIGHT_EXTENSION_ID}/options.html`,
233
- `chrome-extension://${PLAYWRIGHT_EXTENSION_ID}/popup.html`,
234
- `chrome-extension://${PLAYWRIGHT_EXTENSION_ID}/connect.html`,
235
- `chrome-extension://${PLAYWRIGHT_EXTENSION_ID}/index.html`,
236
- ];
237
- const result = await browserSession(PlaywrightMCP, async (page: IPage) => {
238
- for (const url of candidates) {
239
- try {
240
- await page.goto(url);
241
- await page.wait(1);
242
- const token = await page.evaluate(`() => {
243
- const values = new Set();
244
- const push = (value) => {
245
- if (!value || typeof value !== 'string') return;
246
- for (const match of value.matchAll(/[A-Za-z0-9_-]{24,}/g)) values.add(match[0]);
247
- };
248
- document.querySelectorAll('input, textarea, code, pre, span, div').forEach((el) => {
249
- push(el.value);
250
- push(el.textContent || '');
251
- push(el.getAttribute && el.getAttribute('value'));
252
- });
253
- return Array.from(values);
254
- }`);
255
- const matches = Array.isArray(token) ? token.filter((v: string) => v.length >= 24) : [];
256
- if (matches.length > 0) return matches.sort((a: string, b: string) => b.length - a.length)[0];
257
- } catch {}
258
- }
259
- return null;
260
- });
261
- return typeof result === 'string' && result ? result : null;
262
- }
223
+
263
224
 
264
225
  export async function runBrowserDoctor(opts: DoctorOptions = {}): Promise<DoctorReport> {
265
226
  const envToken = process.env[PLAYWRIGHT_TOKEN_ENV] ?? null;
266
- const remoteDebuggingEndpoint = await discoverChromeEndpoint().catch(() => null);
267
227
  const shellPath = opts.shellRc ?? getDefaultShellRcPath();
268
228
  const shellFiles: ShellFileStatus[] = [shellPath].map((filePath) => {
269
229
  if (!fileExists(filePath)) return { path: filePath, exists: false, token: null, fingerprint: null };
@@ -273,17 +233,15 @@ export async function runBrowserDoctor(opts: DoctorOptions = {}): Promise<Doctor
273
233
  });
274
234
  const configPaths = opts.configPaths?.length ? opts.configPaths : getDefaultMcpConfigPaths();
275
235
  const configs = configPaths.map(readConfigStatus);
276
- const cdpToken = !opts.token && !envToken ? await extractTokenViaCdp().catch(() => null) : null;
277
236
 
278
237
  const allTokens = [
279
238
  opts.token ?? null,
280
239
  envToken,
281
240
  ...shellFiles.map(s => s.token),
282
241
  ...configs.map(c => c.token),
283
- cdpToken,
284
242
  ].filter((v): v is string => !!v);
285
243
  const uniqueTokens = [...new Set(allTokens)];
286
- const recommendedToken = opts.token ?? envToken ?? (uniqueTokens.length === 1 ? uniqueTokens[0] : cdpToken) ?? null;
244
+ const recommendedToken = opts.token ?? envToken ?? (uniqueTokens.length === 1 ? uniqueTokens[0] : null) ?? null;
287
245
 
288
246
  const report: DoctorReport = {
289
247
  cliVersion: opts.cliVersion,
@@ -291,11 +249,6 @@ export async function runBrowserDoctor(opts: DoctorOptions = {}): Promise<Doctor
291
249
  envFingerprint: getTokenFingerprint(envToken ?? undefined),
292
250
  shellFiles,
293
251
  configs,
294
- remoteDebuggingEnabled: !!remoteDebuggingEndpoint,
295
- remoteDebuggingEndpoint,
296
- cdpEnabled: process.env.OPENCLI_USE_CDP === '1' || !!process.env.OPENCLI_CDP_ENDPOINT,
297
- cdpToken,
298
- cdpFingerprint: getTokenFingerprint(cdpToken ?? undefined),
299
252
  recommendedToken,
300
253
  recommendedFingerprint: getTokenFingerprint(recommendedToken ?? undefined),
301
254
  warnings: [],
@@ -306,13 +259,11 @@ export async function runBrowserDoctor(opts: DoctorOptions = {}): Promise<Doctor
306
259
  if (!shellFiles.some(s => s.token)) report.issues.push('Shell startup file does not export PLAYWRIGHT_MCP_EXTENSION_TOKEN.');
307
260
  if (!configs.some(c => c.token)) report.issues.push('No scanned MCP config currently contains a Playwright extension token.');
308
261
  if (uniqueTokens.length > 1) report.issues.push('Detected inconsistent Playwright MCP tokens across env/config files.');
309
- if (!report.remoteDebuggingEnabled) report.warnings.push('Chrome remote debugging appears to be disabled or Chrome is not currently exposing a DevTools endpoint.');
310
262
  for (const config of configs) {
311
263
  if (config.parseError) report.warnings.push(`Could not parse ${config.path}: ${config.parseError}`);
312
264
  }
313
265
  if (!recommendedToken) {
314
- if (report.cdpEnabled) report.warnings.push('CDP is enabled, but no token could be extracted automatically from the extension UI.');
315
- else report.warnings.push('No token source found. Enable OPENCLI_USE_CDP=1 to allow a best-effort token read from the extension page.');
266
+ report.warnings.push('No token source found.');
316
267
  }
317
268
  return report;
318
269
  }
@@ -326,8 +277,6 @@ export function renderBrowserDoctorReport(report: DoctorReport): string {
326
277
  const uniqueFingerprints = [...new Set(tokenFingerprints)];
327
278
  const hasMismatch = uniqueFingerprints.length > 1;
328
279
  const lines = [`opencli v${report.cliVersion ?? 'unknown'} doctor`, ''];
329
- lines.push(statusLine(report.remoteDebuggingEnabled ? 'OK' : 'WARN', `Chrome remote debugging: ${report.remoteDebuggingEnabled ? 'enabled' : 'disabled'}`));
330
- if (report.remoteDebuggingEndpoint) lines.push(` ${report.remoteDebuggingEndpoint}`);
331
280
 
332
281
  const envStatus: ReportStatus = !report.envToken ? 'MISSING' : hasMismatch ? 'MISMATCH' : 'OK';
333
282
  lines.push(statusLine(envStatus, `Environment token: ${tokenSummary(report.envToken, report.envFingerprint)}`));
@@ -354,10 +303,6 @@ export function renderBrowserDoctorReport(report: DoctorReport): string {
354
303
  lines.push(statusLine('MISSING', 'MCP config: no existing config files found in scanned locations'));
355
304
  }
356
305
  if (missingConfigCount > 0) lines.push(` Other scanned config locations not present: ${missingConfigCount}`);
357
- if (report.cdpEnabled) {
358
- const cdpStatus: ReportStatus = report.cdpToken ? 'OK' : 'WARN';
359
- lines.push(statusLine(cdpStatus, `CDP token probe: ${tokenSummary(report.cdpToken, report.cdpFingerprint)}`));
360
- }
361
306
  lines.push('');
362
307
  lines.push(statusLine(
363
308
  hasMismatch ? 'MISMATCH' : report.recommendedToken ? 'OK' : 'WARN',
@@ -391,7 +336,7 @@ function writeFileWithMkdir(filePath: string, content: string): void {
391
336
 
392
337
  export async function applyBrowserDoctorFix(report: DoctorReport, opts: DoctorOptions = {}): Promise<string[]> {
393
338
  const token = opts.token ?? report.recommendedToken;
394
- if (!token) throw new Error('No Playwright MCP token is available to write. Provide --token or enable CDP token probing first.');
339
+ if (!token) throw new Error('No Playwright MCP token is available to write. Provide --token first.');
395
340
 
396
341
  const plannedWrites: string[] = [];
397
342
  const shellPath = opts.shellRc ?? report.shellFiles[0]?.path ?? getDefaultShellRcPath();
package/src/main.ts CHANGED
@@ -144,7 +144,7 @@ for (const [, cmd] of registry) {
144
144
  if (actionOpts.verbose) process.env.OPENCLI_VERBOSE = '1';
145
145
  let result: any;
146
146
  if (cmd.browser) {
147
- result = await browserSession(PlaywrightMCP, async (page) => runWithTimeout(executeCommand(cmd, page, kwargs, actionOpts.verbose), { timeout: cmd.timeoutSeconds ?? DEFAULT_BROWSER_COMMAND_TIMEOUT, label: fullName(cmd) }), { forceExtension: cmd.forceExtension });
147
+ result = await browserSession(PlaywrightMCP, async (page) => runWithTimeout(executeCommand(cmd, page, kwargs, actionOpts.verbose), { timeout: cmd.timeoutSeconds ?? DEFAULT_BROWSER_COMMAND_TIMEOUT, label: fullName(cmd) }));
148
148
  } else { result = await executeCommand(cmd, null, kwargs, actionOpts.verbose); }
149
149
  if (actionOpts.verbose && (!result || (Array.isArray(result) && result.length === 0))) {
150
150
  console.error(chalk.yellow(`[Verbose] Warning: Command returned an empty result. If the website structural API changed or requires authentication, check the network or update the adapter.`));
package/src/registry.ts CHANGED
@@ -37,10 +37,7 @@ export interface CliCommand {
37
37
  /** Internal: lazy-loaded TS module support */
38
38
  _lazy?: boolean;
39
39
  _modulePath?: string;
40
- /** Force extension bridge mode (bypass CDP), for anti-bot sites */
41
- forceExtension?: boolean;
42
40
  }
43
-
44
41
  export interface CliOptions {
45
42
  site: string;
46
43
  name: string;
@@ -53,10 +50,7 @@ export interface CliOptions {
53
50
  func?: (page: IPage | null, kwargs: Record<string, any>, debug?: boolean) => Promise<any>;
54
51
  pipeline?: any[];
55
52
  timeoutSeconds?: number;
56
- /** Force extension bridge mode (bypass CDP), for anti-bot sites */
57
- forceExtension?: boolean;
58
53
  }
59
-
60
54
  const _registry = new Map<string, CliCommand>();
61
55
 
62
56
  export function cli(opts: CliOptions): CliCommand {
@@ -72,7 +66,6 @@ export function cli(opts: CliOptions): CliCommand {
72
66
  func: opts.func,
73
67
  pipeline: opts.pipeline,
74
68
  timeoutSeconds: opts.timeoutSeconds,
75
- forceExtension: opts.forceExtension,
76
69
  };
77
70
 
78
71
  const key = fullName(cmd);
package/src/runtime.ts CHANGED
@@ -27,11 +27,10 @@ export async function runWithTimeout<T>(
27
27
  export async function browserSession<T>(
28
28
  BrowserFactory: new () => any,
29
29
  fn: (page: IPage) => Promise<T>,
30
- opts?: { forceExtension?: boolean },
31
30
  ): Promise<T> {
32
31
  const mcp = new BrowserFactory();
33
32
  try {
34
- const page = await mcp.connect({ timeout: DEFAULT_BROWSER_CONNECT_TIMEOUT, forceExtension: opts?.forceExtension });
33
+ const page = await mcp.connect({ timeout: DEFAULT_BROWSER_CONNECT_TIMEOUT });
35
34
  return await fn(page);
36
35
  } finally {
37
36
  await mcp.close().catch(() => {});