agent-browser 0.1.0 → 0.1.2
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/LICENSE +201 -0
- package/README.md +4 -1
- package/dist/actions.js +0 -2
- package/dist/actions.js.map +1 -1
- package/dist/browser.d.ts +5 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +25 -1
- package/dist/browser.js.map +1 -1
- package/dist/index.js +186 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -4
- package/scripts/postinstall.js +17 -0
- package/src/actions.ts +1 -3
- package/src/browser.ts +30 -1
- package/src/index.ts +196 -0
- package/src/types.ts +1 -1
package/src/index.ts
CHANGED
|
@@ -2,9 +2,173 @@
|
|
|
2
2
|
import * as fs from 'fs';
|
|
3
3
|
import * as os from 'os';
|
|
4
4
|
import * as path from 'path';
|
|
5
|
+
import { execSync, spawnSync } from 'child_process';
|
|
5
6
|
import { send, setDebug, setSession, getSession } from './client.js';
|
|
6
7
|
import type { Response } from './types.js';
|
|
7
8
|
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// System Dependencies Installation
|
|
11
|
+
// ============================================================================
|
|
12
|
+
|
|
13
|
+
// Common dependencies needed for Playwright browsers on Linux
|
|
14
|
+
const LINUX_DEPS = {
|
|
15
|
+
// Shared libraries for Chromium/Firefox/WebKit
|
|
16
|
+
apt: [
|
|
17
|
+
'libxcb-shm0',
|
|
18
|
+
'libx11-xcb1',
|
|
19
|
+
'libx11-6',
|
|
20
|
+
'libxcb1',
|
|
21
|
+
'libxext6',
|
|
22
|
+
'libxrandr2',
|
|
23
|
+
'libxcomposite1',
|
|
24
|
+
'libxcursor1',
|
|
25
|
+
'libxdamage1',
|
|
26
|
+
'libxfixes3',
|
|
27
|
+
'libxi6',
|
|
28
|
+
'libgtk-3-0',
|
|
29
|
+
'libpangocairo-1.0-0',
|
|
30
|
+
'libpango-1.0-0',
|
|
31
|
+
'libatk1.0-0',
|
|
32
|
+
'libcairo-gobject2',
|
|
33
|
+
'libcairo2',
|
|
34
|
+
'libgdk-pixbuf-2.0-0',
|
|
35
|
+
'libxrender1',
|
|
36
|
+
'libasound2',
|
|
37
|
+
'libfreetype6',
|
|
38
|
+
'libfontconfig1',
|
|
39
|
+
'libdbus-1-3',
|
|
40
|
+
'libnss3',
|
|
41
|
+
'libnspr4',
|
|
42
|
+
'libatk-bridge2.0-0',
|
|
43
|
+
'libdrm2',
|
|
44
|
+
'libxkbcommon0',
|
|
45
|
+
'libatspi2.0-0',
|
|
46
|
+
'libcups2',
|
|
47
|
+
'libxshmfence1',
|
|
48
|
+
'libgbm1',
|
|
49
|
+
],
|
|
50
|
+
dnf: [
|
|
51
|
+
'libxcb',
|
|
52
|
+
'libX11-xcb',
|
|
53
|
+
'libX11',
|
|
54
|
+
'libXext',
|
|
55
|
+
'libXrandr',
|
|
56
|
+
'libXcomposite',
|
|
57
|
+
'libXcursor',
|
|
58
|
+
'libXdamage',
|
|
59
|
+
'libXfixes',
|
|
60
|
+
'libXi',
|
|
61
|
+
'gtk3',
|
|
62
|
+
'pango',
|
|
63
|
+
'atk',
|
|
64
|
+
'cairo-gobject',
|
|
65
|
+
'cairo',
|
|
66
|
+
'gdk-pixbuf2',
|
|
67
|
+
'libXrender',
|
|
68
|
+
'alsa-lib',
|
|
69
|
+
'freetype',
|
|
70
|
+
'fontconfig',
|
|
71
|
+
'dbus-libs',
|
|
72
|
+
'nss',
|
|
73
|
+
'nspr',
|
|
74
|
+
'at-spi2-atk',
|
|
75
|
+
'libdrm',
|
|
76
|
+
'libxkbcommon',
|
|
77
|
+
'at-spi2-core',
|
|
78
|
+
'cups-libs',
|
|
79
|
+
'libxshmfence',
|
|
80
|
+
'mesa-libgbm',
|
|
81
|
+
'libwayland-client',
|
|
82
|
+
'libwayland-server',
|
|
83
|
+
],
|
|
84
|
+
yum: [
|
|
85
|
+
'libxcb',
|
|
86
|
+
'libX11-xcb',
|
|
87
|
+
'libX11',
|
|
88
|
+
'libXext',
|
|
89
|
+
'libXrandr',
|
|
90
|
+
'libXcomposite',
|
|
91
|
+
'libXcursor',
|
|
92
|
+
'libXdamage',
|
|
93
|
+
'libXfixes',
|
|
94
|
+
'libXi',
|
|
95
|
+
'gtk3',
|
|
96
|
+
'pango',
|
|
97
|
+
'atk',
|
|
98
|
+
'cairo-gobject',
|
|
99
|
+
'cairo',
|
|
100
|
+
'gdk-pixbuf2',
|
|
101
|
+
'libXrender',
|
|
102
|
+
'alsa-lib',
|
|
103
|
+
'freetype',
|
|
104
|
+
'fontconfig',
|
|
105
|
+
'dbus-libs',
|
|
106
|
+
'nss',
|
|
107
|
+
'nspr',
|
|
108
|
+
'at-spi2-atk',
|
|
109
|
+
'libdrm',
|
|
110
|
+
'libxkbcommon',
|
|
111
|
+
'at-spi2-core',
|
|
112
|
+
'cups-libs',
|
|
113
|
+
'libxshmfence',
|
|
114
|
+
'mesa-libgbm',
|
|
115
|
+
],
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
function detectPackageManager(): 'apt' | 'dnf' | 'yum' | null {
|
|
119
|
+
const managers = ['apt-get', 'dnf', 'yum'] as const;
|
|
120
|
+
for (const mgr of managers) {
|
|
121
|
+
try {
|
|
122
|
+
execSync(`which ${mgr}`, { stdio: 'ignore' });
|
|
123
|
+
return mgr === 'apt-get' ? 'apt' : mgr;
|
|
124
|
+
} catch {
|
|
125
|
+
// Not found, try next
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function installSystemDeps(): void {
|
|
132
|
+
if (os.platform() !== 'linux') {
|
|
133
|
+
console.log('System dependency installation is only needed on Linux');
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const pkgMgr = detectPackageManager();
|
|
138
|
+
if (!pkgMgr) {
|
|
139
|
+
throw new Error('No supported package manager found (apt-get, dnf, or yum)');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const deps = LINUX_DEPS[pkgMgr];
|
|
143
|
+
if (!deps || deps.length === 0) {
|
|
144
|
+
throw new Error(`No dependencies defined for package manager: ${pkgMgr}`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
console.log(`Detected package manager: ${pkgMgr}`);
|
|
148
|
+
console.log(`Installing ${deps.length} dependencies...`);
|
|
149
|
+
|
|
150
|
+
let cmd: string;
|
|
151
|
+
switch (pkgMgr) {
|
|
152
|
+
case 'apt':
|
|
153
|
+
cmd = `apt-get update && apt-get install -y ${deps.join(' ')}`;
|
|
154
|
+
break;
|
|
155
|
+
case 'dnf':
|
|
156
|
+
cmd = `dnf install -y ${deps.join(' ')}`;
|
|
157
|
+
break;
|
|
158
|
+
case 'yum':
|
|
159
|
+
cmd = `yum install -y ${deps.join(' ')}`;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Run with sudo if not root
|
|
164
|
+
const isRoot = process.getuid?.() === 0;
|
|
165
|
+
if (!isRoot) {
|
|
166
|
+
cmd = `sudo ${cmd}`;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
execSync(cmd, { stdio: 'inherit' });
|
|
170
|
+
}
|
|
171
|
+
|
|
8
172
|
// ============================================================================
|
|
9
173
|
// Utilities
|
|
10
174
|
// ============================================================================
|
|
@@ -109,6 +273,10 @@ ${c('yellow', 'Debug:')}
|
|
|
109
273
|
${c('cyan', 'console')} View console logs
|
|
110
274
|
${c('cyan', 'errors')} View page errors
|
|
111
275
|
|
|
276
|
+
${c('yellow', 'Setup:')}
|
|
277
|
+
${c('cyan', 'install')} Install browser binaries
|
|
278
|
+
${c('cyan', 'install')} --with-deps Also install system dependencies (Linux)
|
|
279
|
+
|
|
112
280
|
${c('yellow', 'Options:')}
|
|
113
281
|
--session <name> Isolated session (or AGENT_BROWSER_SESSION env)
|
|
114
282
|
--json JSON output
|
|
@@ -946,6 +1114,34 @@ async function main(): Promise<void> {
|
|
|
946
1114
|
process.exit(0);
|
|
947
1115
|
}
|
|
948
1116
|
|
|
1117
|
+
case 'install': {
|
|
1118
|
+
const withDeps = rawArgs.includes('--with-deps') || rawArgs.includes('-d');
|
|
1119
|
+
|
|
1120
|
+
// Install system dependencies first if requested
|
|
1121
|
+
if (withDeps) {
|
|
1122
|
+
console.log(c('cyan', 'Installing system dependencies...'));
|
|
1123
|
+
try {
|
|
1124
|
+
installSystemDeps();
|
|
1125
|
+
console.log(c('green', '✓'), 'System dependencies installed');
|
|
1126
|
+
} catch (error) {
|
|
1127
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
1128
|
+
console.error(c('red', '✗'), 'Failed to install system dependencies:', msg);
|
|
1129
|
+
process.exit(1);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
// Install browsers
|
|
1134
|
+
console.log(c('cyan', 'Installing Playwright browsers...'));
|
|
1135
|
+
try {
|
|
1136
|
+
execSync('npx playwright install', { stdio: 'inherit' });
|
|
1137
|
+
console.log(c('green', '✓'), 'Browsers installed successfully');
|
|
1138
|
+
process.exit(0);
|
|
1139
|
+
} catch (error) {
|
|
1140
|
+
console.error(c('red', '✗'), 'Failed to install browsers');
|
|
1141
|
+
process.exit(1);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
|
|
949
1145
|
// === Legacy aliases for backwards compatibility ===
|
|
950
1146
|
case 'url':
|
|
951
1147
|
cmd = { id, action: 'url' };
|
package/src/types.ts
CHANGED