@cli4ai/chrome 1.0.5 → 1.0.7

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.
Files changed (3) hide show
  1. package/cli4ai.json +57 -8
  2. package/package.json +1 -2
  3. package/run.ts +14 -7
package/cli4ai.json CHANGED
@@ -1,22 +1,71 @@
1
1
  {
2
2
  "name": "chrome",
3
- "version": "1.0.4",
3
+ "version": "1.0.7",
4
4
  "description": "Chrome browser automation (foundation for browser tools)",
5
5
  "author": "cliforai",
6
6
  "license": "MIT",
7
7
  "entry": "run.ts",
8
8
  "runtime": "bun",
9
- "keywords": ["chrome", "browser", "puppeteer", "automation"],
9
+ "keywords": [
10
+ "chrome",
11
+ "browser",
12
+ "puppeteer",
13
+ "automation"
14
+ ],
10
15
  "commands": {
11
- "connect": { "description": "Connect to Chrome", "args": [{ "name": "port", "description": "Default: 9222", "required": false }] },
12
- "navigate": { "description": "Open URL", "args": [{ "name": "url", "required": true }] },
13
- "eval": { "description": "Run JavaScript", "args": [{ "name": "script", "required": true }] },
14
- "screenshot": { "description": "Capture viewport", "args": [{ "name": "output", "required": false }] },
15
- "cookies": { "description": "Get cookies", "args": [{ "name": "domain", "required": false }] }
16
+ "connect": {
17
+ "description": "Connect to Chrome",
18
+ "args": [
19
+ {
20
+ "name": "port",
21
+ "description": "Default: 9222",
22
+ "required": false
23
+ }
24
+ ]
25
+ },
26
+ "navigate": {
27
+ "description": "Open URL",
28
+ "args": [
29
+ {
30
+ "name": "url",
31
+ "required": true
32
+ }
33
+ ]
34
+ },
35
+ "eval": {
36
+ "description": "Run JavaScript",
37
+ "args": [
38
+ {
39
+ "name": "script",
40
+ "required": true
41
+ }
42
+ ]
43
+ },
44
+ "screenshot": {
45
+ "description": "Capture viewport",
46
+ "args": [
47
+ {
48
+ "name": "output",
49
+ "required": false
50
+ }
51
+ ]
52
+ },
53
+ "cookies": {
54
+ "description": "Get cookies",
55
+ "args": [
56
+ {
57
+ "name": "domain",
58
+ "required": false
59
+ }
60
+ ]
61
+ }
16
62
  },
17
63
  "dependencies": {
18
64
  "puppeteer": "^24.0.0",
19
65
  "commander": "^14.0.0"
20
66
  },
21
- "mcp": { "enabled": true, "transport": "stdio" }
67
+ "mcp": {
68
+ "enabled": true,
69
+ "transport": "stdio"
70
+ }
22
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cli4ai/chrome",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Chrome browser automation (foundation for browser tools)",
5
5
  "author": "cliforai",
6
6
  "license": "MIT",
@@ -28,7 +28,6 @@
28
28
  "url": "https://github.com/cliforai/packages/issues"
29
29
  },
30
30
  "dependencies": {
31
- "@cli4ai/lib": "^1.0.2",
32
31
  "puppeteer": "^24.0.0",
33
32
  "commander": "^14.0.0"
34
33
  },
package/run.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import puppeteer from 'puppeteer';
3
3
  import { readFileSync, writeFileSync } from 'fs';
4
4
  import { join, resolve } from 'path';
5
- import { cli, output, outputError, withErrorHandling } from '@cli4ai/lib/cli.ts';
5
+ import { cli, log, output, outputError, withErrorHandling } from '@cli4ai/lib/cli.ts';
6
6
 
7
7
  const WS_FILE = join(import.meta.dir, '.ws-endpoint');
8
8
 
@@ -29,8 +29,10 @@ program
29
29
  .description('Connect to Chrome (default: 9222)')
30
30
  .action(withErrorHandling(async (port = '9222') => {
31
31
  const browser = await puppeteer.connect({ browserURL: `http://127.0.0.1:${port}` });
32
- writeFileSync(WS_FILE, browser.wsEndpoint());
33
- console.log(`Connected on port ${port}`);
32
+ const wsEndpoint = browser.wsEndpoint();
33
+ writeFileSync(WS_FILE, wsEndpoint);
34
+ log(`Connected on port ${port}`);
35
+ output({ connected: true, port, wsEndpoint });
34
36
  browser.disconnect();
35
37
  }));
36
38
 
@@ -41,15 +43,19 @@ program
41
43
  .action(withErrorHandling(async (url: string, options: { newTab?: boolean }) => {
42
44
  const { page, browser } = await getPage(options.newTab);
43
45
  await page.goto(url, { waitUntil: 'networkidle2' });
44
- console.log(await page.title());
46
+ output({ title: await page.title(), url: page.url() });
45
47
  if (options.newTab) await page.close();
46
48
  browser.disconnect();
47
49
  }));
48
50
 
49
51
  program
50
52
  .command('eval <script>')
51
- .description('Run JavaScript')
53
+ .description('Run JavaScript (WARNING: executes arbitrary code in browser context)')
52
54
  .action(withErrorHandling(async (script: string) => {
55
+ // SECURITY WARNING: This command executes arbitrary JavaScript in the browser.
56
+ // Only use with trusted input. Malicious scripts can access cookies, localStorage,
57
+ // and perform actions as the logged-in user.
58
+ log('⚠️ WARNING: Executing arbitrary JavaScript in browser context');
53
59
  const { page, browser } = await getPage();
54
60
  const result = await page.evaluate((code: string) => eval(code), script);
55
61
  if (result !== undefined) output(result);
@@ -64,7 +70,8 @@ program
64
70
  const { page, browser } = await getPage();
65
71
  const outputPath = resolve(outputFile);
66
72
  await page.screenshot({ path: outputPath, fullPage: options.fullPage });
67
- console.log(`Saved: ${outputPath}`);
73
+ log(`Saved: ${outputPath}`);
74
+ output({ path: outputPath });
68
75
  browser.disconnect();
69
76
  }));
70
77
 
@@ -79,7 +86,7 @@ program
79
86
  ? cookies.filter((c: { domain: string }) => c.domain.includes(domain))
80
87
  : cookies;
81
88
  output(filtered);
82
- console.error(`\n${filtered.length} cookies`);
89
+ log(`\n${filtered.length} cookies`);
83
90
  browser.disconnect();
84
91
  }));
85
92