site-agent-pro 1.0.7 → 1.0.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/dist/utils/browser.js +68 -4
- package/package.json +1 -2
package/dist/utils/browser.js
CHANGED
|
@@ -1,17 +1,72 @@
|
|
|
1
1
|
import { execSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
2
3
|
import { chromium } from "playwright";
|
|
3
|
-
import { info } from "./log.js";
|
|
4
|
+
import { info, warn } from "./log.js";
|
|
5
|
+
/**
|
|
6
|
+
* Discovers a system-installed Chrome/Chromium/Edge browser path.
|
|
7
|
+
*/
|
|
8
|
+
export function findSystemChrome() {
|
|
9
|
+
const envPaths = [
|
|
10
|
+
process.env.CHROME_PATH,
|
|
11
|
+
process.env.PUPPETEER_EXECUTABLE_PATH,
|
|
12
|
+
process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH
|
|
13
|
+
];
|
|
14
|
+
for (const p of envPaths) {
|
|
15
|
+
if (p && fs.existsSync(p))
|
|
16
|
+
return p;
|
|
17
|
+
}
|
|
18
|
+
const isMac = process.platform === "darwin";
|
|
19
|
+
const isWin = process.platform === "win32";
|
|
20
|
+
const isLinux = process.platform === "linux";
|
|
21
|
+
let standardPaths = [];
|
|
22
|
+
if (isMac) {
|
|
23
|
+
standardPaths = [
|
|
24
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
25
|
+
"/Applications/Chromium.app/Contents/MacOS/Chromium",
|
|
26
|
+
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
else if (isWin) {
|
|
30
|
+
const prefixes = [
|
|
31
|
+
process.env.LOCALAPPDATA,
|
|
32
|
+
process.env.PROGRAMFILES,
|
|
33
|
+
process.env["PROGRAMFILES(X86)"]
|
|
34
|
+
].filter(Boolean);
|
|
35
|
+
for (const prefix of prefixes) {
|
|
36
|
+
standardPaths.push(`${prefix}\\Google\\Chrome\\Application\\chrome.exe`, `${prefix}\\Chromium\\Application\\chrome.exe`, `${prefix}\\Microsoft\\Edge\\Application\\msedge.exe`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (isLinux) {
|
|
40
|
+
standardPaths = [
|
|
41
|
+
"/usr/bin/google-chrome",
|
|
42
|
+
"/usr/bin/google-chrome-stable",
|
|
43
|
+
"/usr/bin/chromium-browser",
|
|
44
|
+
"/usr/bin/chromium",
|
|
45
|
+
"/usr/bin/microsoft-edge-stable"
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
return standardPaths.find((p) => fs.existsSync(p));
|
|
49
|
+
}
|
|
4
50
|
/**
|
|
5
51
|
* Professional self-healing browser launcher.
|
|
6
|
-
*
|
|
52
|
+
* Tries system Chromium -> Playwright bundled -> Auto-installs if missing.
|
|
7
53
|
*/
|
|
8
54
|
export async function launchWithSelfHealing(launchOptions) {
|
|
55
|
+
const sysPath = findSystemChrome();
|
|
56
|
+
if (sysPath) {
|
|
57
|
+
try {
|
|
58
|
+
return await chromium.launch({ ...launchOptions, executablePath: sysPath });
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
warn(`System browser at ${sysPath} failed to launch: ${err.message}. Falling back to bundled Chromium.`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
9
64
|
try {
|
|
10
65
|
return await chromium.launch(launchOptions);
|
|
11
66
|
}
|
|
12
67
|
catch (err) {
|
|
13
68
|
if (err.message.includes("Executable doesn't exist") || err.message.includes("playwright install")) {
|
|
14
|
-
info("🚀 Playwright browser missing. Automatically installing Chromium...");
|
|
69
|
+
info("🚀 Bundled Playwright browser missing. Automatically installing Chromium...");
|
|
15
70
|
try {
|
|
16
71
|
execSync("npx playwright install chromium", { stdio: "inherit" });
|
|
17
72
|
info("✅ Browser installed successfully! Retrying launch...");
|
|
@@ -28,12 +83,21 @@ export async function launchWithSelfHealing(launchOptions) {
|
|
|
28
83
|
* Self-healing launcher for persistent context (e.g. for MetaMask/Web3 flows).
|
|
29
84
|
*/
|
|
30
85
|
export async function launchPersistentWithSelfHealing(userDataDir, options) {
|
|
86
|
+
const sysPath = findSystemChrome();
|
|
87
|
+
if (sysPath) {
|
|
88
|
+
try {
|
|
89
|
+
return await chromium.launchPersistentContext(userDataDir, { ...options, executablePath: sysPath });
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
warn(`System browser at ${sysPath} failed to launch: ${err.message}. Falling back to bundled Chromium.`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
31
95
|
try {
|
|
32
96
|
return await chromium.launchPersistentContext(userDataDir, options);
|
|
33
97
|
}
|
|
34
98
|
catch (err) {
|
|
35
99
|
if (err.message.includes("Executable doesn't exist") || err.message.includes("playwright install")) {
|
|
36
|
-
info("🚀 Playwright browser missing. Automatically installing Chromium...");
|
|
100
|
+
info("🚀 Bundled Playwright browser missing. Automatically installing Chromium...");
|
|
37
101
|
try {
|
|
38
102
|
execSync("npx playwright install chromium", { stdio: "inherit" });
|
|
39
103
|
info("✅ Browser installed successfully! Retrying launch...");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "site-agent-pro",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "AI-powered browser agent that tests websites like a real user and produces evidence-based, scored reports.",
|
|
6
6
|
"bin": {
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"format": "prettier --write .",
|
|
30
30
|
"lint": "eslint .",
|
|
31
31
|
"browser:install": "playwright install chromium",
|
|
32
|
-
"postinstall": "playwright install chromium",
|
|
33
32
|
"paystack:test": "tsx src/paystack/test-paystack.ts"
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|