@cli4ai/chrome 1.0.5 → 1.0.6
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/package.json +1 -2
- package/run.ts +9 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cli4ai/chrome",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
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
|
-
|
|
33
|
-
|
|
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,7 +43,7 @@ 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
|
-
|
|
46
|
+
output({ title: await page.title(), url: page.url() });
|
|
45
47
|
if (options.newTab) await page.close();
|
|
46
48
|
browser.disconnect();
|
|
47
49
|
}));
|
|
@@ -64,7 +66,8 @@ program
|
|
|
64
66
|
const { page, browser } = await getPage();
|
|
65
67
|
const outputPath = resolve(outputFile);
|
|
66
68
|
await page.screenshot({ path: outputPath, fullPage: options.fullPage });
|
|
67
|
-
|
|
69
|
+
log(`Saved: ${outputPath}`);
|
|
70
|
+
output({ path: outputPath });
|
|
68
71
|
browser.disconnect();
|
|
69
72
|
}));
|
|
70
73
|
|
|
@@ -79,7 +82,7 @@ program
|
|
|
79
82
|
? cookies.filter((c: { domain: string }) => c.domain.includes(domain))
|
|
80
83
|
: cookies;
|
|
81
84
|
output(filtered);
|
|
82
|
-
|
|
85
|
+
log(`\n${filtered.length} cookies`);
|
|
83
86
|
browser.disconnect();
|
|
84
87
|
}));
|
|
85
88
|
|