@jshookmcp/jshook 0.2.7 → 0.2.9
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 +36 -5
- package/README.zh.md +36 -5
- package/dist/{AntiCheatDetector-S8VRj-dD.mjs → AntiCheatDetector-BNk-EoBt.mjs} +3 -3
- package/dist/{CodeInjector-4Z3ngPoX.mjs → CodeInjector-Cq8q01kp.mjs} +5 -5
- package/dist/ConsoleMonitor-CPVQW1Y-.mjs +2201 -0
- package/dist/{DarwinAPI-B8hg_yhz.mjs → DarwinAPI-BNPxu0RH.mjs} +1 -1
- package/dist/DetailedDataManager-BQQcxh64.mjs +217 -0
- package/dist/EventBus-DgPmwpeu.mjs +141 -0
- package/dist/EvidenceGraphBridge-SFesNera.mjs +153 -0
- package/dist/{ExtensionManager-CZ6IveoV.mjs → ExtensionManager-CWYgw0YW.mjs} +13 -6
- package/dist/{FingerprintManager-BVxFJL2-.mjs → FingerprintManager-gzWtkKuf.mjs} +1 -1
- package/dist/{HardwareBreakpoint-DK1yjWkV.mjs → HardwareBreakpoint-B9gZCdFP.mjs} +3 -3
- package/dist/{HeapAnalyzer-CEbo10xU.mjs → HeapAnalyzer-BLDH0dCv.mjs} +4 -4
- package/dist/HookGeneratorBuilders.core.generators.storage-CtcdK78Q.mjs +639 -0
- package/dist/InstrumentationSession-CvPC7Jwy.mjs +244 -0
- package/dist/{MemoryController-DdtnBdD4.mjs → MemoryController-CbVdCIJF.mjs} +3 -3
- package/dist/{MemoryScanSession-RMixN3bX.mjs → MemoryScanSession-BsDZbLYm.mjs} +81 -78
- package/dist/{MemoryScanner-QjK4ld0B.mjs → MemoryScanner-Bcpml6II.mjs} +44 -18
- package/dist/{NativeMemoryManager.impl-CB6gJ0NM.mjs → NativeMemoryManager.impl-dZtA1ZGn.mjs} +14 -53
- package/dist/{NativeMemoryManager.utils-BML4q1ry.mjs → NativeMemoryManager.utils-B-FjA2mJ.mjs} +1 -1
- package/dist/{PEAnalyzer-CK0xe0Fs.mjs → PEAnalyzer-D1lzJ_VG.mjs} +2 -2
- package/dist/PageController-Bqm2kZ_X.mjs +417 -0
- package/dist/{PointerChainEngine-Cd73qu5b.mjs → PointerChainEngine-BOhyVsjx.mjs} +4 -4
- package/dist/PrerequisiteError-Dl33Svkz.mjs +20 -0
- package/dist/ResponseBuilder-D3iFYx2N.mjs +143 -0
- package/dist/ReverseEvidenceGraph-Dlsk94LC.mjs +269 -0
- package/dist/ScriptManager-aHHq0X7U.mjs +3000 -0
- package/dist/{Speedhack-CeF0XmEz.mjs → Speedhack-CqdIFlQl.mjs} +2 -2
- package/dist/{StructureAnalyzer-D4GkMduU.mjs → StructureAnalyzer-DhFaPvRO.mjs} +3 -3
- package/dist/ToolCatalog-C0JGZoOm.mjs +582 -0
- package/dist/ToolError-jh9whhMd.mjs +15 -0
- package/dist/ToolProbe-oC7aPrkv.mjs +45 -0
- package/dist/ToolRegistry-BjaF4oNz.mjs +131 -0
- package/dist/ToolRouter.policy-BWV67ZK-.mjs +304 -0
- package/dist/TraceRecorder-DgxyVbdQ.mjs +519 -0
- package/dist/{Win32API-Bc0QnQsN.mjs → Win32API-CePkipZY.mjs} +1 -1
- package/dist/{Win32Debug-DUHt9XUn.mjs → Win32Debug-BvKs-gxc.mjs} +2 -2
- package/dist/WorkflowEngine-CuvkZtWu.mjs +598 -0
- package/dist/analysis-CL9uACt9.mjs +463 -0
- package/dist/antidebug-CqDTB_uk.mjs +1081 -0
- package/dist/artifactRetention-CFEprwPw.mjs +591 -0
- package/dist/artifacts-Bk2-_uPq.mjs +59 -0
- package/dist/betterSqlite3-0pqusHHH.mjs +74 -0
- package/dist/binary-instrument-CXfpx6fT.mjs +979 -0
- package/dist/bind-helpers-xFfRF-qm.mjs +22 -0
- package/dist/boringssl-inspector-BH2D3VKc.mjs +180 -0
- package/dist/browser-BpOr5PEx.mjs +4082 -0
- package/dist/concurrency-Bt0yv1kJ.mjs +41 -0
- package/dist/{constants-CCvsN80K.mjs → constants-B0OANIBL.mjs} +88 -46
- package/dist/coordination-qUbyF8KU.mjs +259 -0
- package/dist/debugger-gnKxRSN0.mjs +1271 -0
- package/dist/definitions-6M-eejaT.mjs +53 -0
- package/dist/definitions-B18eyf0B.mjs +18 -0
- package/dist/definitions-B3QdlrHv.mjs +34 -0
- package/dist/definitions-B4rAvHNZ.mjs +63 -0
- package/dist/definitions-BB_4jnmy.mjs +37 -0
- package/dist/definitions-BMfYXoNC.mjs +43 -0
- package/dist/definitions-Beid2EB3.mjs +27 -0
- package/dist/definitions-C1UvM5Iy.mjs +126 -0
- package/dist/definitions-CXEI7QC72.mjs +216 -0
- package/dist/definitions-C_4r7Fo-2.mjs +14 -0
- package/dist/definitions-CkFDALoa.mjs +26 -0
- package/dist/definitions-Cke7zEb8.mjs +94 -0
- package/dist/definitions-ClJLzsJQ.mjs +25 -0
- package/dist/definitions-Cq-zroAU.mjs +28 -0
- package/dist/definitions-Cy3Sl6gV.mjs +34 -0
- package/dist/definitions-D3VsGcvz.mjs +47 -0
- package/dist/definitions-DVGfrn7y.mjs +96 -0
- package/dist/definitions-LKpC3-nL.mjs +9 -0
- package/dist/definitions-bAhHQJq9.mjs +359 -0
- package/dist/encoding-Bvz5jLRv.mjs +1065 -0
- package/dist/evidence-graph-bridge-C_fv9PuC.mjs +135 -0
- package/dist/{factory-CibqTNC8.mjs → factory-DxlGh9Xf.mjs} +37 -52
- package/dist/graphql-DYWzJ29s.mjs +1026 -0
- package/dist/handlers-9sAbfIg-.mjs +2552 -0
- package/dist/handlers-Bl8zkwz1.mjs +2716 -0
- package/dist/handlers-C67ktuRN.mjs +710 -0
- package/dist/handlers-C87g8oCe.mjs +276 -0
- package/dist/handlers-CTsDAO6p.mjs +681 -0
- package/dist/handlers-Cgyg6c0U.mjs +645 -0
- package/dist/handlers-D6j6yka7.mjs +2124 -0
- package/dist/handlers-DdFzXLvF.mjs +446 -0
- package/dist/handlers-DeLOCd5m.mjs +799 -0
- package/dist/handlers-DlCJN4Td.mjs +757 -0
- package/dist/handlers-DxGIq15_2.mjs +917 -0
- package/dist/handlers-U6L4xhuF.mjs +585 -0
- package/dist/handlers-tB9Mp9ZK.mjs +84 -0
- package/dist/handlers-tiy7EIBp.mjs +572 -0
- package/dist/handlers.impl-DS0d9fUw.mjs +761 -0
- package/dist/hooks-CzCWByww.mjs +898 -0
- package/dist/index.mjs +384 -155
- package/dist/{logger-BmWzC2lM.mjs → logger-Dh_xb7_2.mjs} +14 -6
- package/dist/maintenance-P7ePRXQC.mjs +830 -0
- package/dist/manifest-2ToTpjv8.mjs +106 -0
- package/dist/manifest-3g71z6Bg.mjs +79 -0
- package/dist/manifest-82baTv4U.mjs +45 -0
- package/dist/manifest-B3QVVeBS.mjs +82 -0
- package/dist/manifest-BB2J8IMJ.mjs +149 -0
- package/dist/manifest-BKbgbSiY.mjs +60 -0
- package/dist/manifest-Bcf-TJzH.mjs +848 -0
- package/dist/manifest-BmtZzQiQ2.mjs +45 -0
- package/dist/manifest-Bnd7kqEY.mjs +55 -0
- package/dist/manifest-BqQX6OQC2.mjs +65 -0
- package/dist/manifest-BqrQ4Tpj.mjs +81 -0
- package/dist/manifest-Br4RPFt5.mjs +370 -0
- package/dist/manifest-C5qDjysN.mjs +107 -0
- package/dist/manifest-C9RT5nk32.mjs +34 -0
- package/dist/manifest-CAhOuvSl.mjs +204 -0
- package/dist/manifest-CBYWCUBJ.mjs +51 -0
- package/dist/manifest-CFADCRa1.mjs +37 -0
- package/dist/manifest-CQVhavRF.mjs +114 -0
- package/dist/manifest-CT7zZBV1.mjs +48 -0
- package/dist/manifest-CV12bcrF.mjs +121 -0
- package/dist/manifest-CXsRWjjI.mjs +224 -0
- package/dist/manifest-CZLUCfG02.mjs +95 -0
- package/dist/manifest-D6phHKFd.mjs +131 -0
- package/dist/manifest-DCyjf4n2.mjs +294 -0
- package/dist/manifest-DHsnKgP6.mjs +60 -0
- package/dist/manifest-Df_dliIe.mjs +55 -0
- package/dist/manifest-Dh8WBmEW.mjs +129 -0
- package/dist/manifest-DhKRAT8_.mjs +92 -0
- package/dist/manifest-DlpTj4ic2.mjs +193 -0
- package/dist/manifest-DrbmZcFl2.mjs +253 -0
- package/dist/manifest-DuwHjUa5.mjs +70 -0
- package/dist/manifest-DzwvxPJX.mjs +38 -0
- package/dist/manifest-NXctwWQq.mjs +68 -0
- package/dist/manifest-Sc_0JQ13.mjs +418 -0
- package/dist/manifest-gZ4s_UtG.mjs +96 -0
- package/dist/manifest-qSleDqdO.mjs +1023 -0
- package/dist/modules-C184v-S9.mjs +11365 -0
- package/dist/mojo-ipc-B_H61Afw.mjs +525 -0
- package/dist/network-671Cw6hV.mjs +3346 -0
- package/dist/{artifacts-BbdOMET5.mjs → outputPaths-B1uGmrWZ.mjs} +219 -212
- package/dist/parse-args-BlRjqlkL.mjs +39 -0
- package/dist/platform-WmNn8Sxb.mjs +2070 -0
- package/dist/process-QcbIy5Zq.mjs +1401 -0
- package/dist/proxy-DqNs0bAd.mjs +170 -0
- package/dist/registry-D-6e18lB.mjs +34 -0
- package/dist/response-BQVP-xUn.mjs +28 -0
- package/dist/server/plugin-api.mjs +2 -2
- package/dist/shared-state-board-DV-dpHFJ.mjs +586 -0
- package/dist/sourcemap-Dq8ez8vS.mjs +650 -0
- package/dist/ssrf-policy-ZaUfvhq7.mjs +166 -0
- package/dist/streaming-BUQ0VJsg.mjs +725 -0
- package/dist/tool-builder-DCbIC5Eo.mjs +186 -0
- package/dist/transform-CiYJfNX0.mjs +1007 -0
- package/dist/types-Bx92KJfT.mjs +4 -0
- package/dist/wasm-DQTnHDs4.mjs +531 -0
- package/dist/workflow-f3xJOcjx.mjs +725 -0
- package/package.json +48 -78
- package/dist/ExtensionManager-DqUSOamB.mjs +0 -2
- package/dist/ToolCatalog-CnwmMIw3.mjs +0 -61483
- package/dist/{CacheAdapters-CzFNpD9a.mjs → CacheAdapters-CDe5WPSV.mjs} +0 -0
- package/dist/{StealthVerifier-BzBCFiwx.mjs → StealthVerifier-Bo4T3bz8.mjs} +0 -0
- package/dist/{VersionDetector-CNXcvD46.mjs → VersionDetector-CwVLVdDM.mjs} +0 -0
- package/dist/{formatAddress-ChCSIRWT.mjs → formatAddress-DVkj9kpI.mjs} +0 -0
- package/dist/{types-BBjOqye-.mjs → types-CPhOReNX.mjs} +1 -1
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import { t as logger } from "./logger-Dh_xb7_2.mjs";
|
|
2
|
+
import { Kt as PAGE_FRAME_SELECTOR_TIMEOUT_MS, qt as PAGE_NETWORK_IDLE_TIMEOUT_MS } from "./constants-B0OANIBL.mjs";
|
|
3
|
+
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
4
|
+
//#region src/modules/collector/PageController.ts
|
|
5
|
+
var PageController = class {
|
|
6
|
+
constructor(collector) {
|
|
7
|
+
this.collector = collector;
|
|
8
|
+
}
|
|
9
|
+
hasAttachedTargetSession() {
|
|
10
|
+
return this.collector.getAttachedTargetSession() !== null;
|
|
11
|
+
}
|
|
12
|
+
getAttachedTargetInfo() {
|
|
13
|
+
return this.collector.getAttachedTargetInfo();
|
|
14
|
+
}
|
|
15
|
+
async evaluateAttachedTarget(code, options) {
|
|
16
|
+
return await this.collector.getBrowserTargetSessionManager().evaluate(code, options);
|
|
17
|
+
}
|
|
18
|
+
async addScriptToAttachedTarget(source) {
|
|
19
|
+
return await this.collector.getBrowserTargetSessionManager().addScriptToEvaluateOnNewDocument(source);
|
|
20
|
+
}
|
|
21
|
+
async navigate(url, options) {
|
|
22
|
+
const page = await this.collector.getActivePage();
|
|
23
|
+
const startTime = Date.now();
|
|
24
|
+
await page.goto(url, {
|
|
25
|
+
waitUntil: options?.waitUntil || "networkidle2",
|
|
26
|
+
timeout: options?.timeout || 3e4
|
|
27
|
+
});
|
|
28
|
+
const loadTime = Date.now() - startTime;
|
|
29
|
+
const title = await page.title();
|
|
30
|
+
const currentUrl = page.url();
|
|
31
|
+
logger.info(`Navigated to: ${url}`);
|
|
32
|
+
return {
|
|
33
|
+
url: currentUrl,
|
|
34
|
+
title,
|
|
35
|
+
loadTime
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
async reload(options) {
|
|
39
|
+
await (await this.collector.getActivePage()).reload({
|
|
40
|
+
waitUntil: options?.waitUntil || "networkidle2",
|
|
41
|
+
timeout: options?.timeout || 3e4
|
|
42
|
+
});
|
|
43
|
+
logger.info("Page reloaded");
|
|
44
|
+
}
|
|
45
|
+
async goBack(timeout = 1e4) {
|
|
46
|
+
await (await this.collector.getActivePage()).goBack({
|
|
47
|
+
waitUntil: "domcontentloaded",
|
|
48
|
+
timeout
|
|
49
|
+
});
|
|
50
|
+
logger.info("Navigated back");
|
|
51
|
+
}
|
|
52
|
+
async goForward(timeout = 1e4) {
|
|
53
|
+
await (await this.collector.getActivePage()).goForward({
|
|
54
|
+
waitUntil: "domcontentloaded",
|
|
55
|
+
timeout
|
|
56
|
+
});
|
|
57
|
+
logger.info("Navigated forward");
|
|
58
|
+
}
|
|
59
|
+
async click(selector, options, frameOptions) {
|
|
60
|
+
const page = await this.collector.getActivePage();
|
|
61
|
+
await (await this.resolveFrame(page, frameOptions)).click(selector, {
|
|
62
|
+
button: options?.button || "left",
|
|
63
|
+
clickCount: options?.clickCount || 1,
|
|
64
|
+
delay: options?.delay
|
|
65
|
+
});
|
|
66
|
+
logger.info(`Clicked: ${selector}${frameOptions?.frameUrl || frameOptions?.frameSelector ? " (in frame)" : ""}`);
|
|
67
|
+
}
|
|
68
|
+
async type(selector, text, options, frameOptions) {
|
|
69
|
+
const page = await this.collector.getActivePage();
|
|
70
|
+
await (await this.resolveFrame(page, frameOptions)).type(selector, text, { delay: options?.delay });
|
|
71
|
+
logger.info(`Typed into ${selector}: ${text.substring(0, 20)}...`);
|
|
72
|
+
}
|
|
73
|
+
async select(selector, values, frameOptions) {
|
|
74
|
+
const page = await this.collector.getActivePage();
|
|
75
|
+
await (await this.resolveFrame(page, frameOptions)).select(selector, ...values);
|
|
76
|
+
logger.info(`Selected in ${selector}: ${values.join(", ")}`);
|
|
77
|
+
}
|
|
78
|
+
async hover(selector, frameOptions) {
|
|
79
|
+
const page = await this.collector.getActivePage();
|
|
80
|
+
await (await this.resolveFrame(page, frameOptions)).hover(selector);
|
|
81
|
+
logger.info(`Hovered: ${selector}`);
|
|
82
|
+
}
|
|
83
|
+
async scroll(options) {
|
|
84
|
+
await (await this.collector.getActivePage()).evaluate((opts) => {
|
|
85
|
+
window.scrollTo(opts.x || 0, opts.y || 0);
|
|
86
|
+
}, options);
|
|
87
|
+
logger.info(`Scrolled to: x=${options.x || 0}, y=${options.y || 0}`);
|
|
88
|
+
}
|
|
89
|
+
async waitForSelector(selector, timeout) {
|
|
90
|
+
try {
|
|
91
|
+
const page = await this.collector.getActivePage();
|
|
92
|
+
await page.waitForSelector(selector, { timeout: timeout || 3e4 });
|
|
93
|
+
const element = await page.evaluate((sel) => {
|
|
94
|
+
const el = document.querySelector(sel);
|
|
95
|
+
if (!el) return null;
|
|
96
|
+
return {
|
|
97
|
+
tagName: el.tagName.toLowerCase(),
|
|
98
|
+
id: el.id || void 0,
|
|
99
|
+
className: el.className || void 0,
|
|
100
|
+
textContent: el.textContent?.trim().substring(0, 100) || void 0,
|
|
101
|
+
attributes: Array.from(el.attributes).reduce((acc, attr) => {
|
|
102
|
+
acc[attr.name] = attr.value;
|
|
103
|
+
return acc;
|
|
104
|
+
}, {})
|
|
105
|
+
};
|
|
106
|
+
}, selector);
|
|
107
|
+
logger.info(`Selector appeared: ${selector}`);
|
|
108
|
+
return {
|
|
109
|
+
success: true,
|
|
110
|
+
element,
|
|
111
|
+
message: `Selector appeared: ${selector}`
|
|
112
|
+
};
|
|
113
|
+
} catch (error) {
|
|
114
|
+
logger.error(`waitForSelector timeout for ${selector}:`, error);
|
|
115
|
+
return {
|
|
116
|
+
success: false,
|
|
117
|
+
message: `Timeout waiting for selector: ${selector}`
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async waitForNavigation(timeout) {
|
|
122
|
+
await (await this.collector.getActivePage()).waitForNavigation({
|
|
123
|
+
waitUntil: "networkidle2",
|
|
124
|
+
timeout: timeout || 3e4
|
|
125
|
+
});
|
|
126
|
+
logger.info("Navigation completed");
|
|
127
|
+
}
|
|
128
|
+
async evaluate(code, frameOptions) {
|
|
129
|
+
const page = await this.collector.getActivePage();
|
|
130
|
+
if (frameOptions?.frameUrl || frameOptions?.frameSelector) {
|
|
131
|
+
const result = await evaluateOnContextWithTimeout(page, await this.resolveFrame(page, frameOptions), code);
|
|
132
|
+
logger.info("JavaScript executed (in frame)");
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
const result = await evaluateWithTimeout(page, code);
|
|
136
|
+
logger.info("JavaScript executed");
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Resolve a child frame from the active page.
|
|
141
|
+
* When no options are provided (or both fields are undefined), returns page.mainFrame().
|
|
142
|
+
*/
|
|
143
|
+
async resolveFrame(page, options) {
|
|
144
|
+
if (!options) return page.mainFrame();
|
|
145
|
+
if (options.frameUrl) {
|
|
146
|
+
const frames = page.frames();
|
|
147
|
+
const frame = frames.find((f) => f.url().includes(options.frameUrl));
|
|
148
|
+
if (!frame) {
|
|
149
|
+
const available = frames.map((f) => f.url()).filter((u) => u && u !== "about:blank");
|
|
150
|
+
throw new Error(`No frame matching URL substring "${options.frameUrl}". Available frames: ${available.join(", ") || "(none)"}`);
|
|
151
|
+
}
|
|
152
|
+
return frame;
|
|
153
|
+
}
|
|
154
|
+
if (options.frameSelector) {
|
|
155
|
+
await page.waitForSelector(options.frameSelector, { timeout: PAGE_FRAME_SELECTOR_TIMEOUT_MS }).catch(() => null);
|
|
156
|
+
const handle = await page.$(options.frameSelector);
|
|
157
|
+
if (!handle) throw new Error(`No element found for iframe selector: ${options.frameSelector}`);
|
|
158
|
+
const frame = await handle.contentFrame();
|
|
159
|
+
if (!frame) throw new Error(`Element "${options.frameSelector}" exists but has no content frame (not an iframe or not yet loaded).`);
|
|
160
|
+
return frame;
|
|
161
|
+
}
|
|
162
|
+
return page.mainFrame();
|
|
163
|
+
}
|
|
164
|
+
/** List all frames in the active page with URL and name info. */
|
|
165
|
+
async listFrames() {
|
|
166
|
+
const page = await this.collector.getActivePage();
|
|
167
|
+
const mainFrame = page.mainFrame();
|
|
168
|
+
return page.frames().map((frame) => ({
|
|
169
|
+
url: frame.url(),
|
|
170
|
+
name: frame.name() || "",
|
|
171
|
+
id: frame._id || "",
|
|
172
|
+
isMainFrame: frame === mainFrame
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
async getURL() {
|
|
176
|
+
return (await this.collector.getActivePage()).url();
|
|
177
|
+
}
|
|
178
|
+
async getTitle() {
|
|
179
|
+
return await (await this.collector.getActivePage()).title();
|
|
180
|
+
}
|
|
181
|
+
async getContent() {
|
|
182
|
+
return await (await this.collector.getActivePage()).content();
|
|
183
|
+
}
|
|
184
|
+
async screenshot(options) {
|
|
185
|
+
const page = await this.collector.getActivePage();
|
|
186
|
+
const screenshotOpts = {
|
|
187
|
+
path: options?.path,
|
|
188
|
+
type: options?.type || "png",
|
|
189
|
+
quality: options?.quality,
|
|
190
|
+
fullPage: options?.fullPage || false
|
|
191
|
+
};
|
|
192
|
+
if (options?.clip) {
|
|
193
|
+
screenshotOpts.clip = options.clip;
|
|
194
|
+
screenshotOpts.fullPage = false;
|
|
195
|
+
}
|
|
196
|
+
const buffer = await page.screenshot(screenshotOpts);
|
|
197
|
+
logger.info(`Screenshot taken${options?.path ? `: ${options.path}` : ""}`);
|
|
198
|
+
return buffer;
|
|
199
|
+
}
|
|
200
|
+
async getPerformanceMetrics() {
|
|
201
|
+
const metrics = await evaluateWithTimeout(await this.collector.getActivePage(), () => {
|
|
202
|
+
const perf = performance.getEntriesByType("navigation")[0];
|
|
203
|
+
return {
|
|
204
|
+
domContentLoaded: perf.domContentLoadedEventEnd - perf.domContentLoadedEventStart,
|
|
205
|
+
loadComplete: perf.loadEventEnd - perf.loadEventStart,
|
|
206
|
+
dns: perf.domainLookupEnd - perf.domainLookupStart,
|
|
207
|
+
tcp: perf.connectEnd - perf.connectStart,
|
|
208
|
+
request: perf.responseStart - perf.requestStart,
|
|
209
|
+
response: perf.responseEnd - perf.responseStart,
|
|
210
|
+
total: perf.loadEventEnd - perf.fetchStart,
|
|
211
|
+
resources: performance.getEntriesByType("resource").length
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
logger.info("Performance metrics retrieved");
|
|
215
|
+
return metrics;
|
|
216
|
+
}
|
|
217
|
+
async injectScript(scriptContent) {
|
|
218
|
+
await evaluateWithTimeout(await this.collector.getActivePage(), (script) => {
|
|
219
|
+
const scriptElement = document.createElement("script");
|
|
220
|
+
scriptElement.textContent = script;
|
|
221
|
+
document.head.appendChild(scriptElement);
|
|
222
|
+
}, scriptContent);
|
|
223
|
+
logger.info("Script injected into page");
|
|
224
|
+
}
|
|
225
|
+
async setCookies(cookies) {
|
|
226
|
+
await (await this.collector.getActivePage()).setCookie(...cookies);
|
|
227
|
+
logger.info(`Set ${cookies.length} cookies`);
|
|
228
|
+
}
|
|
229
|
+
async getCookies() {
|
|
230
|
+
const cookies = await (await this.collector.getActivePage()).cookies();
|
|
231
|
+
logger.info(`Retrieved ${cookies.length} cookies`);
|
|
232
|
+
return cookies;
|
|
233
|
+
}
|
|
234
|
+
async clearCookies() {
|
|
235
|
+
const page = await this.collector.getActivePage();
|
|
236
|
+
const cookies = await page.cookies();
|
|
237
|
+
await page.deleteCookie(...cookies);
|
|
238
|
+
logger.info("All cookies cleared");
|
|
239
|
+
}
|
|
240
|
+
async setViewport(width, height) {
|
|
241
|
+
await (await this.collector.getActivePage()).setViewport({
|
|
242
|
+
width,
|
|
243
|
+
height
|
|
244
|
+
});
|
|
245
|
+
logger.info(`Viewport set to ${width}x${height}`);
|
|
246
|
+
}
|
|
247
|
+
async emulateDevice(deviceName) {
|
|
248
|
+
const page = await this.collector.getActivePage();
|
|
249
|
+
const devices = {
|
|
250
|
+
iPhone: {
|
|
251
|
+
viewport: {
|
|
252
|
+
width: 375,
|
|
253
|
+
height: 812,
|
|
254
|
+
isMobile: true
|
|
255
|
+
},
|
|
256
|
+
userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15"
|
|
257
|
+
},
|
|
258
|
+
iPad: {
|
|
259
|
+
viewport: {
|
|
260
|
+
width: 768,
|
|
261
|
+
height: 1024,
|
|
262
|
+
isMobile: true
|
|
263
|
+
},
|
|
264
|
+
userAgent: "Mozilla/5.0 (iPad; CPU OS 14_0 like Mac OS X) AppleWebKit/605.1.15"
|
|
265
|
+
},
|
|
266
|
+
Android: {
|
|
267
|
+
viewport: {
|
|
268
|
+
width: 360,
|
|
269
|
+
height: 640,
|
|
270
|
+
isMobile: true
|
|
271
|
+
},
|
|
272
|
+
userAgent: "Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 Chrome/91.0.4472.120"
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
const normalized = String(deviceName || "").trim().toLowerCase();
|
|
276
|
+
let resolvedDevice = null;
|
|
277
|
+
if (normalized.includes("iphone")) resolvedDevice = "iPhone";
|
|
278
|
+
else if (normalized.includes("ipad")) resolvedDevice = "iPad";
|
|
279
|
+
else if (normalized.includes("android") || normalized.includes("pixel")) resolvedDevice = "Android";
|
|
280
|
+
if (!resolvedDevice) throw new Error(`Unsupported device "${deviceName}". Supported values include: iPhone, iPad, Android (aliases like "iPhone 13" are accepted).`);
|
|
281
|
+
const device = devices[resolvedDevice];
|
|
282
|
+
await page.setViewport(device.viewport);
|
|
283
|
+
await page.setUserAgent(device.userAgent);
|
|
284
|
+
logger.info(`Emulating ${resolvedDevice} (input: ${deviceName})`);
|
|
285
|
+
return resolvedDevice;
|
|
286
|
+
}
|
|
287
|
+
async waitForNetworkIdle(timeout = PAGE_NETWORK_IDLE_TIMEOUT_MS) {
|
|
288
|
+
await (await this.collector.getActivePage()).waitForNetworkIdle({ timeout });
|
|
289
|
+
logger.info("Network is idle");
|
|
290
|
+
}
|
|
291
|
+
async getLocalStorage() {
|
|
292
|
+
const storage = await (await this.collector.getActivePage()).evaluate(() => {
|
|
293
|
+
const items = {};
|
|
294
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
295
|
+
const key = localStorage.key(i);
|
|
296
|
+
if (key) items[key] = localStorage.getItem(key) || "";
|
|
297
|
+
}
|
|
298
|
+
return items;
|
|
299
|
+
});
|
|
300
|
+
logger.info(`Retrieved ${Object.keys(storage).length} localStorage items`);
|
|
301
|
+
return storage;
|
|
302
|
+
}
|
|
303
|
+
async setLocalStorage(key, value) {
|
|
304
|
+
await (await this.collector.getActivePage()).evaluate((k, v) => {
|
|
305
|
+
localStorage.setItem(k, v);
|
|
306
|
+
}, key, value);
|
|
307
|
+
logger.info(`Set localStorage: ${key}`);
|
|
308
|
+
}
|
|
309
|
+
async clearLocalStorage() {
|
|
310
|
+
await (await this.collector.getActivePage()).evaluate(() => {
|
|
311
|
+
localStorage.clear();
|
|
312
|
+
});
|
|
313
|
+
logger.info("LocalStorage cleared");
|
|
314
|
+
}
|
|
315
|
+
async pressKey(key) {
|
|
316
|
+
await (await this.collector.getActivePage()).keyboard.press(key);
|
|
317
|
+
logger.info(`Pressed key: ${key}`);
|
|
318
|
+
}
|
|
319
|
+
async uploadFile(selector, filePath) {
|
|
320
|
+
const input = await (await this.collector.getActivePage()).$(selector);
|
|
321
|
+
if (!input) throw new Error(`File input not found: ${selector}`);
|
|
322
|
+
await input.uploadFile(filePath);
|
|
323
|
+
logger.info(`File uploaded: ${filePath}`);
|
|
324
|
+
}
|
|
325
|
+
async getAllLinks() {
|
|
326
|
+
const links = await (await this.collector.getActivePage()).evaluate(() => {
|
|
327
|
+
const anchors = document.querySelectorAll("a[href]");
|
|
328
|
+
const result = [];
|
|
329
|
+
for (let i = 0; i < anchors.length; i++) {
|
|
330
|
+
const anchor = anchors[i];
|
|
331
|
+
result.push({
|
|
332
|
+
text: anchor.textContent?.trim() || "",
|
|
333
|
+
href: anchor.href
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
return result;
|
|
337
|
+
});
|
|
338
|
+
logger.info(`Found ${links.length} links`);
|
|
339
|
+
return links;
|
|
340
|
+
}
|
|
341
|
+
async getPage() {
|
|
342
|
+
return await this.collector.getActivePage();
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
/**
|
|
346
|
+
* Pre-flight CDP health check: verify the page CDP target is responsive.
|
|
347
|
+
* After debugger enable + pause/resume, the Playwright CDP session can enter
|
|
348
|
+
* a zombie state where Runtime.evaluate hangs indefinitely without firing
|
|
349
|
+
* 'disconnected'. Without this check, page.evaluate() blocks for the full 30 s
|
|
350
|
+
* timeout — with this check we fail fast (~3 s) with a clear message.
|
|
351
|
+
*/
|
|
352
|
+
async function checkPageCDPHealth(page, timeoutMs = 500) {
|
|
353
|
+
const ac = new AbortController();
|
|
354
|
+
const timer = setTimeout$1(timeoutMs, void 0, { signal: ac.signal }).then(() => {
|
|
355
|
+
throw new Error("cdp_unreachable");
|
|
356
|
+
});
|
|
357
|
+
try {
|
|
358
|
+
const cdp = await Promise.race([page.createCDPSession(), timer]);
|
|
359
|
+
await Promise.race([cdp.send("Runtime.evaluate", {
|
|
360
|
+
expression: "1",
|
|
361
|
+
returnByValue: true
|
|
362
|
+
}), timer]);
|
|
363
|
+
} catch (err) {
|
|
364
|
+
if ((err instanceof Error ? err.message : String(err)) === "cdp_unreachable") throw new Error("CDP session unresponsive — the debugger may be blocking page evaluation. Call debugger_lifecycle({ action: 'disable' })() before this tool, or run it before debugger_lifecycle({ action: 'enable' })().", { cause: err });
|
|
365
|
+
throw err;
|
|
366
|
+
} finally {
|
|
367
|
+
ac.abort();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
async function evaluateOnContextWithTimeout(page, context, pageFunction, ...args) {
|
|
371
|
+
const timeoutMs = 3e4;
|
|
372
|
+
await checkPageCDPHealth(page);
|
|
373
|
+
return Promise.race([context.evaluate(pageFunction, ...[...args]), new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error(`page.evaluate timed out after ${timeoutMs}ms`)), timeoutMs))]);
|
|
374
|
+
}
|
|
375
|
+
async function evaluateWithTimeout(page, pageFunction, ...args) {
|
|
376
|
+
return evaluateOnContextWithTimeout(page, page, pageFunction, ...args);
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Wrap a page.evaluateOnNewDocument() call with:
|
|
380
|
+
* 1. A CDP pre-flight health check
|
|
381
|
+
* 2. A hard timeout (30 s) as a backstop
|
|
382
|
+
*/
|
|
383
|
+
async function evaluateOnNewDocumentWithTimeout(page, pageFunction, ...args) {
|
|
384
|
+
const timeoutMs = 3e4;
|
|
385
|
+
await checkPageCDPHealth(page);
|
|
386
|
+
return Promise.race([page.evaluateOnNewDocument(pageFunction, ...[...args]), new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error(`page.evaluateOnNewDocument timed out after ${timeoutMs}ms`)), timeoutMs))]);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Wrap page.coverage.startJSCoverage() with a timeout.
|
|
390
|
+
*/
|
|
391
|
+
async function coverageStartJSWithTimeout(page, options) {
|
|
392
|
+
const timeoutMs = 3e4;
|
|
393
|
+
return Promise.race([page.coverage.startJSCoverage(options), new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error(`coverage.startJSCoverage timed out after ${timeoutMs}ms`)), timeoutMs))]);
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Wrap page.coverage.startCSSCoverage() with a timeout.
|
|
397
|
+
*/
|
|
398
|
+
async function coverageStartCSSWithTimeout(page, options) {
|
|
399
|
+
const timeoutMs = 3e4;
|
|
400
|
+
return Promise.race([page.coverage.startCSSCoverage(options), new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error(`coverage.startCSSCoverage timed out after ${timeoutMs}ms`)), timeoutMs))]);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Wrap page.coverage.stopJSCoverage() with a timeout.
|
|
404
|
+
*/
|
|
405
|
+
async function coverageStopJSWithTimeout(page) {
|
|
406
|
+
const timeoutMs = 3e4;
|
|
407
|
+
return Promise.race([page.coverage.stopJSCoverage(), new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error(`coverage.stopJSCoverage timed out after ${timeoutMs}ms`)), timeoutMs))]);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Wrap page.coverage.stopCSSCoverage() with a timeout.
|
|
411
|
+
*/
|
|
412
|
+
async function coverageStopCSSWithTimeout(page) {
|
|
413
|
+
const timeoutMs = 3e4;
|
|
414
|
+
return Promise.race([page.coverage.stopCSSCoverage(), new Promise((_, reject) => setTimeout(() => reject(/* @__PURE__ */ new Error(`coverage.stopCSSCoverage timed out after ${timeoutMs}ms`)), timeoutMs))]);
|
|
415
|
+
}
|
|
416
|
+
//#endregion
|
|
417
|
+
export { coverageStopJSWithTimeout as a, coverageStopCSSWithTimeout as i, coverageStartCSSWithTimeout as n, evaluateOnNewDocumentWithTimeout as o, coverageStartJSWithTimeout as r, evaluateWithTimeout as s, PageController as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
3
|
-
import { t as
|
|
4
|
-
import { n as parseAddress, t as formatAddress } from "./formatAddress-
|
|
1
|
+
import { Jt as POINTER_CHAIN_MAX_DEPTH, Xt as POINTER_CHAIN_MAX_RESULTS, Yt as POINTER_CHAIN_MAX_OFFSET, Zt as POINTER_CHAIN_SCAN_CHUNK_SIZE } from "./constants-B0OANIBL.mjs";
|
|
2
|
+
import { t as createPlatformProvider } from "./factory-DxlGh9Xf.mjs";
|
|
3
|
+
import { t as nativeMemoryManager } from "./NativeMemoryManager.impl-dZtA1ZGn.mjs";
|
|
4
|
+
import { n as parseAddress, t as formatAddress } from "./formatAddress-DVkj9kpI.mjs";
|
|
5
5
|
import { randomUUID } from "node:crypto";
|
|
6
6
|
//#region src/native/PointerChainEngine.ts
|
|
7
7
|
/**
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { t as ToolError } from "./ToolError-jh9whhMd.mjs";
|
|
2
|
+
//#region src/errors/PrerequisiteError.ts
|
|
3
|
+
/**
|
|
4
|
+
* Thrown when a tool's prerequisite is not met (e.g. debugger not enabled,
|
|
5
|
+
* browser not connected, profiling not started).
|
|
6
|
+
*
|
|
7
|
+
* The MCP server catches this and returns a graceful
|
|
8
|
+
* `{ success: false, message }` response instead of `isError: true`.
|
|
9
|
+
*
|
|
10
|
+
* Extends ToolError with code 'PREREQUISITE' for unified error classification.
|
|
11
|
+
* Constructor signature unchanged — backward-compatible with all existing callers.
|
|
12
|
+
*/
|
|
13
|
+
var PrerequisiteError = class extends ToolError {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super("PREREQUISITE", message);
|
|
16
|
+
this.name = "PrerequisiteError";
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { PrerequisiteError as t };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
//#region src/server/domains/shared/ResponseBuilder.ts
|
|
2
|
+
/**
|
|
3
|
+
* Fluent builder for MCP tool responses.
|
|
4
|
+
*
|
|
5
|
+
* Replaces the verbose 14-line deep-nesting pattern:
|
|
6
|
+
* ```
|
|
7
|
+
* return { content: [{ type: 'text', text: JSON.stringify({...}, null, 2) }] };
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* With a chainable API:
|
|
11
|
+
* ```
|
|
12
|
+
* return R.ok().set('driver', 'chrome').json();
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
var ResponseBuilder = class {
|
|
16
|
+
payload = {};
|
|
17
|
+
_isError = false;
|
|
18
|
+
_additionalContent = [];
|
|
19
|
+
_useStructured = false;
|
|
20
|
+
/** Mark as success (sets `success: true`). */
|
|
21
|
+
ok() {
|
|
22
|
+
this.payload.success = true;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
/** Mark as failure (sets `success: false, error: <message>, message: <message>`). */
|
|
26
|
+
fail(error) {
|
|
27
|
+
this.payload.success = false;
|
|
28
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
29
|
+
this.payload.error = msg;
|
|
30
|
+
this.payload.message = msg;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
/** Set a single key-value pair. */
|
|
34
|
+
set(key, value) {
|
|
35
|
+
this.payload[key] = value;
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
/** Merge multiple fields at once. */
|
|
39
|
+
merge(fields) {
|
|
40
|
+
Object.assign(this.payload, fields);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
/** Set MCP-level `isError: true` on the response envelope. */
|
|
44
|
+
mcpError() {
|
|
45
|
+
this._isError = true;
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
/** Push an image block to the final response. */
|
|
49
|
+
image(base64, mimeType) {
|
|
50
|
+
this._additionalContent.push({
|
|
51
|
+
type: "image",
|
|
52
|
+
data: base64,
|
|
53
|
+
mimeType
|
|
54
|
+
});
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
/** Push an embedded resource block to the final response. */
|
|
58
|
+
embeddedResource(uri, text, mimeType = "text/plain") {
|
|
59
|
+
this._additionalContent.push({
|
|
60
|
+
type: "resource",
|
|
61
|
+
resource: {
|
|
62
|
+
uri,
|
|
63
|
+
text,
|
|
64
|
+
mimeType
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/** Send output payload natively as `structuredContent` in the MCP envelope instead of stringifying inside text block. */
|
|
70
|
+
structured() {
|
|
71
|
+
this._useStructured = true;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build the ToolResponse. Handles text vs structured plus extra blocks.
|
|
76
|
+
* Optionally merges extra fields before building.
|
|
77
|
+
*/
|
|
78
|
+
json(fields) {
|
|
79
|
+
if (fields) this.merge(fields);
|
|
80
|
+
return {
|
|
81
|
+
content: [{
|
|
82
|
+
type: "text",
|
|
83
|
+
text: JSON.stringify(this.payload, null, 2)
|
|
84
|
+
}, ...this._additionalContent],
|
|
85
|
+
...this._isError ? { isError: true } : {},
|
|
86
|
+
...this._useStructured ? { structuredContent: this.payload } : {}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** Alias for json(). */
|
|
90
|
+
build(fields) {
|
|
91
|
+
return this.json(fields);
|
|
92
|
+
}
|
|
93
|
+
/** Build a ToolResponse from an arbitrary value (no success/error wrapper). */
|
|
94
|
+
static raw(data) {
|
|
95
|
+
return { content: [{
|
|
96
|
+
type: "text",
|
|
97
|
+
text: JSON.stringify(data, null, 2)
|
|
98
|
+
}] };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Build a ToolResponse from a plain text string.
|
|
102
|
+
* Setting `isError = true` returns a soft error for macro compatibility
|
|
103
|
+
* without triggering a JSON-RPC ErrorCode.
|
|
104
|
+
*/
|
|
105
|
+
static text(text, isError = false) {
|
|
106
|
+
return {
|
|
107
|
+
content: [{
|
|
108
|
+
type: "text",
|
|
109
|
+
text
|
|
110
|
+
}],
|
|
111
|
+
...isError ? { isError: true } : {}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Safely extract and parse JSON from an MCP ToolResponse.
|
|
116
|
+
* Useful for consuming tool results in workflow/orchestration logic.
|
|
117
|
+
*/
|
|
118
|
+
static parse(response) {
|
|
119
|
+
if (!response.content || response.content.length === 0) throw new Error("ToolResponse has no content");
|
|
120
|
+
const textBlock = response.content.find((c) => c.type === "text");
|
|
121
|
+
if (!textBlock || !("text" in textBlock)) throw new Error("ToolResponse has no text content block");
|
|
122
|
+
try {
|
|
123
|
+
return JSON.parse(textBlock.text);
|
|
124
|
+
} catch (e) {
|
|
125
|
+
throw new Error(`Failed to parse tool result as JSON: ${String(e)}\nRaw text: ${textBlock.text.substring(0, 500)}`, { cause: e });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
/** Shorthand factory — the primary entry point for building responses. */
|
|
130
|
+
const R = {
|
|
131
|
+
/** Start a success response (`{ success: true, ... }`). */
|
|
132
|
+
ok: () => new ResponseBuilder().ok(),
|
|
133
|
+
/** Start a failure response (`{ success: false, error: "..." }`). */
|
|
134
|
+
fail: (error) => new ResponseBuilder().fail(error),
|
|
135
|
+
/** Wrap an existing object as-is (no success/error wrapper). */
|
|
136
|
+
raw: (data) => ResponseBuilder.raw(data),
|
|
137
|
+
/** Wrap a plain text string. */
|
|
138
|
+
text: (text, isError = false) => ResponseBuilder.text(text, isError),
|
|
139
|
+
/** Parse a response back into an object. */
|
|
140
|
+
parse: (response) => ResponseBuilder.parse(response)
|
|
141
|
+
};
|
|
142
|
+
//#endregion
|
|
143
|
+
export { R as t };
|