@kritchoff/agent-browser 1.0.0 → 1.0.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/README.md +35 -35
- package/dist/orchestrator.js +4 -4
- package/dist/orchestrator.js.map +1 -1
- package/package.json +6 -15
- package/bin/agent-browser-linux-x64 +0 -0
- package/scripts/copy-native.js +0 -36
- package/scripts/postinstall.js +0 -235
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @kritchoff/agent-browser
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<strong>The Ultimate Headless Android Browser SDK for AI Agents</strong>
|
|
4
|
+
<strong>The Ultimate Headless Android Browser SDK & CLI for AI Agents</strong>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
|
-
This
|
|
7
|
+
This package provides a **Real Android Browser** (WootzApp) wrapped in a Docker container, controlled by a high-speed, Playwright-like TypeScript daemon.
|
|
8
8
|
|
|
9
9
|
It is specifically designed for AI Agents to navigate the mobile web, bypass bot detection, and generate LLM-friendly semantic trees (`AXTree`).
|
|
10
10
|
|
|
@@ -13,6 +13,7 @@ It is specifically designed for AI Agents to navigate the mobile web, bypass bot
|
|
|
13
13
|
## 🌟 Key Features
|
|
14
14
|
|
|
15
15
|
- **Cross-Platform**: Works natively on **Windows, macOS (Intel & Apple Silicon), and Linux** using a pure Node.js Orchestrator (No WSL or bash required).
|
|
16
|
+
- **Bundled CLI**: Control the browser directly from your terminal (`agent-browser start`).
|
|
16
17
|
- **Zero-Config Setup**: Automatically downloads and orchestrates the required Docker containers.
|
|
17
18
|
- **Hyper-Speed Warm Boots**: Uses advanced VDI Volume Mounting to boot the Android environment in **< 5 seconds** after the first run.
|
|
18
19
|
- **Fast Resets**: Cleans the browser state via Android userspace reboot in **~15 seconds**.
|
|
@@ -30,24 +31,47 @@ It is specifically designed for AI Agents to navigate the mobile web, bypass bot
|
|
|
30
31
|
|
|
31
32
|
---
|
|
32
33
|
|
|
33
|
-
##
|
|
34
|
+
## 💻 Global CLI Usage (Recommended for Testing)
|
|
34
35
|
|
|
35
|
-
|
|
36
|
+
The easiest way to use the Agent Browser is via the global Command Line Interface.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# 1. Install globally
|
|
40
|
+
npm install -g @kritchoff/agent-browser
|
|
41
|
+
|
|
42
|
+
# 2. Start the environment (Takes ~90s first time, ~5s after)
|
|
43
|
+
agent-browser start
|
|
44
|
+
|
|
45
|
+
# 3. Run commands interactively
|
|
46
|
+
agent-browser navigate https://news.ycombinator.com
|
|
47
|
+
agent-browser click ".titleline a"
|
|
48
|
+
|
|
49
|
+
# 4. Get the Semantic UI Tree printed to your terminal
|
|
50
|
+
agent-browser snapshot
|
|
51
|
+
|
|
52
|
+
# 5. Clean the browser state for a new session (~15s)
|
|
53
|
+
agent-browser reset
|
|
54
|
+
|
|
55
|
+
# 6. Completely stop and tear down containers
|
|
56
|
+
agent-browser stop
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 📦 Node.js SDK Usage (For your AI Agents)
|
|
62
|
+
|
|
63
|
+
Install the SDK locally in your project:
|
|
36
64
|
|
|
37
65
|
```bash
|
|
38
66
|
npm install @kritchoff/agent-browser
|
|
39
67
|
```
|
|
40
68
|
|
|
41
|
-
*(Optional but recommended)* Install `tsx` to run TypeScript files natively
|
|
69
|
+
*(Optional but recommended)* Install `tsx` to run TypeScript files natively:
|
|
42
70
|
```bash
|
|
43
71
|
npm install -D tsx
|
|
44
72
|
```
|
|
45
73
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
## 🚀 Quick Start Guide
|
|
49
|
-
|
|
50
|
-
Create a file named `agent.ts`:
|
|
74
|
+
### Quick Start Code (`agent.ts`)
|
|
51
75
|
|
|
52
76
|
```typescript
|
|
53
77
|
import { WootzAgent } from '@kritchoff/agent-browser';
|
|
@@ -91,30 +115,6 @@ npx tsx agent.ts
|
|
|
91
115
|
|
|
92
116
|
---
|
|
93
117
|
|
|
94
|
-
## 💻 CLI Usage (Global Install)
|
|
95
|
-
|
|
96
|
-
You can use the SDK directly from your terminal to debug or control the browser manually without writing code. The CLI is automatically installed when you install the package globally.
|
|
97
|
-
|
|
98
|
-
```bash
|
|
99
|
-
npm install -g @kritchoff/agent-browser
|
|
100
|
-
|
|
101
|
-
# 1. Start the environment (Takes ~90s first time, ~5s after)
|
|
102
|
-
agent-browser start
|
|
103
|
-
|
|
104
|
-
# 2. Run commands interactively
|
|
105
|
-
agent-browser navigate https://news.ycombinator.com
|
|
106
|
-
agent-browser click ".titleline a"
|
|
107
|
-
agent-browser snapshot
|
|
108
|
-
|
|
109
|
-
# 3. Clean the browser for a new session
|
|
110
|
-
agent-browser reset
|
|
111
|
-
|
|
112
|
-
# 4. Stop and clean up containers
|
|
113
|
-
agent-browser stop
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
118
|
## 📖 Complete API Reference
|
|
119
119
|
|
|
120
120
|
For a complete list of all available commands (clicking, typing, tabbing, network interception, storage), please read the **[COMMANDS.md](./COMMANDS.md)** file.
|
|
@@ -125,7 +125,7 @@ For a complete list of all available commands (clicking, typing, tabbing, networ
|
|
|
125
125
|
|
|
126
126
|
### `Error: Timed out waiting for Agent Daemon on port 32001`
|
|
127
127
|
- **Cause**: The Android container took too long to download or boot, or your machine is slow. (We wait 3 minutes by default).
|
|
128
|
-
- **Fix**: Run `agent
|
|
128
|
+
- **Fix**: Run `agent-browser stop` and try `agent-browser start` again. The Docker images might still be downloading in the background.
|
|
129
129
|
|
|
130
130
|
### `net::ERR_NAME_NOT_RESOLVED`
|
|
131
131
|
- **Cause**: The Android Emulator temporarily lost its internet connection after a Warm Boot.
|
package/dist/orchestrator.js
CHANGED
|
@@ -96,11 +96,8 @@ export class Orchestrator {
|
|
|
96
96
|
EMULATOR_SNAPSHOT_NAME: 'quickboot'
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
|
-
this.log("Waiting for Daemon Connection...");
|
|
100
|
-
if (agentCont)
|
|
101
|
-
await this.waitForLog(agentCont, "Daemon listening on TCP");
|
|
102
99
|
if (androidCont) {
|
|
103
|
-
this.log("Rehydrating Android network connection...");
|
|
100
|
+
this.log("Rehydrating Android network connection...", 'info');
|
|
104
101
|
try {
|
|
105
102
|
execSync(`docker exec "${androidCont}" adb shell cmd connectivity airplane-mode enable`, { stdio: 'ignore' });
|
|
106
103
|
await new Promise(r => setTimeout(r, 2000));
|
|
@@ -111,6 +108,9 @@ export class Orchestrator {
|
|
|
111
108
|
this.log(`Network rehydration warning: ${e}`, 'warn');
|
|
112
109
|
}
|
|
113
110
|
}
|
|
111
|
+
this.log("Waiting for Daemon Connection...");
|
|
112
|
+
if (agentCont)
|
|
113
|
+
await this.waitForLog(agentCont, "Daemon listening on TCP", 180000);
|
|
114
114
|
}
|
|
115
115
|
else {
|
|
116
116
|
// === COLD START ===
|
package/dist/orchestrator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orchestrator.js","sourceRoot":"","sources":["../src/orchestrator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAa,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/D,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AACnD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AACnD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,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OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;gBAC9B,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;oBACtC,YAAY,CAAC,KAAK,CAAC,CAAC;oBACpB,IAAI,CAAC,IAAI,EAAE,CAAC;oBACZ,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;gBACvB,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kritchoff/agent-browser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Headless browser automation CLI for AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,18 +18,10 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"prepare": "husky",
|
|
20
20
|
"version:sync": "node scripts/sync-version.js",
|
|
21
|
-
"version": "npm run version:sync
|
|
21
|
+
"version": "npm run version:sync",
|
|
22
22
|
"build": "tsc",
|
|
23
|
-
"build:native": "npm run version:sync && cargo build --release --manifest-path cli/Cargo.toml && node scripts/copy-native.js",
|
|
24
|
-
"build:linux": "npm run version:sync && docker compose -f docker/docker-compose.yml run --rm build-linux",
|
|
25
|
-
"build:macos": "npm run version:sync && (cargo build --release --manifest-path cli/Cargo.toml --target aarch64-apple-darwin & cargo build --release --manifest-path cli/Cargo.toml --target x86_64-apple-darwin & wait) && cp cli/target/aarch64-apple-darwin/release/agent-browser bin/agent-browser-darwin-arm64 && cp cli/target/x86_64-apple-darwin/release/agent-browser bin/agent-browser-darwin-x64",
|
|
26
|
-
"build:windows": "npm run version:sync && docker compose -f docker/docker-compose.yml run --rm build-windows",
|
|
27
|
-
"build:all-platforms": "npm run version:sync && (npm run build:linux & npm run build:windows & wait) && npm run build:macos",
|
|
28
23
|
"build:docker": "docker build -t agent-browser-builder -f docker/Dockerfile.build .",
|
|
29
|
-
"
|
|
30
|
-
"fast-reset": "./scripts/fast_reset.sh",
|
|
31
|
-
"sdk": "./sdk.sh",
|
|
32
|
-
"release": "npm run version:sync && npm run build && npm run build:all-platforms && npm publish",
|
|
24
|
+
"release": "npm run version:sync && npm run build && npm publish",
|
|
33
25
|
"prepublishOnly": "npm run build",
|
|
34
26
|
"start": "node dist/daemon.js",
|
|
35
27
|
"dev": "tsx src/daemon.ts",
|
|
@@ -38,7 +30,6 @@
|
|
|
38
30
|
"format:check": "prettier --check 'src/**/*.ts'",
|
|
39
31
|
"test": "vitest run",
|
|
40
32
|
"test:watch": "vitest",
|
|
41
|
-
"postinstall": "node scripts/postinstall.js",
|
|
42
33
|
"changeset": "changeset",
|
|
43
34
|
"ci:version": "changeset version && pnpm run version:sync && pnpm install --no-frozen-lockfile",
|
|
44
35
|
"ci:publish": "pnpm run version:sync && pnpm run build && changeset publish"
|
|
@@ -54,12 +45,12 @@
|
|
|
54
45
|
"license": "Apache-2.0",
|
|
55
46
|
"repository": {
|
|
56
47
|
"type": "git",
|
|
57
|
-
"url": "git+https://github.com/
|
|
48
|
+
"url": "git+https://github.com/kritchoff/agent-browser.git"
|
|
58
49
|
},
|
|
59
50
|
"bugs": {
|
|
60
|
-
"url": "https://github.com/
|
|
51
|
+
"url": "https://github.com/kritchoff/agent-browser/issues"
|
|
61
52
|
},
|
|
62
|
-
"homepage": "https://github.com/
|
|
53
|
+
"homepage": "https://github.com/kritchoff/agent-browser#readme",
|
|
63
54
|
"dependencies": {
|
|
64
55
|
"node-simctl": "^7.4.0",
|
|
65
56
|
"playwright-core": "^1.57.0",
|
|
Binary file
|
package/scripts/copy-native.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Copies the compiled Rust binary to bin/ with platform-specific naming
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { copyFileSync, existsSync, mkdirSync } from 'fs';
|
|
8
|
-
import { dirname, join } from 'path';
|
|
9
|
-
import { fileURLToPath } from 'url';
|
|
10
|
-
import { platform, arch } from 'os';
|
|
11
|
-
|
|
12
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
13
|
-
const projectRoot = join(__dirname, '..');
|
|
14
|
-
|
|
15
|
-
const sourceExt = platform() === 'win32' ? '.exe' : '';
|
|
16
|
-
const sourcePath = join(projectRoot, `cli/target/release/agent-browser${sourceExt}`);
|
|
17
|
-
const binDir = join(projectRoot, 'bin');
|
|
18
|
-
|
|
19
|
-
// Determine platform suffix
|
|
20
|
-
const platformKey = `${platform()}-${arch()}`;
|
|
21
|
-
const ext = platform() === 'win32' ? '.exe' : '';
|
|
22
|
-
const targetName = `agent-browser-${platformKey}${ext}`;
|
|
23
|
-
const targetPath = join(binDir, targetName);
|
|
24
|
-
|
|
25
|
-
if (!existsSync(sourcePath)) {
|
|
26
|
-
console.error(`Error: Native binary not found at ${sourcePath}`);
|
|
27
|
-
console.error('Run "cargo build --release --manifest-path cli/Cargo.toml" first');
|
|
28
|
-
process.exit(1);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (!existsSync(binDir)) {
|
|
32
|
-
mkdirSync(binDir, { recursive: true });
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
copyFileSync(sourcePath, targetPath);
|
|
36
|
-
console.log(`✓ Copied native binary to ${targetPath}`);
|
package/scripts/postinstall.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Postinstall script for agent-browser
|
|
5
|
-
*
|
|
6
|
-
* Downloads the platform-specific native binary if not present.
|
|
7
|
-
* On global installs, patches npm's bin entry to use the native binary directly:
|
|
8
|
-
* - Windows: Overwrites .cmd/.ps1 shims
|
|
9
|
-
* - Mac/Linux: Replaces symlink to point to native binary
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { existsSync, mkdirSync, chmodSync, createWriteStream, unlinkSync, writeFileSync, symlinkSync, lstatSync } from 'fs';
|
|
13
|
-
import { dirname, join } from 'path';
|
|
14
|
-
import { fileURLToPath } from 'url';
|
|
15
|
-
import { platform, arch } from 'os';
|
|
16
|
-
import { get } from 'https';
|
|
17
|
-
import { execSync } from 'child_process';
|
|
18
|
-
|
|
19
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
20
|
-
const projectRoot = join(__dirname, '..');
|
|
21
|
-
const binDir = join(projectRoot, 'bin');
|
|
22
|
-
|
|
23
|
-
// Platform detection
|
|
24
|
-
const platformKey = `${platform()}-${arch()}`;
|
|
25
|
-
const ext = platform() === 'win32' ? '.exe' : '';
|
|
26
|
-
const binaryName = `agent-browser-${platformKey}${ext}`;
|
|
27
|
-
const binaryPath = join(binDir, binaryName);
|
|
28
|
-
|
|
29
|
-
// Package info
|
|
30
|
-
const packageJson = JSON.parse(
|
|
31
|
-
(await import('fs')).readFileSync(join(projectRoot, 'package.json'), 'utf8')
|
|
32
|
-
);
|
|
33
|
-
const version = packageJson.version;
|
|
34
|
-
|
|
35
|
-
// GitHub release URL
|
|
36
|
-
const GITHUB_REPO = 'vercel-labs/agent-browser';
|
|
37
|
-
const DOWNLOAD_URL = `https://github.com/${GITHUB_REPO}/releases/download/v${version}/${binaryName}`;
|
|
38
|
-
|
|
39
|
-
async function downloadFile(url, dest) {
|
|
40
|
-
return new Promise((resolve, reject) => {
|
|
41
|
-
const file = createWriteStream(dest);
|
|
42
|
-
|
|
43
|
-
const request = (url) => {
|
|
44
|
-
get(url, (response) => {
|
|
45
|
-
// Handle redirects
|
|
46
|
-
if (response.statusCode === 301 || response.statusCode === 302) {
|
|
47
|
-
request(response.headers.location);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (response.statusCode !== 200) {
|
|
52
|
-
reject(new Error(`Failed to download: HTTP ${response.statusCode}`));
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
response.pipe(file);
|
|
57
|
-
file.on('finish', () => {
|
|
58
|
-
file.close();
|
|
59
|
-
resolve();
|
|
60
|
-
});
|
|
61
|
-
}).on('error', (err) => {
|
|
62
|
-
unlinkSync(dest);
|
|
63
|
-
reject(err);
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
request(url);
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
async function main() {
|
|
72
|
-
// Check if binary already exists
|
|
73
|
-
if (existsSync(binaryPath)) {
|
|
74
|
-
// Ensure binary is executable (npm doesn't preserve execute bit)
|
|
75
|
-
if (platform() !== 'win32') {
|
|
76
|
-
chmodSync(binaryPath, 0o755);
|
|
77
|
-
}
|
|
78
|
-
console.log(`✓ Native binary ready: ${binaryName}`);
|
|
79
|
-
|
|
80
|
-
// On global installs, fix npm's bin entry to use native binary directly
|
|
81
|
-
await fixGlobalInstallBin();
|
|
82
|
-
|
|
83
|
-
showPlaywrightReminder();
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Ensure bin directory exists
|
|
88
|
-
if (!existsSync(binDir)) {
|
|
89
|
-
mkdirSync(binDir, { recursive: true });
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
console.log(`Downloading native binary for ${platformKey}...`);
|
|
93
|
-
console.log(`URL: ${DOWNLOAD_URL}`);
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
await downloadFile(DOWNLOAD_URL, binaryPath);
|
|
97
|
-
|
|
98
|
-
// Make executable on Unix
|
|
99
|
-
if (platform() !== 'win32') {
|
|
100
|
-
chmodSync(binaryPath, 0o755);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
console.log(`✓ Downloaded native binary: ${binaryName}`);
|
|
104
|
-
} catch (err) {
|
|
105
|
-
console.log(`⚠ Could not download native binary: ${err.message}`);
|
|
106
|
-
console.log(` The CLI will use Node.js fallback (slightly slower startup)`);
|
|
107
|
-
console.log('');
|
|
108
|
-
console.log('To build the native binary locally:');
|
|
109
|
-
console.log(' 1. Install Rust: https://rustup.rs');
|
|
110
|
-
console.log(' 2. Run: npm run build:native');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// On global installs, fix npm's bin entry to use native binary directly
|
|
114
|
-
// This avoids the /bin/sh error on Windows and provides zero-overhead execution
|
|
115
|
-
await fixGlobalInstallBin();
|
|
116
|
-
|
|
117
|
-
showPlaywrightReminder();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function showPlaywrightReminder() {
|
|
121
|
-
console.log('');
|
|
122
|
-
console.log('╔═══════════════════════════════════════════════════════════════════════════╗');
|
|
123
|
-
console.log('║ To download browser binaries, run: ║');
|
|
124
|
-
console.log('║ ║');
|
|
125
|
-
console.log('║ npx playwright install chromium ║');
|
|
126
|
-
console.log('║ ║');
|
|
127
|
-
console.log('║ On Linux, include system dependencies with: ║');
|
|
128
|
-
console.log('║ ║');
|
|
129
|
-
console.log('║ npx playwright install --with-deps chromium ║');
|
|
130
|
-
console.log('║ ║');
|
|
131
|
-
console.log('╚═══════════════════════════════════════════════════════════════════════════╝');
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Fix npm's bin entry on global installs to use the native binary directly.
|
|
136
|
-
* This provides zero-overhead CLI execution for global installs.
|
|
137
|
-
*/
|
|
138
|
-
async function fixGlobalInstallBin() {
|
|
139
|
-
if (platform() === 'win32') {
|
|
140
|
-
await fixWindowsShims();
|
|
141
|
-
} else {
|
|
142
|
-
await fixUnixSymlink();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Fix npm symlink on Mac/Linux global installs.
|
|
148
|
-
* Replace the symlink to the JS wrapper with a symlink to the native binary.
|
|
149
|
-
*/
|
|
150
|
-
async function fixUnixSymlink() {
|
|
151
|
-
// Get npm's global bin directory (npm prefix -g + /bin)
|
|
152
|
-
let npmBinDir;
|
|
153
|
-
try {
|
|
154
|
-
const prefix = execSync('npm prefix -g', { encoding: 'utf8' }).trim();
|
|
155
|
-
npmBinDir = join(prefix, 'bin');
|
|
156
|
-
} catch {
|
|
157
|
-
return; // npm not available
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const symlinkPath = join(npmBinDir, 'agent-browser');
|
|
161
|
-
|
|
162
|
-
// Check if symlink exists (indicates global install)
|
|
163
|
-
try {
|
|
164
|
-
const stat = lstatSync(symlinkPath);
|
|
165
|
-
if (!stat.isSymbolicLink()) {
|
|
166
|
-
return; // Not a symlink, don't touch it
|
|
167
|
-
}
|
|
168
|
-
} catch {
|
|
169
|
-
return; // Symlink doesn't exist, not a global install
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Replace symlink to point directly to native binary
|
|
173
|
-
try {
|
|
174
|
-
unlinkSync(symlinkPath);
|
|
175
|
-
symlinkSync(binaryPath, symlinkPath);
|
|
176
|
-
console.log('✓ Optimized: symlink points to native binary (zero overhead)');
|
|
177
|
-
} catch (err) {
|
|
178
|
-
// Permission error or other issue - not critical, JS wrapper still works
|
|
179
|
-
console.log(`⚠ Could not optimize symlink: ${err.message}`);
|
|
180
|
-
console.log(' CLI will work via Node.js wrapper (slightly slower startup)');
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Fix npm-generated shims on Windows global installs.
|
|
186
|
-
* npm generates shims that try to run /bin/sh, which doesn't exist on Windows.
|
|
187
|
-
* We overwrite them to invoke the native .exe directly.
|
|
188
|
-
*/
|
|
189
|
-
async function fixWindowsShims() {
|
|
190
|
-
// Check if this is a global install by looking for npm's global prefix
|
|
191
|
-
let npmBinDir;
|
|
192
|
-
try {
|
|
193
|
-
npmBinDir = execSync('npm prefix -g', { encoding: 'utf8' }).trim();
|
|
194
|
-
} catch {
|
|
195
|
-
return; // Not a global install or npm not available
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// The shims are in the npm prefix directory (not prefix/bin on Windows)
|
|
199
|
-
const cmdShim = join(npmBinDir, 'agent-browser.cmd');
|
|
200
|
-
const ps1Shim = join(npmBinDir, 'agent-browser.ps1');
|
|
201
|
-
|
|
202
|
-
// Only fix if shims exist (indicates global install)
|
|
203
|
-
if (!existsSync(cmdShim)) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// Path to native binary relative to npm prefix
|
|
208
|
-
const relativeBinaryPath = 'node_modules\\agent-browser\\bin\\agent-browser-win32-x64.exe';
|
|
209
|
-
|
|
210
|
-
try {
|
|
211
|
-
// Overwrite .cmd shim
|
|
212
|
-
const cmdContent = `@ECHO off\r\n"%~dp0${relativeBinaryPath}" %*\r\n`;
|
|
213
|
-
writeFileSync(cmdShim, cmdContent);
|
|
214
|
-
|
|
215
|
-
// Overwrite .ps1 shim
|
|
216
|
-
const ps1Content = `#!/usr/bin/env pwsh
|
|
217
|
-
$basedir = Split-Path $MyInvocation.MyCommand.Definition -Parent
|
|
218
|
-
$exe = ""
|
|
219
|
-
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
|
|
220
|
-
$exe = ".exe"
|
|
221
|
-
}
|
|
222
|
-
& "$basedir/${relativeBinaryPath.replace(/\\/g, '/')}" $args
|
|
223
|
-
exit $LASTEXITCODE
|
|
224
|
-
`;
|
|
225
|
-
writeFileSync(ps1Shim, ps1Content);
|
|
226
|
-
|
|
227
|
-
console.log('✓ Optimized: shims point to native binary (zero overhead)');
|
|
228
|
-
} catch (err) {
|
|
229
|
-
// Permission error or other issue - not critical, JS wrapper still works
|
|
230
|
-
console.log(`⚠ Could not optimize shims: ${err.message}`);
|
|
231
|
-
console.log(' CLI will work via Node.js wrapper (slightly slower startup)');
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
main().catch(console.error);
|