alvin-bot 5.7.0 → 5.8.0
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/CHANGELOG.md +13 -0
- package/dist/claude.js +1 -102
- package/dist/config.js +1 -96
- package/dist/engine.js +1 -90
- package/dist/find-claude-binary.js +1 -98
- package/dist/handlers/async-agent-chunk-handler.js +1 -50
- package/dist/handlers/background-bypass.js +1 -75
- package/dist/handlers/commands.js +1 -2336
- package/dist/handlers/cron-progress.js +1 -52
- package/dist/handlers/document.js +1 -194
- package/dist/handlers/message.js +1 -959
- package/dist/handlers/photo.js +1 -154
- package/dist/handlers/platform-message.js +1 -360
- package/dist/handlers/stuck-timer.js +1 -54
- package/dist/handlers/video.js +1 -237
- package/dist/handlers/voice.js +1 -148
- package/dist/i18n.js +1 -805
- package/dist/index.js +1 -697
- package/dist/init-data-dir.js +1 -98
- package/dist/middleware/auth.js +1 -233
- package/dist/migrate.js +1 -162
- package/dist/paths.js +1 -146
- package/dist/platforms/discord.js +1 -175
- package/dist/platforms/index.js +1 -130
- package/dist/platforms/signal.js +1 -205
- package/dist/platforms/slack-slash-parser.js +1 -32
- package/dist/platforms/slack.js +1 -501
- package/dist/platforms/telegram.js +1 -111
- package/dist/platforms/types.js +1 -8
- package/dist/platforms/whatsapp-auth-helpers.js +1 -53
- package/dist/platforms/whatsapp.js +1 -707
- package/dist/providers/claude-sdk-provider.js +1 -565
- package/dist/providers/codex-cli-provider.js +1 -134
- package/dist/providers/index.js +1 -7
- package/dist/providers/ollama-provider.js +1 -32
- package/dist/providers/openai-compatible.js +1 -406
- package/dist/providers/registry.js +1 -352
- package/dist/providers/runtime-header.js +1 -45
- package/dist/providers/tool-executor.js +1 -475
- package/dist/providers/types.js +1 -227
- package/dist/services/access.js +1 -144
- package/dist/services/allowed-users-gate.js +1 -56
- package/dist/services/alvin-dispatch.js +1 -174
- package/dist/services/alvin-mcp-tools.js +1 -104
- package/dist/services/asset-index.js +1 -224
- package/dist/services/async-agent-parser.js +1 -418
- package/dist/services/async-agent-watcher.js +1 -583
- package/dist/services/auto-diagnostic.js +1 -228
- package/dist/services/broadcast.js +1 -52
- package/dist/services/browser-manager.js +1 -562
- package/dist/services/browser-webfetch.js +1 -127
- package/dist/services/browser.js +1 -121
- package/dist/services/cdp-bootstrap.js +1 -357
- package/dist/services/compaction.js +1 -144
- package/dist/services/critical-notify.js +1 -203
- package/dist/services/cron-resolver.js +1 -58
- package/dist/services/cron-scheduling.js +1 -310
- package/dist/services/cron.js +1 -861
- package/dist/services/custom-tools.js +1 -317
- package/dist/services/delivery-queue.js +1 -173
- package/dist/services/delivery-registry.js +1 -21
- package/dist/services/disk-cleanup.js +1 -203
- package/dist/services/elevenlabs.js +1 -58
- package/dist/services/embeddings/auto-detect.js +1 -74
- package/dist/services/embeddings/fts5.js +1 -108
- package/dist/services/embeddings/gemini.js +1 -65
- package/dist/services/embeddings/index.js +1 -496
- package/dist/services/embeddings/ollama.js +1 -78
- package/dist/services/embeddings/openai.js +1 -49
- package/dist/services/embeddings/provider.js +1 -22
- package/dist/services/embeddings/vector-base.js +1 -113
- package/dist/services/embeddings-migration.js +1 -193
- package/dist/services/embeddings.js +1 -9
- package/dist/services/env-file.js +1 -50
- package/dist/services/exec-guard.js +1 -71
- package/dist/services/fallback-order.js +1 -154
- package/dist/services/file-permissions.js +1 -93
- package/dist/services/heartbeat-file.js +1 -65
- package/dist/services/heartbeat.js +1 -313
- package/dist/services/hooks.js +1 -44
- package/dist/services/imagegen.js +1 -72
- package/dist/services/language-detect.js +1 -154
- package/dist/services/markdown.js +1 -63
- package/dist/services/mcp.js +1 -263
- package/dist/services/memory-extractor.js +1 -178
- package/dist/services/memory-inject-mode.js +1 -43
- package/dist/services/memory-layers.js +1 -156
- package/dist/services/memory.js +1 -146
- package/dist/services/ollama-manager.js +1 -339
- package/dist/services/permissions-wizard.js +1 -291
- package/dist/services/personality.js +1 -376
- package/dist/services/plugins.js +1 -171
- package/dist/services/preflight.js +1 -292
- package/dist/services/process-manager.js +1 -291
- package/dist/services/release-highlights.js +1 -79
- package/dist/services/reminders.js +1 -97
- package/dist/services/restart.js +1 -48
- package/dist/services/security-audit.js +1 -74
- package/dist/services/self-diagnosis.js +1 -272
- package/dist/services/self-search.js +1 -129
- package/dist/services/session-persistence.js +1 -237
- package/dist/services/session.js +1 -282
- package/dist/services/skills.js +1 -290
- package/dist/services/ssrf-guard.js +1 -162
- package/dist/services/standing-orders.js +1 -29
- package/dist/services/steer-channel.js +1 -46
- package/dist/services/stop-controller.js +1 -52
- package/dist/services/subagent-dedup.js +1 -86
- package/dist/services/subagent-delivery.js +1 -452
- package/dist/services/subagent-stats.js +1 -123
- package/dist/services/subagents.js +1 -814
- package/dist/services/sudo.js +1 -329
- package/dist/services/telegram.js +1 -158
- package/dist/services/timing-safe-bearer.js +1 -51
- package/dist/services/tool-discovery.js +1 -214
- package/dist/services/trends.js +1 -580
- package/dist/services/updater.js +1 -291
- package/dist/services/usage-tracker.js +1 -144
- package/dist/services/users.js +1 -271
- package/dist/services/voice.js +1 -104
- package/dist/services/watchdog-brake.js +1 -154
- package/dist/services/watchdog.js +1 -311
- package/dist/services/workspaces.js +1 -276
- package/dist/tui/index.js +1 -667
- package/dist/util/console-formatter.js +1 -109
- package/dist/util/debounce.js +1 -24
- package/dist/util/telegram-error-filter.js +1 -62
- package/dist/version.js +1 -24
- package/dist/web/bind-strategy.js +1 -42
- package/dist/web/canvas.js +1 -30
- package/dist/web/doctor-api.js +1 -604
- package/dist/web/openai-compat.js +1 -252
- package/dist/web/server.js +1 -1902
- package/dist/web/setup-api.js +1 -1101
- package/package.json +5 -2
- package/dist/.metadata_never_index +0 -0
|
@@ -1,562 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Multi-Strategy Browser Manager — with automatic fallback chain.
|
|
3
|
-
*
|
|
4
|
-
* Strategy priority:
|
|
5
|
-
* 1. Gateway (browse-server.cjs HTTP server) — if script exists and is running
|
|
6
|
-
* 2. CDP (Chrome DevTools Protocol) — via hub browser.sh cdp, persistent cookies
|
|
7
|
-
* 3. Hub Stealth (Playwright + stealth plugin) — via hub browser.sh stealth
|
|
8
|
-
* 4. Raw CLI (bare Playwright) — last resort, easily blocked
|
|
9
|
-
*
|
|
10
|
-
* If a strategy is unavailable, we automatically cascade to the next one
|
|
11
|
-
* and log a warning so failures are visible, not silent.
|
|
12
|
-
*/
|
|
13
|
-
import { execSync, execFileSync, spawn } from "child_process";
|
|
14
|
-
import http from "http";
|
|
15
|
-
import fs from "fs";
|
|
16
|
-
import { config } from "../config.js";
|
|
17
|
-
import { BROWSE_SERVER_SCRIPT, HUB_BROWSER_SH } from "../paths.js";
|
|
18
|
-
import { screenshotUrl, extractText, generatePdf } from "./browser.js";
|
|
19
|
-
import { webfetchNavigate, WebfetchFailed } from "./browser-webfetch.js";
|
|
20
|
-
import * as cdpBootstrap from "./cdp-bootstrap.js";
|
|
21
|
-
const CDP_PORT = 9222;
|
|
22
|
-
const EXEC_TIMEOUT = 60_000; // 60s for page loads via shell
|
|
23
|
-
// ── Logging ──────────────────────────────────────────────────────────
|
|
24
|
-
function log(msg) {
|
|
25
|
-
console.log(`[browser-manager] ${msg}`);
|
|
26
|
-
}
|
|
27
|
-
// ── Availability Checks ──────────────────────────────────────────────
|
|
28
|
-
function isGatewayScriptPresent() {
|
|
29
|
-
return fs.existsSync(BROWSE_SERVER_SCRIPT);
|
|
30
|
-
}
|
|
31
|
-
async function isGatewayRunning() {
|
|
32
|
-
try {
|
|
33
|
-
const health = await gatewayRequest("/health");
|
|
34
|
-
return !!health?.ok;
|
|
35
|
-
}
|
|
36
|
-
catch {
|
|
37
|
-
return false;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function isHubBrowserAvailable() {
|
|
41
|
-
return fs.existsSync(HUB_BROWSER_SH);
|
|
42
|
-
}
|
|
43
|
-
async function isCDPAvailable() {
|
|
44
|
-
return new Promise((resolve) => {
|
|
45
|
-
const req = http.get(`http://127.0.0.1:${CDP_PORT}/json/version`, (res) => {
|
|
46
|
-
let data = "";
|
|
47
|
-
res.on("data", (chunk) => (data += chunk));
|
|
48
|
-
res.on("end", () => resolve(res.statusCode === 200));
|
|
49
|
-
});
|
|
50
|
-
req.on("error", () => resolve(false));
|
|
51
|
-
req.setTimeout(3000, () => {
|
|
52
|
-
req.destroy();
|
|
53
|
-
resolve(false);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
// ── Strategy Selection with Fallback ─────────────────────────────────
|
|
58
|
-
/** Pick the preferred strategy based on task type.
|
|
59
|
-
*
|
|
60
|
-
* Default for a one-shot read is `webfetch` — the cheapest tier. It
|
|
61
|
-
* only fails on JS-heavy or bot-guarded pages, and the cascade in
|
|
62
|
-
* resolveStrategy() handles the upgrade path automatically.
|
|
63
|
-
*/
|
|
64
|
-
export function selectStrategy(task = {}) {
|
|
65
|
-
if (task.useUserBrowser || config.cdpUrl)
|
|
66
|
-
return "cdp";
|
|
67
|
-
if (task.interactive || task.multiStep)
|
|
68
|
-
return "gateway";
|
|
69
|
-
return "webfetch";
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Resolve the preferred strategy to one that's actually available.
|
|
73
|
-
*
|
|
74
|
-
* Cascade order:
|
|
75
|
-
* webfetch → hub-stealth → cdp → gateway → cli
|
|
76
|
-
*
|
|
77
|
-
* Rationale:
|
|
78
|
-
* - `webfetch` is a plain HTTP GET — instant, zero footprint.
|
|
79
|
-
* - `hub-stealth` (playwright+stealth) handles JS-rendered pages
|
|
80
|
-
* without a persistent browser process.
|
|
81
|
-
* - `cdp` brings cookies/auth for login-walled sites.
|
|
82
|
-
* - `gateway` exposes the multi-step HTTP API (ref-based ops, long
|
|
83
|
-
* sessions) when the browse-server.cjs helper is available.
|
|
84
|
-
* - `cli` (raw Playwright) is the last-resort fallback.
|
|
85
|
-
*/
|
|
86
|
-
export async function resolveStrategy(preferred) {
|
|
87
|
-
const chain = [];
|
|
88
|
-
// Build fallback chain starting from preferred. webfetch and
|
|
89
|
-
// hub-stealth are always available (no external state check), so
|
|
90
|
-
// they're included as floor entries. CDP/gateway only get in if the
|
|
91
|
-
// caller asked for them explicitly, since they need running daemons.
|
|
92
|
-
switch (preferred) {
|
|
93
|
-
case "webfetch":
|
|
94
|
-
chain.push("webfetch", "hub-stealth", "cli");
|
|
95
|
-
break;
|
|
96
|
-
case "gateway":
|
|
97
|
-
chain.push("gateway", "cdp", "hub-stealth", "webfetch", "cli");
|
|
98
|
-
break;
|
|
99
|
-
case "cdp":
|
|
100
|
-
chain.push("cdp", "hub-stealth", "webfetch", "cli");
|
|
101
|
-
break;
|
|
102
|
-
case "hub-stealth":
|
|
103
|
-
chain.push("hub-stealth", "webfetch", "cli");
|
|
104
|
-
break;
|
|
105
|
-
case "cli":
|
|
106
|
-
chain.push("cli");
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
for (const strategy of chain) {
|
|
110
|
-
switch (strategy) {
|
|
111
|
-
case "webfetch":
|
|
112
|
-
// Native fetch is always present on Node ≥ 18 — no availability
|
|
113
|
-
// probe needed. Each call is self-contained, so we return the
|
|
114
|
-
// strategy tag and let navigate() handle per-call errors.
|
|
115
|
-
return "webfetch";
|
|
116
|
-
case "gateway":
|
|
117
|
-
if (isGatewayScriptPresent() && (await isGatewayRunning()))
|
|
118
|
-
return "gateway";
|
|
119
|
-
if (!isGatewayScriptPresent()) {
|
|
120
|
-
log("Gateway unavailable: browse-server.cjs not found. Falling back.");
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
log("Gateway not running. Falling back.");
|
|
124
|
-
}
|
|
125
|
-
break;
|
|
126
|
-
case "cdp":
|
|
127
|
-
if (await isCDPAvailable())
|
|
128
|
-
return "cdp";
|
|
129
|
-
// Bot-owned bootstrap is the primary path — works for every install,
|
|
130
|
-
// no Hub dependency, no conflict with user's own Chrome.
|
|
131
|
-
try {
|
|
132
|
-
log("CDP not running — starting bot-managed Chromium via cdp-bootstrap...");
|
|
133
|
-
await cdpBootstrap.ensureRunning({ mode: "headless" });
|
|
134
|
-
if (await isCDPAvailable()) {
|
|
135
|
-
log("CDP bootstrap started successfully.");
|
|
136
|
-
return "cdp";
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
catch (err) {
|
|
140
|
-
log(`CDP bootstrap failed: ${err.message}`);
|
|
141
|
-
}
|
|
142
|
-
// Dev-only fallback: maintainer Hub script, if present
|
|
143
|
-
if (isHubBrowserAvailable()) {
|
|
144
|
-
try {
|
|
145
|
-
log("Trying Hub script as fallback...");
|
|
146
|
-
execSync(`"${HUB_BROWSER_SH}" cdp start headless`, {
|
|
147
|
-
stdio: "pipe",
|
|
148
|
-
timeout: 15_000,
|
|
149
|
-
});
|
|
150
|
-
await new Promise((r) => setTimeout(r, 3000));
|
|
151
|
-
if (await isCDPAvailable()) {
|
|
152
|
-
log("CDP via Hub script.");
|
|
153
|
-
return "cdp";
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
catch (err) {
|
|
157
|
-
log(`Hub script fallback failed: ${err.message}`);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
log("CDP unavailable. Falling back.");
|
|
161
|
-
break;
|
|
162
|
-
case "hub-stealth":
|
|
163
|
-
if (isHubBrowserAvailable())
|
|
164
|
-
return "hub-stealth";
|
|
165
|
-
log("Hub browser.sh not found. Falling back to raw Playwright.");
|
|
166
|
-
break;
|
|
167
|
-
case "cli":
|
|
168
|
-
return "cli"; // Always available as last resort
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return "cli";
|
|
172
|
-
}
|
|
173
|
-
function execHub(argv) {
|
|
174
|
-
try {
|
|
175
|
-
// H3: use execFileSync with discrete argv array — no shell interpolation,
|
|
176
|
-
// so attacker-controlled URLs cannot inject shell metacharacters.
|
|
177
|
-
const result = execFileSync(HUB_BROWSER_SH, argv, {
|
|
178
|
-
stdio: "pipe",
|
|
179
|
-
timeout: EXEC_TIMEOUT,
|
|
180
|
-
env: { ...process.env, PATH: process.env.PATH },
|
|
181
|
-
});
|
|
182
|
-
const stdout = result.toString().trim();
|
|
183
|
-
// Try to parse as JSON (stealth outputs JSON)
|
|
184
|
-
try {
|
|
185
|
-
return JSON.parse(stdout);
|
|
186
|
-
}
|
|
187
|
-
catch {
|
|
188
|
-
// Not JSON — return as raw text
|
|
189
|
-
return { title: "", url: "", raw: stdout };
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
catch (err) {
|
|
193
|
-
const error = err;
|
|
194
|
-
log(`Hub script failed: ${error.stderr?.toString()?.trim() || error.message}`);
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
// ── Gateway Management ───────────────────────────────────────────────
|
|
199
|
-
let gatewayProcess = null;
|
|
200
|
-
async function gatewayRequest(urlPath, params = {}, timeoutMs = 15_000) {
|
|
201
|
-
const query = new URLSearchParams(params).toString();
|
|
202
|
-
const url = `http://127.0.0.1:${config.browseServerPort}${urlPath}${query ? "?" + query : ""}`;
|
|
203
|
-
return new Promise((resolve, reject) => {
|
|
204
|
-
const req = http.get(url, (res) => {
|
|
205
|
-
let data = "";
|
|
206
|
-
res.on("data", (chunk) => (data += chunk));
|
|
207
|
-
res.on("end", () => {
|
|
208
|
-
try {
|
|
209
|
-
resolve(JSON.parse(data));
|
|
210
|
-
}
|
|
211
|
-
catch {
|
|
212
|
-
reject(new Error(`Invalid JSON from gateway: ${data.slice(0, 200)}`));
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
req.on("error", reject);
|
|
217
|
-
req.setTimeout(timeoutMs, () => {
|
|
218
|
-
req.destroy(new Error(`Gateway request timed out after ${timeoutMs}ms: ${urlPath}`));
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
async function ensureGateway() {
|
|
223
|
-
// Check if already running
|
|
224
|
-
if (await isGatewayRunning())
|
|
225
|
-
return true;
|
|
226
|
-
// Try to start it
|
|
227
|
-
if (!isGatewayScriptPresent()) {
|
|
228
|
-
log("Cannot start gateway: browse-server.cjs not found.");
|
|
229
|
-
return false;
|
|
230
|
-
}
|
|
231
|
-
gatewayProcess = spawn("node", [BROWSE_SERVER_SCRIPT, String(config.browseServerPort)], {
|
|
232
|
-
stdio: "pipe",
|
|
233
|
-
detached: false,
|
|
234
|
-
});
|
|
235
|
-
gatewayProcess.on("exit", () => {
|
|
236
|
-
gatewayProcess = null;
|
|
237
|
-
});
|
|
238
|
-
// Surface spawn failures so we don't silently think the gateway is running.
|
|
239
|
-
gatewayProcess.on("error", (err) => {
|
|
240
|
-
log(`gateway spawn error: ${err.message}`);
|
|
241
|
-
gatewayProcess = null;
|
|
242
|
-
});
|
|
243
|
-
// Drain stdio pipes — otherwise stdout/stderr buffer fills and the child
|
|
244
|
-
// blocks on write. We don't care about the content (just that they drain).
|
|
245
|
-
gatewayProcess.stdout?.on("error", () => { });
|
|
246
|
-
gatewayProcess.stderr?.on("error", () => { });
|
|
247
|
-
gatewayProcess.stdout?.resume();
|
|
248
|
-
gatewayProcess.stderr?.resume();
|
|
249
|
-
// Wait for startup (max 10s)
|
|
250
|
-
for (let i = 0; i < 20; i++) {
|
|
251
|
-
await new Promise((r) => setTimeout(r, 500));
|
|
252
|
-
if (await isGatewayRunning())
|
|
253
|
-
return true;
|
|
254
|
-
}
|
|
255
|
-
log("Gateway failed to start within 10s.");
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
// ── Unified Operations ───────────────────────────────────────────────
|
|
259
|
-
/** Navigate to URL using best available strategy.
|
|
260
|
-
*
|
|
261
|
-
* Error-based cascade: if the chosen tier throws, we walk DOWN the
|
|
262
|
-
* priority chain until one succeeds or we exhaust the list. This lets
|
|
263
|
-
* a 403 from webfetch transparently upgrade to hub-stealth without
|
|
264
|
-
* callers having to know about the fallback graph.
|
|
265
|
-
*/
|
|
266
|
-
export async function navigate(url, task = {}) {
|
|
267
|
-
const primary = await resolveStrategy(selectStrategy(task));
|
|
268
|
-
log(`navigate(${url}) using strategy: ${primary}`);
|
|
269
|
-
// Try primary, then hub-stealth as a universal fallback. We keep the
|
|
270
|
-
// fallback list short here to avoid cascading timeouts — the full
|
|
271
|
-
// cascade is only for resolveStrategy's availability check.
|
|
272
|
-
const attempt = async (strategy) => {
|
|
273
|
-
return navigateOne(strategy, url);
|
|
274
|
-
};
|
|
275
|
-
try {
|
|
276
|
-
return await attempt(primary);
|
|
277
|
-
}
|
|
278
|
-
catch (err) {
|
|
279
|
-
log(`navigate(${url}) ${primary} failed: ${err.message}`);
|
|
280
|
-
if (primary === "webfetch") {
|
|
281
|
-
// Webfetch is the most common tier and the most common to hit a
|
|
282
|
-
// bot guard — cascade to hub-stealth explicitly, then cli.
|
|
283
|
-
try {
|
|
284
|
-
return await attempt("hub-stealth");
|
|
285
|
-
}
|
|
286
|
-
catch (err2) {
|
|
287
|
-
log(`navigate(${url}) hub-stealth fallback failed: ${err2.message}`);
|
|
288
|
-
return await attempt("cli");
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
throw err;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
/** Single-strategy navigate — no fallback logic, just do the thing. */
|
|
295
|
-
async function navigateOne(strategy, url) {
|
|
296
|
-
switch (strategy) {
|
|
297
|
-
case "webfetch": {
|
|
298
|
-
try {
|
|
299
|
-
const r = await webfetchNavigate(url);
|
|
300
|
-
return { title: r.title, url: r.url };
|
|
301
|
-
}
|
|
302
|
-
catch (err) {
|
|
303
|
-
if (err instanceof WebfetchFailed)
|
|
304
|
-
throw err;
|
|
305
|
-
throw new WebfetchFailed(url, err.message, { cause: err });
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
case "gateway": {
|
|
309
|
-
await ensureGateway();
|
|
310
|
-
return gatewayRequest("/navigate", { url });
|
|
311
|
-
}
|
|
312
|
-
case "cdp": {
|
|
313
|
-
// Try hub CDP first
|
|
314
|
-
if (isHubBrowserAvailable()) {
|
|
315
|
-
const result = execHub(["cdp", "goto", url]);
|
|
316
|
-
if (result && !result.error) {
|
|
317
|
-
return { title: result.title || "", url: result.url || url };
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
// Fallback: direct Playwright CDP
|
|
321
|
-
try {
|
|
322
|
-
const { chromium } = await import("playwright");
|
|
323
|
-
const browser = await chromium.connectOverCDP(config.cdpUrl || `http://127.0.0.1:${CDP_PORT}`);
|
|
324
|
-
const contexts = browser.contexts();
|
|
325
|
-
const page = contexts[0]?.pages()[0] || (await contexts[0]?.newPage()) || (await browser.newPage());
|
|
326
|
-
await page.goto(url, { waitUntil: "networkidle", timeout: 30000 });
|
|
327
|
-
const title = await page.title();
|
|
328
|
-
return { title, url: page.url() };
|
|
329
|
-
}
|
|
330
|
-
catch (err) {
|
|
331
|
-
log(`Direct CDP failed: ${err.message}`);
|
|
332
|
-
// Last resort: try stealth
|
|
333
|
-
if (isHubBrowserAvailable()) {
|
|
334
|
-
const stealthResult = execHub(["stealth", url]);
|
|
335
|
-
if (stealthResult) {
|
|
336
|
-
return { title: stealthResult.title || "", url: stealthResult.url || url };
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
throw err;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
case "hub-stealth": {
|
|
343
|
-
const result = execHub(["stealth", url]);
|
|
344
|
-
if (result && !result.error) {
|
|
345
|
-
return { title: result.title || "", url: result.url || url };
|
|
346
|
-
}
|
|
347
|
-
// Fallback to raw CLI
|
|
348
|
-
log("Hub stealth failed, falling back to raw Playwright.");
|
|
349
|
-
const text = await extractText(url);
|
|
350
|
-
return { title: url, url, tree: [text.slice(0, 500)] };
|
|
351
|
-
}
|
|
352
|
-
case "cli":
|
|
353
|
-
default: {
|
|
354
|
-
const text = await extractText(url);
|
|
355
|
-
return { title: url, url, tree: [text.slice(0, 500)] };
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
/** Take a screenshot */
|
|
360
|
-
export async function screenshot(url, options = {}) {
|
|
361
|
-
const strategy = await resolveStrategy(selectStrategy());
|
|
362
|
-
log(`screenshot(${url}) using strategy: ${strategy}`);
|
|
363
|
-
switch (strategy) {
|
|
364
|
-
case "gateway": {
|
|
365
|
-
await ensureGateway();
|
|
366
|
-
if (url)
|
|
367
|
-
await gatewayRequest("/navigate", { url });
|
|
368
|
-
const result = await gatewayRequest("/screenshot", options.fullPage ? { full: "true" } : {});
|
|
369
|
-
return result.path;
|
|
370
|
-
}
|
|
371
|
-
case "cdp": {
|
|
372
|
-
if (isHubBrowserAvailable()) {
|
|
373
|
-
const tmpName = `shot_${Date.now()}.png`;
|
|
374
|
-
const result = execHub(["cdp", "shot", url, tmpName]);
|
|
375
|
-
if (result?.screenshot)
|
|
376
|
-
return result.screenshot;
|
|
377
|
-
}
|
|
378
|
-
// Fallback to raw Playwright
|
|
379
|
-
return screenshotUrl(url, { fullPage: options.fullPage });
|
|
380
|
-
}
|
|
381
|
-
case "hub-stealth": {
|
|
382
|
-
const tmpName = `shot_${Date.now()}.png`;
|
|
383
|
-
const result = execHub(["stealth", url, `--screenshot=${tmpName}`]);
|
|
384
|
-
if (result?.screenshot)
|
|
385
|
-
return result.screenshot;
|
|
386
|
-
// Fallback
|
|
387
|
-
return screenshotUrl(url, { fullPage: options.fullPage });
|
|
388
|
-
}
|
|
389
|
-
case "cli":
|
|
390
|
-
default:
|
|
391
|
-
return screenshotUrl(url, { fullPage: options.fullPage });
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
// ── CDP Direct-Playwright Helper ─────────────────────────────────────
|
|
395
|
-
// Used as fallback when the gateway isn't running but CDP Chrome is.
|
|
396
|
-
// Each call opens a short-lived CDP connection, operates on the newest
|
|
397
|
-
// existing page in the current context (keeps Chrome itself alive), and
|
|
398
|
-
// disconnects. Safe for sub-agents that need a single op at a time.
|
|
399
|
-
async function withCdpPage(fn) {
|
|
400
|
-
const { chromium } = await import("playwright");
|
|
401
|
-
const browser = await chromium.connectOverCDP(config.cdpUrl || `http://127.0.0.1:${CDP_PORT}`);
|
|
402
|
-
try {
|
|
403
|
-
const context = browser.contexts()[0];
|
|
404
|
-
if (!context)
|
|
405
|
-
throw new Error("No CDP contexts available — is Chrome CDP running?");
|
|
406
|
-
const pages = context.pages();
|
|
407
|
-
const page = pages[pages.length - 1] || (await context.newPage());
|
|
408
|
-
return await fn(page);
|
|
409
|
-
}
|
|
410
|
-
finally {
|
|
411
|
-
await browser.close(); // Closes CDP connection, not Chrome itself
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
const NEEDS_INTERACTIVE_HINT = "Start CDP: alvin-bot browser start (headless by default)";
|
|
415
|
-
/**
|
|
416
|
-
* Get accessibility tree (gateway preferred, CDP fallback returns outerHTML).
|
|
417
|
-
* The @eN ref model only exists in the gateway; under CDP we return a
|
|
418
|
-
* best-effort DOM snippet instead so callers can still see what's there.
|
|
419
|
-
*/
|
|
420
|
-
export async function getTree(limit = 100) {
|
|
421
|
-
if (await isGatewayRunning()) {
|
|
422
|
-
return gatewayRequest("/tree", { limit: String(limit) });
|
|
423
|
-
}
|
|
424
|
-
if (await isCDPAvailable()) {
|
|
425
|
-
return withCdpPage(async (page) => {
|
|
426
|
-
const elements = await page.$$eval("a, button, input, select, textarea, [role=button], [role=link]", (els, max) => els.slice(0, max).map((el, i) => {
|
|
427
|
-
const tag = el.tagName.toLowerCase();
|
|
428
|
-
const text = (el.textContent || "").trim().slice(0, 60);
|
|
429
|
-
const id = el.id ? `#${el.id}` : "";
|
|
430
|
-
const name = el.name
|
|
431
|
-
? `[name=${el.name}]`
|
|
432
|
-
: "";
|
|
433
|
-
return `@e${i + 1} <${tag}${id}${name}> "${text}"`;
|
|
434
|
-
}), limit);
|
|
435
|
-
return { tree: elements, total: elements.length };
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
throw new Error(`[browser-manager] getTree requires gateway or CDP. ${NEEDS_INTERACTIVE_HINT}`);
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Click an element. Accepts a gateway ref (@eN → "eN") when gateway is
|
|
442
|
-
* running, or a CSS selector when only CDP is available.
|
|
443
|
-
*/
|
|
444
|
-
export async function click(refOrSelector) {
|
|
445
|
-
if (await isGatewayRunning()) {
|
|
446
|
-
return gatewayRequest("/click", { ref: refOrSelector });
|
|
447
|
-
}
|
|
448
|
-
if (await isCDPAvailable()) {
|
|
449
|
-
return withCdpPage(async (page) => {
|
|
450
|
-
await page.click(refOrSelector, { timeout: 10_000 });
|
|
451
|
-
return { title: await page.title(), url: page.url() };
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
throw new Error(`[browser-manager] click() requires gateway or CDP. ${NEEDS_INTERACTIVE_HINT}`);
|
|
455
|
-
}
|
|
456
|
-
/** Fill an input. refOrSelector semantics match click(). */
|
|
457
|
-
export async function fill(refOrSelector, value) {
|
|
458
|
-
if (await isGatewayRunning()) {
|
|
459
|
-
await gatewayRequest("/fill", { ref: refOrSelector, value });
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
if (await isCDPAvailable()) {
|
|
463
|
-
await withCdpPage(async (page) => {
|
|
464
|
-
await page.fill(refOrSelector, value, { timeout: 10_000 });
|
|
465
|
-
});
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
468
|
-
throw new Error(`[browser-manager] fill() requires gateway or CDP. ${NEEDS_INTERACTIVE_HINT}`);
|
|
469
|
-
}
|
|
470
|
-
/** Type text character-by-character (for inputs that reject page.fill). */
|
|
471
|
-
export async function type(refOrSelector, text) {
|
|
472
|
-
if (await isGatewayRunning()) {
|
|
473
|
-
await gatewayRequest("/type", { ref: refOrSelector, text });
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
if (await isCDPAvailable()) {
|
|
477
|
-
await withCdpPage(async (page) => {
|
|
478
|
-
await page.type(refOrSelector, text, { timeout: 10_000 });
|
|
479
|
-
});
|
|
480
|
-
return;
|
|
481
|
-
}
|
|
482
|
-
throw new Error(`[browser-manager] type() requires gateway or CDP. ${NEEDS_INTERACTIVE_HINT}`);
|
|
483
|
-
}
|
|
484
|
-
/** Press a keyboard key (page-level if no ref, element-level with ref). */
|
|
485
|
-
export async function press(key, refOrSelector) {
|
|
486
|
-
if (await isGatewayRunning()) {
|
|
487
|
-
await gatewayRequest("/press", refOrSelector ? { key, ref: refOrSelector } : { key });
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
if (await isCDPAvailable()) {
|
|
491
|
-
await withCdpPage(async (page) => {
|
|
492
|
-
if (refOrSelector) {
|
|
493
|
-
await page.locator(refOrSelector).press(key, { timeout: 10_000 });
|
|
494
|
-
}
|
|
495
|
-
else {
|
|
496
|
-
await page.keyboard.press(key);
|
|
497
|
-
}
|
|
498
|
-
});
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
throw new Error(`[browser-manager] press() requires gateway or CDP. ${NEEDS_INTERACTIVE_HINT}`);
|
|
502
|
-
}
|
|
503
|
-
/** Scroll page. CDP fallback uses window.scrollBy. */
|
|
504
|
-
export async function scroll(direction, amount = 600) {
|
|
505
|
-
if (await isGatewayRunning()) {
|
|
506
|
-
return gatewayRequest("/scroll", { direction, amount: String(amount) });
|
|
507
|
-
}
|
|
508
|
-
if (await isCDPAvailable()) {
|
|
509
|
-
return withCdpPage(async (page) => {
|
|
510
|
-
const delta = direction === "up" ? -amount :
|
|
511
|
-
direction === "top" ? -1e9 :
|
|
512
|
-
direction === "bottom" ? 1e9 :
|
|
513
|
-
amount;
|
|
514
|
-
await page.evaluate((d) => window.scrollBy(0, d), delta);
|
|
515
|
-
return { title: await page.title(), url: page.url() };
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
throw new Error(`[browser-manager] scroll() requires gateway or CDP. ${NEEDS_INTERACTIVE_HINT}`);
|
|
519
|
-
}
|
|
520
|
-
/** Evaluate JS in the page context. */
|
|
521
|
-
export async function evaluate(js) {
|
|
522
|
-
if (await isGatewayRunning()) {
|
|
523
|
-
const result = await gatewayRequest("/eval", { js });
|
|
524
|
-
return result.result;
|
|
525
|
-
}
|
|
526
|
-
if (await isCDPAvailable()) {
|
|
527
|
-
return withCdpPage(async (page) => {
|
|
528
|
-
// `page.evaluate(fn)` wraps a function — we need eval of a raw
|
|
529
|
-
// expression string, so wrap in an IIFE.
|
|
530
|
-
return page.evaluate(new Function(`return (${js})`));
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
throw new Error(`[browser-manager] evaluate() requires gateway or CDP. ${NEEDS_INTERACTIVE_HINT}`);
|
|
534
|
-
}
|
|
535
|
-
/** Generate PDF from URL */
|
|
536
|
-
export async function pdf(url) {
|
|
537
|
-
return generatePdf(url);
|
|
538
|
-
}
|
|
539
|
-
/** Close browser / stop gateway */
|
|
540
|
-
export async function close() {
|
|
541
|
-
try {
|
|
542
|
-
await gatewayRequest("/close");
|
|
543
|
-
}
|
|
544
|
-
catch { }
|
|
545
|
-
if (gatewayProcess) {
|
|
546
|
-
gatewayProcess.kill();
|
|
547
|
-
gatewayProcess = null;
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
/** Get current page info (gateway preferred, CDP fallback reads newest page). */
|
|
551
|
-
export async function info() {
|
|
552
|
-
if (await isGatewayRunning()) {
|
|
553
|
-
return gatewayRequest("/info");
|
|
554
|
-
}
|
|
555
|
-
if (await isCDPAvailable()) {
|
|
556
|
-
return withCdpPage(async (page) => ({
|
|
557
|
-
title: await page.title(),
|
|
558
|
-
url: page.url(),
|
|
559
|
-
}));
|
|
560
|
-
}
|
|
561
|
-
throw new Error(`[browser-manager] info() requires gateway or CDP. ${NEEDS_INTERACTIVE_HINT}`);
|
|
562
|
-
}
|
|
1
|
+
function _0x32b4(){const _0x352725=['lJaUmc4XoG','mtvrsfDxtLu','igjYB3DZzs1Zzq','DcbYDw5UAw5NlG','q0rqig5VDcbYDq','CMvZigDHDgv3yq','igjYB3DZzxiGCW','igLUChv0lcbZzq','Bg9JyxrVCG','zxjYB3i','DhjPBq','l2nSAwnR','AwXLzcb0BYbZDa','EsbVCIbdrfaUia','C3rLywX0Aa','zw5K','y29UC3rYDwn0BW','rfaUia','CMfWihn0yxj0zq','nJmXnZaYDuncEu5h','zxHPDa','yxKGB3iGq0rqlG','D3jPz2H0lG','y2XPy2S','BM90igzVDw5KlG','BgWOksbYzxf1Aq','D3nLCG','BgfIBguUiezHBa','BxvSDgLtDgvW','Dgv3yxK6ia','BMfTzq','DgfYDcaOAgvHza','igzHAwXLzdOG','odmXoda2ne1JCwvwCq','Aw5NigjHy2SGDa','zxj2zxiUy2PZia','CNzLCI5JANmGBG','ienOCM9Tzsbdra','Bxm6ia','CguOksbYzxf1Aq','zNvSBfbHz2u','C2v0vgLTzw91Da','z290BW','mtiZodmWnerRCgDwrG','C3rKzxjY','y2rWvxjS','Cgf0Aa','BMv3ugfNzq','CgLWzq','lw1HBMfNzwqGqW','shvIihn0zwfSDa','A2v5yM9HCMq','Ahr0CdOVlZeYnW','r2f0zxDHEsbYzq','w2jYB3DZzxiTBq','kcGOlISPkYKRkq','ugXHExDYAwDODa','Dgv4DenVBNrLBG','C2vHCMnO','BMf2AwDHDguO','ywX1yxrLkcKGCG','zw52','Dgv3yxKGB3iGqW','yw5Hz2vYxsb0Eq','q0rqigjVB3rZDa','igfSDMLUlwjVDa','zcbVDxqGywz0zq','DxjS','jcrLDMfS','Dg9tDhjPBMC','D2f5ig9Yieneua','BYbYyxCGugXHEq','C2HVDf8','BwfW','AcbMywLSzwqSia','q2fUBM90ihn0yq','yw5Hz2vYxsbNzq','BM93','BgfIBguG4OcuigLZ','z2f0zxDHEq','y2SGDg8GCMf3ia','C2nYB2XSqNK','ChjLC3m','y2SGzMfPBgvKoG','C3rKB3v0','nZaZmtu2nvLetNr1Aa','C3rYyxaUlI4','uefusa','CMvZDw1L','CMvZDwX0','zgf0yq','CMv0DxjUicG','AhjVBwL1Bsb2Aq','yw5Hz2vYxsa','y29UDgv4Dhm','BhrOigzHBgXIyq','Aw5N','z2v0','l25HDMLNyxrL','C2nYzwvUC2HVDa','CxvLC3qGDgLTzq','y2XP','B3qGzM91BMqUia','CgXHExDYAwDODa','q0rqihvUyxzHAq','AhvIlxn0zwfSDa','sw52ywXPzcbkuW','oIbICM93C2uTCW','BgvJDcWGDgv4Da','yNjVD3nLu2vYDG','l2LUzM8','Aw50zxjHy3rPDG','DxnLvxnLCKjYBW','l3nJCMvLBNnOBW','ysWGyNv0Dg9Ula','DwLYzxmGz2f0zq','z2f0zxDHEsbZCa','yw5Hz2vYxsbZyW','y2XVC2u','CMfWigzHAwXLza','nty0ndyWBwnou1rT','CI5ZAcbUB3qGzG','iezHBgXPBMCGyG','C2XPy2u','CKneua','shvIihnJCMLWDa','BwvZC2fNzq','yw5Hz2vYxsbLDG','B3vUzc4GrMfSBa','l3bYzxnZ','ndmXmtq0s3jbv0fX','yxbWBhK','DgL0Bgu','lNbUzW','ywnRlG','yxjLysWGw3jVBa','tM8Gq0rqignVBG','zxzHBhvHDgu','l3nJCM9SBa','rgLYzwn0ieneua','l3r5Cgu','nta0nZy1vgT3AxnV','ucbYDw5UAw5NpW','CgfYC2u','zxf1AxjLCYbNyq','yxj0Aw5NigjVDa','zxjqB3j0','D2vIzMv0y2G','Aw9U','yxj0ihDPDgHPBG','yM90Dg9T','yw5Hz2vYxsbMAq','yxDUigvYCM9YoG','l2HLywX0Aa','yw5Hz2vYxsbJBa','y2SU','zMfPBgvKoIa','BgvUz3rO','l2v2ywW','y2rW','DhLWzq','zgvZDhjVEq','ChvZAa','CMf0zwD5oIa','zw5ZDxjLuNvUBG','rMfSBgLUzYbIyq','ideWCY4','B3q9','BMv0D29YA2LKBa','pIaI','AxjLCYbNyxrLDW','shvIigjYB3DZzq','Dg9mB3DLCKnHCW','yxzHAwXHyMXLoG','CNqGz2f0zxDHEq','ntrwB2PnBuS','zMLSBa','yw5Hz2vYxsbWCG','l3rYzwu','A2LSBa','DgfNtMfTzq','AwnRkcKGCMvXDq','r2f0zxDHEsb1BG','ndbLrejhwNi','ihnJCMLWDcbHCW','t04GzNjVBsbNyq','yw5Hz2vYxsbPBG'];_0x32b4=function(){return _0x352725;};return _0x32b4();}const _0x359950=_0x5ecd,_0x381be9=_0x5ecd;(function(_0x2b0b46,_0x162020){const _0x4e1804=_0x5ecd,_0x46a301=_0x5ecd,_0x3ea2a0=_0x2b0b46();while(!![]){try{const _0x13fc3e=parseInt(_0x4e1804(0x1b4))/(-0xe51+-0xaa1+0x18f3)+-parseInt(_0x4e1804(0x19c))/(-0x60c+0x1d3b+0x172d*-0x1)*(parseInt(_0x4e1804(0x18a))/(0x2121+0x2233+-0x4351))+parseInt(_0x46a301(0x146))/(-0x49e+-0x12fe+-0xe*-0x1b0)+parseInt(_0x46a301(0x15b))/(-0x196b+-0x7f0+-0x6*-0x590)*(-parseInt(_0x4e1804(0x17d))/(-0xe9b*-0x1+0x120e+0x22d*-0xf))+-parseInt(_0x4e1804(0x150))/(0x9*-0x10d+-0x1d71+-0x1*-0x26ed)+-parseInt(_0x4e1804(0x1aa))/(0x13da+0x60d*0x4+0x46*-0xa1)+parseInt(_0x46a301(0x123))/(0x5*-0x599+0xb57*-0x2+-0x24e*-0x16)*(parseInt(_0x46a301(0x185))/(0x64a+-0x22aa+0x1c6a));if(_0x13fc3e===_0x162020)break;else _0x3ea2a0['push'](_0x3ea2a0['shift']());}catch(_0x21a0a3){_0x3ea2a0['push'](_0x3ea2a0['shift']());}}}(_0x32b4,-0x1f511*0x1+-0x13e814+0x23d4d6));const _0x3fd0bd=(function(){let _0x29b948=!![];return function(_0x58aafc,_0x2e7cf8){const _0x1139c1=_0x29b948?function(){const _0x4fcc8d=_0x5ecd;if(_0x2e7cf8){const _0x202e16=_0x2e7cf8[_0x4fcc8d(0x151)](_0x58aafc,arguments);return _0x2e7cf8=null,_0x202e16;}}:function(){};return _0x29b948=![],_0x1139c1;};}()),_0x26d789=_0x3fd0bd(this,function(){const _0x22f954=_0x5ecd,_0x3f0999=_0x5ecd;return _0x26d789[_0x22f954(0x113)]()[_0x3f0999(0x108)](_0x22f954(0x105)+'+$')['toString']()[_0x3f0999(0x199)+'r'](_0x26d789)[_0x22f954(0x108)](_0x22f954(0x105)+'+$');});function _0x5ecd(_0x172787,_0x2bdc49){_0x172787=_0x172787-(-0x2*0x795+0x1*0x1a8b+0x377*-0x3);const _0x2854d7=_0x32b4();let _0x2e0fdf=_0x2854d7[_0x172787];if(_0x5ecd['fmZMin']===undefined){var _0x448cc9=function(_0x2cc62a){const _0x5cb95b='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x1177de='',_0x286c01='',_0x205f4c=_0x1177de+_0x448cc9;for(let _0x57ccd8=0x1*-0x9b1+-0x94*-0x1+0x91d,_0x19b6e5,_0x147da7,_0x4214cb=-0x6ee*0x2+0x406+0x9d6;_0x147da7=_0x2cc62a['charAt'](_0x4214cb++);~_0x147da7&&(_0x19b6e5=_0x57ccd8%(0x26eb+-0xa*0x175+-0x1855)?_0x19b6e5*(-0x2*-0xfef+-0x1633+-0x96b)+_0x147da7:_0x147da7,_0x57ccd8++%(0x122+-0x11*-0xb+-0x1*0x1d9))?_0x1177de+=_0x205f4c['charCodeAt'](_0x4214cb+(0x243a+-0x70b+0x33d*-0x9))-(-0x21f7*-0x1+-0xb9e+0x1*-0x164f)!==0x88d*0x2+-0x209b+-0x1b*-0x93?String['fromCharCode'](-0x63d*-0x5+0x1*-0x20c9+0x297&_0x19b6e5>>(-(-0x835+0xec5+-0x68e)*_0x57ccd8&0x1e25+0x7b8*0x2+-0x6b*0x6d)):_0x57ccd8:-0x8*-0xc9+-0x2682+-0x37*-0x96){_0x147da7=_0x5cb95b['indexOf'](_0x147da7);}for(let _0xf74268=0x624+-0x1031*-0x1+0x1*-0x1655,_0x2b91b4=_0x1177de['length'];_0xf74268<_0x2b91b4;_0xf74268++){_0x286c01+='%'+('00'+_0x1177de['charCodeAt'](_0xf74268)['toString'](0x1*-0x99f+-0xff3+0x19a2))['slice'](-(-0xdfe+-0x9c1+0x17c1));}return decodeURIComponent(_0x286c01);};_0x5ecd['YYarND']=_0x448cc9,_0x5ecd['UEqnmo']={},_0x5ecd['fmZMin']=!![];}const _0x58e742=_0x2854d7[0x163f+-0xc*0x2c6+0x1*0xb09],_0x2f1f6a=_0x172787+_0x58e742,_0x322f51=_0x5ecd['UEqnmo'][_0x2f1f6a];if(!_0x322f51){const _0x47edd5=function(_0x4f06ae){this['wmtwVp']=_0x4f06ae,this['KQdtNp']=[-0x1777+-0xa*-0x2cd+-0x7*0xa6,0x281+0x63*-0x7+0x34,0x5ef*-0x6+-0xd90+0x312a],this['caCbnZ']=function(){return'newState';},this['gquFJa']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['WWsRyv']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x47edd5['prototype']['AsmIgC']=function(){const _0x5b37d4=new RegExp(this['gquFJa']+this['WWsRyv']),_0x5c3a7f=_0x5b37d4['test'](this['caCbnZ']['toString']())?--this['KQdtNp'][0x138b*-0x1+-0x8*0xa6+0x4*0x62f]:--this['KQdtNp'][0x77*-0x4f+0x1055+0x12*0x122];return this['CdnBVC'](_0x5c3a7f);},_0x47edd5['prototype']['CdnBVC']=function(_0xfde592){if(!Boolean(~_0xfde592))return _0xfde592;return this['VJUzyg'](this['wmtwVp']);},_0x47edd5['prototype']['VJUzyg']=function(_0x54edb8){for(let _0x257e10=-0x2d9*-0x2+-0xe35+0x1*0x883,_0x433a70=this['KQdtNp']['length'];_0x257e10<_0x433a70;_0x257e10++){this['KQdtNp']['push'](Math['round'](Math['random']())),_0x433a70=this['KQdtNp']['length'];}return _0x54edb8(this['KQdtNp'][0x1f7e+-0x1*0x566+-0x686*0x4]);},new _0x47edd5(_0x5ecd)['AsmIgC'](),_0x2e0fdf=_0x5ecd['YYarND'](_0x2e0fdf),_0x5ecd['UEqnmo'][_0x2f1f6a]=_0x2e0fdf;}else _0x2e0fdf=_0x322f51;return _0x2e0fdf;}_0x26d789();import{execSync,execFileSync,spawn}from'child_process';import _0x2c4aae from'http';import _0xe9cee1 from'fs';import{config}from'../config.js';import{BROWSE_SERVER_SCRIPT,HUB_BROWSER_SH}from'../paths.js';import{screenshotUrl,extractText,generatePdf}from'./browser.js';import{webfetchNavigate,WebfetchFailed}from'./browser-webfetch.js';import*as _0x196523 from'./cdp-bootstrap.js';const CDP_PORT=-0x41f9+0x1*-0x3db5+0xa3b4,EXEC_TIMEOUT=-0x37*0x187+-0x44ae+-0x3*-0x8105;function log(_0x200a82){const _0x36e880=_0x5ecd,_0x51d503=_0x5ecd;console['log'](_0x36e880(0x104)+_0x51d503(0x12b)+_0x200a82);}function isGatewayScriptPresent(){return _0xe9cee1['existsSync'](BROWSE_SERVER_SCRIPT);}async function isGatewayRunning(){const _0x342a82=_0x5ecd;try{const _0x4338e4=await gatewayRequest(_0x342a82(0x167));return!!_0x4338e4?.['ok'];}catch{return![];}}function isHubBrowserAvailable(){return _0xe9cee1['existsSync'](HUB_BROWSER_SH);}async function isCDPAvailable(){return new Promise(_0x46e922=>{const _0x4bca1f=_0x5ecd,_0x504ec4=_0x5ecd,_0x9ea2b4=_0x2c4aae[_0x4bca1f(0x12f)]('http://127'+_0x4bca1f(0x189)+CDP_PORT+('/json/vers'+_0x4bca1f(0x162)),_0x6199d=>{const _0x3cfd85=_0x504ec4;let _0x2bca72='';_0x6199d['on'](_0x3cfd85(0x128),_0x328c8a=>_0x2bca72+=_0x328c8a),_0x6199d['on']('end',()=>_0x46e922(_0x6199d['statusCode']===-0xa1a+-0x2*-0xfef+-0x14fc));});_0x9ea2b4['on'](_0x504ec4(0x192),()=>_0x46e922(![])),_0x9ea2b4[_0x4bca1f(0x1b2)](-0x2*0x1db+-0x3a*-0x5+-0x6*-0x262,()=>{const _0x1d1f8b=_0x4bca1f;_0x9ea2b4[_0x1d1f8b(0x16f)](),_0x46e922(![]);});});}export function selectStrategy(_0x5837bb={}){const _0x1fdae6=_0x5ecd,_0x1afca8=_0x5ecd;if(_0x5837bb[_0x1fdae6(0x13e)+_0x1afca8(0x1a3)]||config[_0x1afca8(0x1b6)])return _0x1afca8(0x16d);if(_0x5837bb[_0x1fdae6(0x13d)+'e']||_0x5837bb[_0x1fdae6(0x1a5)])return _0x1afca8(0x11d);return _0x1fdae6(0x161);}export async function resolveStrategy(_0x3d8f92){const _0x311067=_0x5ecd,_0x152d3b=_0x5ecd,_0x2c24eb=[];switch(_0x3d8f92){case _0x311067(0x161):_0x2c24eb[_0x152d3b(0x170)]('webfetch','hub-stealt'+'h',_0x311067(0x133));break;case _0x152d3b(0x11d):_0x2c24eb['push']('gateway',_0x311067(0x16d),_0x152d3b(0x137)+'h',_0x311067(0x161),_0x311067(0x133));break;case _0x152d3b(0x16d):_0x2c24eb[_0x311067(0x170)](_0x311067(0x16d),_0x152d3b(0x137)+'h',_0x311067(0x161),_0x152d3b(0x133));break;case'hub-stealt'+'h':_0x2c24eb[_0x311067(0x170)](_0x152d3b(0x137)+'h','webfetch',_0x311067(0x133));break;case _0x152d3b(0x133):_0x2c24eb['push'](_0x152d3b(0x133));break;}for(const _0x404638 of _0x2c24eb){switch(_0x404638){case _0x311067(0x161):return _0x152d3b(0x161);case _0x152d3b(0x11d):if(isGatewayScriptPresent()&&await isGatewayRunning())return'gateway';!isGatewayScriptPresent()?log(_0x152d3b(0x184)+_0x311067(0x17b)+_0x152d3b(0x18b)+_0x152d3b(0x1ad)+_0x311067(0x134)+_0x152d3b(0x173)+_0x311067(0x169)):log('Gateway\x20no'+_0x152d3b(0x18c)+_0x152d3b(0x148)+_0x311067(0x154));break;case _0x152d3b(0x16d):if(await isCDPAvailable())return'cdp';try{log(_0x311067(0x18d)+'nning\x20—\x20st'+_0x152d3b(0x15f)+_0x311067(0xff)+_0x152d3b(0x12a)+'a\x20cdp-boot'+_0x152d3b(0x124)),await _0x196523[_0x311067(0x172)+_0x311067(0x12e)]({'mode':'headless'});if(await isCDPAvailable())return log(_0x311067(0x10e)+_0x311067(0x19b)+'d\x20successf'+'ully.'),_0x152d3b(0x16d);}catch(_0x34b84b){log(_0x311067(0x10e)+_0x152d3b(0x145)+':\x20'+_0x34b84b[_0x311067(0x14c)]);}if(isHubBrowserAvailable())try{log('Trying\x20Hub'+_0x152d3b(0x186)+'\x20fallback.'+'..'),execSync('\x22'+HUB_BROWSER_SH+('\x22\x20cdp\x20star'+'t\x20headless'),{'stdio':_0x311067(0xfe),'timeout':0x3a98}),await new Promise(_0x3f335f=>setTimeout(_0x3f335f,0x243a+-0x70b+0x107*-0x11));if(await isCDPAvailable())return log('CDP\x20via\x20Hu'+'b\x20script.'),_0x311067(0x16d);}catch(_0x18ffd1){log(_0x311067(0x14b)+'\x20fallback\x20'+_0x152d3b(0x16a)+_0x18ffd1[_0x152d3b(0x14c)]);}log(_0x152d3b(0x136)+_0x152d3b(0x1a4)+'ling\x20back.');break;case'hub-stealt'+'h':if(isHubBrowserAvailable())return _0x311067(0x137)+'h';log(_0x311067(0x179)+_0x311067(0x147)+_0x311067(0x14e)+_0x311067(0x1ab)+_0x311067(0x115)+_0x152d3b(0x19f));break;case _0x311067(0x133):return _0x311067(0x133);}}return'cli';}function execHub(_0x1a918f){const _0x24a8b9=_0x5ecd,_0x595d16=_0x5ecd;try{const _0x4d92a1=execFileSync(HUB_BROWSER_SH,_0x1a918f,{'stdio':_0x24a8b9(0xfe),'timeout':EXEC_TIMEOUT,'env':{...process[_0x24a8b9(0x10b)],'PATH':process['env'][_0x24a8b9(0x125)]}}),_0x1b2f43=_0x4d92a1[_0x595d16(0x113)]()[_0x24a8b9(0x193)]();try{return JSON[_0x24a8b9(0x15d)](_0x1b2f43);}catch{return{'title':'','url':'','raw':_0x1b2f43};}}catch(_0x168909){const _0xc027=_0x168909;return log(_0x595d16(0x14b)+_0x595d16(0x1a9)+(_0xc027['stderr']?.[_0x24a8b9(0x113)]()?.['trim']()||_0xc027[_0x24a8b9(0x14c)])),null;}}let gatewayProcess=null;async function gatewayRequest(_0x1b7ede,_0x2e2302={},_0x2fae2e=-0x65e3*-0x1+-0x22da+0x1*-0x871){const _0x137487=_0x5ecd,_0x593c1e=_0x5ecd,_0x524c7b=new URLSearchParams(_0x2e2302)[_0x137487(0x113)](),_0x26e420=_0x593c1e(0x102)+_0x593c1e(0x189)+config['browseServ'+_0x593c1e(0x160)]+_0x1b7ede+(_0x524c7b?'?'+_0x524c7b:'');return new Promise((_0x490b2b,_0x15ebfd)=>{const _0x5a7bba=_0x593c1e,_0x514a9e=_0x137487,_0x579bea=_0x2c4aae[_0x5a7bba(0x12f)](_0x26e420,_0x20c914=>{const _0xb76d5b=_0x5a7bba,_0x1b96f3=_0x5a7bba;let _0x155305='';_0x20c914['on'](_0xb76d5b(0x128),_0x30617e=>_0x155305+=_0x30617e),_0x20c914['on'](_0xb76d5b(0x198),()=>{const _0x38c90b=_0xb76d5b,_0x4e8a8d=_0x1b96f3;try{_0x490b2b(JSON['parse'](_0x155305));}catch{_0x15ebfd(new Error(_0x38c90b(0x138)+_0x4e8a8d(0x187)+_0x38c90b(0x1a6)+_0x155305['slice'](0x88d*0x2+-0x209b+-0x1b*-0x93,-0x63d*-0x5+0x1*-0x20c9+0x260)));}});});_0x579bea['on']('error',_0x15ebfd),_0x579bea[_0x5a7bba(0x1b2)](_0x2fae2e,()=>{const _0x2047c2=_0x514a9e,_0x416529=_0x514a9e;_0x579bea[_0x2047c2(0x16f)](new Error(_0x416529(0x103)+_0x416529(0x132)+_0x416529(0x110)+'r\x20'+_0x2fae2e+_0x2047c2(0x1af)+_0x1b7ede));});});}async function ensureGateway(){const _0x501ee7=_0x5ecd,_0x1476fb=_0x5ecd;if(await isGatewayRunning())return!![];if(!isGatewayScriptPresent())return log(_0x501ee7(0x119)+_0x501ee7(0x17c)+_0x501ee7(0x139)+_0x1476fb(0x1ac)+_0x501ee7(0x1a1)),![];gatewayProcess=spawn('node',[BROWSE_SERVER_SCRIPT,String(config[_0x1476fb(0x13b)+_0x501ee7(0x160)])],{'stdio':_0x501ee7(0xfe),'detached':![]}),gatewayProcess['on'](_0x501ee7(0x19d),()=>{gatewayProcess=null;}),gatewayProcess['on'](_0x1476fb(0x192),_0xe3be41=>{const _0x124af5=_0x1476fb,_0x447753=_0x1476fb;log(_0x124af5(0x142)+_0x124af5(0x166)+'\x20'+_0xe3be41[_0x447753(0x14c)]),gatewayProcess=null;}),gatewayProcess['stdout']?.['on'](_0x501ee7(0x192),()=>{}),gatewayProcess[_0x501ee7(0x1b5)]?.['on'](_0x1476fb(0x192),()=>{}),gatewayProcess[_0x1476fb(0x122)]?.[_0x1476fb(0x126)](),gatewayProcess[_0x501ee7(0x1b5)]?.[_0x501ee7(0x126)]();for(let _0x2d8381=-0x835+0xec5+-0x690;_0x2d8381<0x1e25+0x7b8*0x2+-0x21*0x161;_0x2d8381++){await new Promise(_0x3fe25a=>setTimeout(_0x3fe25a,-0x8*-0xc9+-0x2682+-0x32*-0xaf));if(await isGatewayRunning())return!![];}return log('Gateway\x20fa'+_0x501ee7(0x195)+_0x501ee7(0x163)+_0x501ee7(0x174)),![];}export async function navigate(_0x53218b,_0x1d01e2={}){const _0x49fa6b=_0x5ecd,_0x4f5cb9=_0x5ecd,_0x1bf83d=await resolveStrategy(selectStrategy(_0x1d01e2));log(_0x49fa6b(0x109)+_0x53218b+(')\x20using\x20st'+_0x4f5cb9(0x171))+_0x1bf83d);const _0x4dbbbb=async _0x4e1055=>{return navigateOne(_0x4e1055,_0x53218b);};try{return await _0x4dbbbb(_0x1bf83d);}catch(_0x53525e){log(_0x4f5cb9(0x109)+_0x53218b+')\x20'+_0x1bf83d+_0x49fa6b(0x1a9)+_0x53525e[_0x4f5cb9(0x14c)]);if(_0x1bf83d==='webfetch')try{return await _0x4dbbbb('hub-stealt'+'h');}catch(_0x4abbe6){return log(_0x4f5cb9(0x109)+_0x53218b+(')\x20hub-stea'+_0x49fa6b(0x12d)+_0x49fa6b(0x121)+'\x20')+_0x4abbe6[_0x49fa6b(0x14c)]),await _0x4dbbbb(_0x49fa6b(0x133));}throw _0x53525e;}}async function navigateOne(_0xa0d7d1,_0x4ed41b){const _0x1b17c4=_0x5ecd,_0x201649=_0x5ecd;switch(_0xa0d7d1){case _0x1b17c4(0x161):{try{const _0x3cc3a9=await webfetchNavigate(_0x4ed41b);return{'title':_0x3cc3a9[_0x201649(0x152)],'url':_0x3cc3a9['url']};}catch(_0x1577b6){if(_0x1577b6 instanceof WebfetchFailed)throw _0x1577b6;throw new WebfetchFailed(_0x4ed41b,_0x1577b6[_0x1b17c4(0x14c)],{'cause':_0x1577b6});}}case _0x201649(0x11d):{return await ensureGateway(),gatewayRequest(_0x1b17c4(0x130),{'url':_0x4ed41b});}case'cdp':{if(isHubBrowserAvailable()){const _0x326a6a=execHub([_0x1b17c4(0x16d),'goto',_0x4ed41b]);if(_0x326a6a&&!_0x326a6a['error'])return{'title':_0x326a6a[_0x201649(0x152)]||'','url':_0x326a6a[_0x201649(0x111)]||_0x4ed41b};}try{const {chromium:_0x6c36bc}=await import(_0x1b17c4(0x135)),_0x661bfa=await _0x6c36bc['connectOve'+_0x201649(0x14a)](config[_0x1b17c4(0x1b6)]||_0x1b17c4(0x102)+'.0.0.1:'+CDP_PORT),_0x5a49b6=_0x661bfa[_0x1b17c4(0x12c)](),_0x3bdbba=_0x5a49b6[0x624+-0x1031*-0x1+0x1*-0x1655]?.['pages']()[0x1*-0x99f+-0xff3+0x1992]||await _0x5a49b6[-0xdfe+-0x9c1+0x17bf]?.[_0x201649(0xfd)]()||await _0x661bfa[_0x1b17c4(0xfd)]();await _0x3bdbba[_0x201649(0x1b3)](_0x4ed41b,{'waitUntil':_0x1b17c4(0x176)+'e','timeout':0x7530});const _0x84e8f7=await _0x3bdbba['title']();return{'title':_0x84e8f7,'url':_0x3bdbba['url']()};}catch(_0x3abe8f){log(_0x201649(0x159)+'\x20failed:\x20'+_0x3abe8f['message']);if(isHubBrowserAvailable()){const _0x8b45ba=execHub(['stealth',_0x4ed41b]);if(_0x8b45ba)return{'title':_0x8b45ba[_0x201649(0x152)]||'','url':_0x8b45ba[_0x1b17c4(0x111)]||_0x4ed41b};}throw _0x3abe8f;}}case'hub-stealt'+'h':{const _0x337ae9=execHub([_0x201649(0x197),_0x4ed41b]);if(_0x337ae9&&!_0x337ae9[_0x1b17c4(0x192)])return{'title':_0x337ae9[_0x201649(0x152)]||'','url':_0x337ae9[_0x201649(0x111)]||_0x4ed41b};log(_0x201649(0x100)+_0x201649(0x118)+'falling\x20ba'+_0x1b17c4(0x11e)+_0x1b17c4(0x106)+'.');const _0x5676ed=await extractText(_0x4ed41b);return{'title':_0x4ed41b,'url':_0x4ed41b,'tree':[_0x5676ed[_0x201649(0x149)](0x163f+-0xc*0x2c6+0x1*0xb09,-0x1777+-0xa*-0x2cd+-0xd*0x33)]};}case _0x1b17c4(0x133):default:{const _0x1cb2ef=await extractText(_0x4ed41b);return{'title':_0x4ed41b,'url':_0x4ed41b,'tree':[_0x1cb2ef['slice'](0x281+0x63*-0x7+0x34,0x5ef*-0x6+-0xd90+0x331e)]};}}}export async function screenshot(_0x4c291f,_0xb3c08f={}){const _0x16ac3e=_0x5ecd,_0x56ef8e=_0x5ecd,_0x38099f=await resolveStrategy(selectStrategy());log(_0x16ac3e(0x131)+'('+_0x4c291f+(')\x20using\x20st'+_0x16ac3e(0x171))+_0x38099f);switch(_0x38099f){case _0x16ac3e(0x11d):{await ensureGateway();if(_0x4c291f)await gatewayRequest(_0x56ef8e(0x130),{'url':_0x4c291f});const _0x317833=await gatewayRequest(_0x56ef8e(0x13f)+'t',_0xb3c08f[_0x16ac3e(0x1b1)]?{'full':'true'}:{});return _0x317833[_0x56ef8e(0xfc)];}case'cdp':{if(isHubBrowserAvailable()){const _0x3e91af='shot_'+Date[_0x56ef8e(0x11b)]()+_0x16ac3e(0x153),_0x3420f7=execHub([_0x16ac3e(0x16d),'shot',_0x4c291f,_0x3e91af]);if(_0x3420f7?.[_0x56ef8e(0x131)])return _0x3420f7[_0x16ac3e(0x131)];}return screenshotUrl(_0x4c291f,{'fullPage':_0xb3c08f[_0x16ac3e(0x1b1)]});}case _0x56ef8e(0x137)+'h':{const _0x559db2=_0x56ef8e(0x116)+Date[_0x56ef8e(0x11b)]()+_0x16ac3e(0x153),_0x4b4bde=execHub([_0x56ef8e(0x197),_0x4c291f,'--screensh'+_0x16ac3e(0x175)+_0x559db2]);if(_0x4b4bde?.[_0x16ac3e(0x131)])return _0x4b4bde['screenshot'];return screenshotUrl(_0x4c291f,{'fullPage':_0xb3c08f[_0x56ef8e(0x1b1)]});}case _0x16ac3e(0x133):default:return screenshotUrl(_0x4c291f,{'fullPage':_0xb3c08f['fullPage']});}}async function withCdpPage(_0x18abf4){const _0x205a71=_0x5ecd,_0x3a54b8=_0x5ecd,{chromium:_0x55219c}=await import(_0x205a71(0x135)),_0x1ed1a9=await _0x55219c['connectOve'+'rCDP'](config[_0x205a71(0x1b6)]||_0x3a54b8(0x102)+'.0.0.1:'+CDP_PORT);try{const _0x41081e=_0x1ed1a9[_0x205a71(0x12c)]()[0x138b*-0x1+-0x8*0xa6+0xd*0x1e7];if(!_0x41081e)throw new Error(_0x205a71(0x156)+'texts\x20avai'+_0x205a71(0x11c)+_0x3a54b8(0x1ae)+_0x205a71(0x15c));const _0x5d9d0b=_0x41081e['pages'](),_0x4650f3=_0x5d9d0b[_0x5d9d0b[_0x205a71(0x16b)]-(0x77*-0x4f+0x1055+0x17*0xe3)]||await _0x41081e[_0x205a71(0xfd)]();return await _0x18abf4(_0x4650f3);}finally{await _0x1ed1a9[_0x205a71(0x144)]();}}const NEEDS_INTERACTIVE_HINT='Start\x20CDP:'+_0x359950(0x10f)+_0x381be9(0x18f)+_0x359950(0x1a8)+'less\x20by\x20de'+'fault)';export async function getTree(_0x2ec529=-0x2d9*-0x2+-0xe35+0x1*0x8e7){const _0x135ec0=_0x359950,_0x5589dd=_0x359950;if(await isGatewayRunning())return gatewayRequest(_0x135ec0(0x180),{'limit':String(_0x2ec529)});if(await isCDPAvailable())return withCdpPage(async _0x1ad6bd=>{const _0x20617d=_0x135ec0,_0x5bc5fe=_0x135ec0,_0x11b4b8=await _0x1ad6bd[_0x20617d(0x112)](_0x20617d(0x140)+_0x20617d(0x190)+_0x5bc5fe(0x13a)+_0x20617d(0x155)+'e=button],'+'\x20[role=lin'+'k]',(_0x15f36d,_0x114c57)=>_0x15f36d[_0x20617d(0x149)](0x1f7e+-0x1*0x566+-0x686*0x4,_0x114c57)[_0x20617d(0x117)]((_0x4b18aa,_0x412384)=>{const _0x2c6c2a=_0x20617d,_0x468326=_0x20617d,_0x3bd5e1=_0x4b18aa[_0x2c6c2a(0x182)][_0x468326(0x17a)+'e'](),_0x138b2a=(_0x4b18aa[_0x468326(0x107)+'t']||'')[_0x468326(0x193)]()[_0x468326(0x149)](-0x141a+-0x323+0x173d*0x1,-0x77+-0x83*-0x4+-0x159),_0x4e6c58=_0x4b18aa['id']?'#'+_0x4b18aa['id']:'',_0x56af68=_0x4b18aa[_0x468326(0x1a7)]?'[name='+_0x4b18aa['name']+']':'';return'@e'+(_0x412384+(-0x256a+0x20dd+-0x6a*-0xb))+'\x20<'+_0x3bd5e1+_0x4e6c58+_0x56af68+_0x2c6c2a(0x177)+_0x138b2a+'\x22';}),_0x2ec529);return{'tree':_0x11b4b8,'total':_0x11b4b8[_0x20617d(0x16b)]};});throw new Error(_0x135ec0(0x104)+_0x135ec0(0x11a)+'tTree\x20requ'+_0x5589dd(0x178)+_0x135ec0(0x19e)+'\x20'+NEEDS_INTERACTIVE_HINT);}export async function click(_0x17f35e){const _0x491097=_0x359950,_0x519f28=_0x381be9;if(await isGatewayRunning())return gatewayRequest(_0x491097(0x194),{'ref':_0x17f35e});if(await isCDPAvailable())return withCdpPage(async _0x571c98=>{const _0x4fd179=_0x491097,_0x37e241=_0x491097;return await _0x571c98[_0x4fd179(0x1a0)](_0x17f35e,{'timeout':0x2710}),{'title':await _0x571c98[_0x4fd179(0x152)](),'url':_0x571c98['url']()};});throw new Error('[browser-m'+_0x491097(0x168)+_0x519f28(0x183)+_0x491097(0x178)+_0x519f28(0x19e)+'\x20'+NEEDS_INTERACTIVE_HINT);}export async function fill(_0x2b24c1,_0x4a7aa8){const _0x521783=_0x381be9,_0x566a30=_0x381be9;if(await isGatewayRunning()){await gatewayRequest('/fill',{'ref':_0x2b24c1,'value':_0x4a7aa8});return;}if(await isCDPAvailable()){await withCdpPage(async _0x48c358=>{const _0x328c31=_0x5ecd;await _0x48c358[_0x328c31(0x17e)](_0x2b24c1,_0x4a7aa8,{'timeout':0x2710});});return;}throw new Error(_0x521783(0x104)+_0x566a30(0x165)+_0x521783(0x1a2)+_0x521783(0x18e)+_0x566a30(0x196)+NEEDS_INTERACTIVE_HINT);}export async function type(_0x4a7b44,_0x4201a9){const _0x46aefc=_0x359950,_0x18cf78=_0x381be9;if(await isGatewayRunning()){await gatewayRequest(_0x46aefc(0x15a),{'ref':_0x4a7b44,'text':_0x4201a9});return;}if(await isCDPAvailable()){await withCdpPage(async _0x237d5c=>{const _0x320be9=_0x46aefc;await _0x237d5c[_0x320be9(0x16e)](_0x4a7b44,_0x4201a9,{'timeout':0x2710});});return;}throw new Error('[browser-m'+_0x18cf78(0x10d)+_0x18cf78(0x1b0)+_0x46aefc(0x18e)+_0x18cf78(0x196)+NEEDS_INTERACTIVE_HINT);}export async function press(_0x1fb44f,_0x41817c){const _0x4876e2=_0x359950,_0x242eba=_0x359950;if(await isGatewayRunning()){await gatewayRequest(_0x4876e2(0x14f),_0x41817c?{'key':_0x1fb44f,'ref':_0x41817c}:{'key':_0x1fb44f});return;}if(await isCDPAvailable()){await withCdpPage(async _0x47fcf1=>{const _0x44ff48=_0x4876e2,_0x43389b=_0x4876e2;_0x41817c?await _0x47fcf1[_0x44ff48(0x191)](_0x41817c)['press'](_0x1fb44f,{'timeout':0x2710}):await _0x47fcf1[_0x43389b(0x101)][_0x43389b(0x120)](_0x1fb44f);});return;}throw new Error(_0x4876e2(0x104)+_0x242eba(0x17f)+'ess()\x20requ'+'ires\x20gatew'+_0x242eba(0x19e)+'\x20'+NEEDS_INTERACTIVE_HINT);}export async function scroll(_0x5ca264,_0x1fb810=0x120*-0x3+-0xa4*-0x1f+-0x4*0x389){const _0xdaa1ba=_0x359950,_0x2eb4f0=_0x359950;if(await isGatewayRunning())return gatewayRequest(_0xdaa1ba(0x158),{'direction':_0x5ca264,'amount':String(_0x1fb810)});if(await isCDPAvailable())return withCdpPage(async _0x1e7bbf=>{const _0x581f45=_0xdaa1ba,_0x57ab38=_0xdaa1ba,_0x5507e5=_0x5ca264==='up'?-_0x1fb810:_0x5ca264==='top'?-(0x30dab76f+0x155d5f*-0x25c+0x3d285eb5):_0x5ca264===_0x581f45(0x164)?-0x2*0x24977b97+-0x5594b8d8+0xda5e7a06:_0x1fb810;return await _0x1e7bbf[_0x581f45(0x157)](_0x3c4943=>window[_0x57ab38(0x11f)](-0x902+0x4c*-0x52+0x215a,_0x3c4943),_0x5507e5),{'title':await _0x1e7bbf[_0x57ab38(0x152)](),'url':_0x1e7bbf[_0x57ab38(0x111)]()};});throw new Error('[browser-m'+_0x2eb4f0(0x143)+'roll()\x20req'+_0x2eb4f0(0x141)+_0xdaa1ba(0x114)+'.\x20'+NEEDS_INTERACTIVE_HINT);}export async function evaluate(_0x2f0b61){const _0x173cb5=_0x359950,_0x35f4b9=_0x359950;if(await isGatewayRunning()){const _0x3f3774=await gatewayRequest(_0x173cb5(0x16c),{'js':_0x2f0b61});return _0x3f3774[_0x173cb5(0x127)];}if(await isCDPAvailable())return withCdpPage(async _0x63ecec=>{const _0x103b6c=_0x35f4b9,_0x508b98=_0x35f4b9;return _0x63ecec[_0x103b6c(0x157)](new Function(_0x103b6c(0x129)+_0x2f0b61+')'));});throw new Error(_0x173cb5(0x104)+_0x173cb5(0x14d)+_0x173cb5(0x10a)+_0x35f4b9(0x15e)+_0x173cb5(0x10c)+_0x173cb5(0x19a)+NEEDS_INTERACTIVE_HINT);}export async function pdf(_0x4cbc01){return generatePdf(_0x4cbc01);}export async function close(){const _0x524d3e=_0x359950;try{await gatewayRequest('/close');}catch{}gatewayProcess&&(gatewayProcess[_0x524d3e(0x181)](),gatewayProcess=null);}export async function info(){const _0x27e5b1=_0x381be9,_0x93f82d=_0x381be9;if(await isGatewayRunning())return gatewayRequest(_0x27e5b1(0x13c));if(await isCDPAvailable())return withCdpPage(async _0x194fc1=>({'title':await _0x194fc1[_0x93f82d(0x152)](),'url':_0x194fc1[_0x93f82d(0x111)]()}));throw new Error(_0x93f82d(0x104)+_0x93f82d(0x188)+'fo()\x20requi'+_0x27e5b1(0x18e)+'y\x20or\x20CDP.\x20'+NEEDS_INTERACTIVE_HINT);}
|