agent-browser 0.20.6 → 0.20.8
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/README.md +7 -52
- package/bin/agent-browser-darwin-arm64 +0 -0
- package/bin/agent-browser-darwin-x64 +0 -0
- package/bin/agent-browser-linux-arm64 +0 -0
- package/bin/agent-browser-linux-musl-arm64 +0 -0
- package/bin/agent-browser-linux-musl-x64 +0 -0
- package/bin/agent-browser-linux-x64 +0 -0
- package/bin/agent-browser-win32-x64.exe +0 -0
- package/package.json +1 -1
- package/scripts/postinstall.js +49 -4
package/README.md
CHANGED
|
@@ -794,15 +794,15 @@ See the [environments example](examples/environments/) for a working demo with a
|
|
|
794
794
|
|
|
795
795
|
```typescript
|
|
796
796
|
import chromium from '@sparticuz/chromium';
|
|
797
|
-
import {
|
|
797
|
+
import { execSync } from 'child_process';
|
|
798
798
|
|
|
799
799
|
export async function handler() {
|
|
800
|
-
const
|
|
801
|
-
|
|
802
|
-
executablePath
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
800
|
+
const executablePath = await chromium.executablePath();
|
|
801
|
+
const result = execSync(
|
|
802
|
+
`AGENT_BROWSER_EXECUTABLE_PATH=${executablePath} agent-browser open https://example.com && agent-browser snapshot -i --json`,
|
|
803
|
+
{ encoding: 'utf-8' }
|
|
804
|
+
);
|
|
805
|
+
return JSON.parse(result);
|
|
806
806
|
}
|
|
807
807
|
```
|
|
808
808
|
|
|
@@ -953,51 +953,6 @@ Connect to `ws://localhost:9223` to receive frames and send input:
|
|
|
953
953
|
}
|
|
954
954
|
```
|
|
955
955
|
|
|
956
|
-
### Programmatic API
|
|
957
|
-
|
|
958
|
-
For advanced use, control streaming directly via the protocol:
|
|
959
|
-
|
|
960
|
-
```typescript
|
|
961
|
-
import { BrowserManager } from 'agent-browser';
|
|
962
|
-
|
|
963
|
-
const browser = new BrowserManager();
|
|
964
|
-
await browser.launch({ headless: true });
|
|
965
|
-
await browser.navigate('https://example.com');
|
|
966
|
-
|
|
967
|
-
// Start screencast
|
|
968
|
-
await browser.startScreencast(
|
|
969
|
-
(frame) => {
|
|
970
|
-
// frame.data is base64-encoded image
|
|
971
|
-
// frame.metadata contains viewport info
|
|
972
|
-
console.log('Frame received:', frame.metadata.deviceWidth, 'x', frame.metadata.deviceHeight);
|
|
973
|
-
},
|
|
974
|
-
{
|
|
975
|
-
format: 'jpeg',
|
|
976
|
-
quality: 80,
|
|
977
|
-
maxWidth: 1280,
|
|
978
|
-
maxHeight: 720,
|
|
979
|
-
}
|
|
980
|
-
);
|
|
981
|
-
|
|
982
|
-
// Inject mouse events
|
|
983
|
-
await browser.injectMouseEvent({
|
|
984
|
-
type: 'mousePressed',
|
|
985
|
-
x: 100,
|
|
986
|
-
y: 200,
|
|
987
|
-
button: 'left',
|
|
988
|
-
});
|
|
989
|
-
|
|
990
|
-
// Inject keyboard events
|
|
991
|
-
await browser.injectKeyboardEvent({
|
|
992
|
-
type: 'keyDown',
|
|
993
|
-
key: 'Enter',
|
|
994
|
-
code: 'Enter',
|
|
995
|
-
});
|
|
996
|
-
|
|
997
|
-
// Stop when done
|
|
998
|
-
await browser.stopScreencast();
|
|
999
|
-
```
|
|
1000
|
-
|
|
1001
956
|
## Architecture
|
|
1002
957
|
|
|
1003
958
|
agent-browser uses a client-daemon architecture:
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -128,15 +128,60 @@ async function main() {
|
|
|
128
128
|
showInstallReminder();
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
function findSystemChrome() {
|
|
132
|
+
const os = platform();
|
|
133
|
+
if (os === 'darwin') {
|
|
134
|
+
const candidates = [
|
|
135
|
+
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
136
|
+
'/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
|
|
137
|
+
'/Applications/Chromium.app/Contents/MacOS/Chromium',
|
|
138
|
+
];
|
|
139
|
+
return candidates.find(p => existsSync(p)) || null;
|
|
140
|
+
}
|
|
141
|
+
if (os === 'linux') {
|
|
142
|
+
const names = ['google-chrome', 'google-chrome-stable', 'chromium-browser', 'chromium'];
|
|
143
|
+
for (const name of names) {
|
|
144
|
+
try {
|
|
145
|
+
const result = execSync(`which ${name} 2>/dev/null`, { encoding: 'utf8' }).trim();
|
|
146
|
+
if (result) return result;
|
|
147
|
+
} catch {}
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
if (os === 'win32') {
|
|
152
|
+
const candidates = [
|
|
153
|
+
`${process.env.LOCALAPPDATA}\\Google\\Chrome\\Application\\chrome.exe`,
|
|
154
|
+
'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
|
|
155
|
+
'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
|
|
156
|
+
];
|
|
157
|
+
return candidates.find(p => p && existsSync(p)) || null;
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
|
|
131
162
|
function showInstallReminder() {
|
|
163
|
+
const systemChrome = findSystemChrome();
|
|
164
|
+
if (systemChrome) {
|
|
165
|
+
console.log('');
|
|
166
|
+
console.log(` ✓ System Chrome found: ${systemChrome}`);
|
|
167
|
+
console.log(' agent-browser will use it automatically.');
|
|
168
|
+
console.log('');
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
|
|
132
172
|
console.log('');
|
|
133
|
-
console.log('
|
|
173
|
+
console.log(' ⚠ No Chrome installation detected.');
|
|
174
|
+
console.log(' If you plan to use a local browser, run:');
|
|
134
175
|
console.log('');
|
|
135
176
|
console.log(' agent-browser install');
|
|
177
|
+
if (platform() === 'linux') {
|
|
178
|
+
console.log('');
|
|
179
|
+
console.log(' On Linux, include system dependencies with:');
|
|
180
|
+
console.log('');
|
|
181
|
+
console.log(' agent-browser install --with-deps');
|
|
182
|
+
}
|
|
136
183
|
console.log('');
|
|
137
|
-
console.log('
|
|
138
|
-
console.log('');
|
|
139
|
-
console.log(' agent-browser install --with-deps');
|
|
184
|
+
console.log(' You can skip this if you use --cdp, --provider, --engine, or --executable-path.');
|
|
140
185
|
console.log('');
|
|
141
186
|
}
|
|
142
187
|
|