rea-agents 2.3.0 → 2.5.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/README.md +80 -18
- package/bridge/ghidra/ReaGhidraBridge.java +48 -1
- package/bridge/hopper_bridge.py +259 -24
- package/dist/application/AnalysisClientCleanup.js +14 -0
- package/dist/application/ApplicationWorkflowEvidenceResolver.js +31 -13
- package/dist/application/ArtifactExtraction.js +5 -1
- package/dist/application/ArtifactGraphConstruction.js +3 -15
- package/dist/application/ArtifactInventory/classify.js +5 -1
- package/dist/application/ArtifactInventory/reader.js +2 -0
- package/dist/application/BinarySession.js +15 -4
- package/dist/application/BinarySessionStatus.js +32 -1
- package/dist/application/BrowserEvidence.js +14 -0
- package/dist/application/BrowserScenarioCapturePort.js +1 -0
- package/dist/application/BrowserScenarioCaptureService.js +53 -0
- package/dist/application/BrowserScenarioEvidence.js +40 -0
- package/dist/application/CallPathTracing.js +160 -0
- package/dist/application/CapabilityInventory.js +79 -15
- package/dist/application/CompositeProvider.js +10 -1
- package/dist/application/DirectAnalysis.js +7 -2
- package/dist/application/EnhancedLiteralTracing.js +118 -0
- package/dist/application/EnhancedTools.js +35 -121
- package/dist/application/JavaScriptApplicationWorkflowEvidence.js +13 -0
- package/dist/application/JavaScriptApplicationWorkflowService.js +27 -1
- package/dist/application/JavaScriptRuntimeObservationEvidence.js +34 -0
- package/dist/application/JavaScriptRuntimeObservationPort.js +1 -0
- package/dist/application/JavaScriptRuntimeObservationService.js +46 -0
- package/dist/application/JavaScriptSemanticGraphAsyncProjection.js +147 -0
- package/dist/application/JavaScriptSemanticGraphBuilder.js +34 -6
- package/dist/application/JavaScriptSemanticGraphChildProcessProjection.js +156 -0
- package/dist/application/JavaScriptSemanticGraphConstruction.js +2 -2
- package/dist/application/JavaScriptSemanticGraphDataProjection.js +203 -0
- package/dist/application/JavaScriptSemanticGraphFingerprintProjection.js +25 -0
- package/dist/application/JavaScriptSemanticGraphFlowProjection.js +129 -8
- package/dist/application/JavaScriptSemanticGraphObjectProjection.js +81 -0
- package/dist/application/JavaScriptSemanticGraphProjection.js +14 -7
- package/dist/application/JavaScriptSemanticGraphResourceProjection.js +59 -0
- package/dist/application/JavaScriptSemanticGraphValueProjection.js +77 -0
- package/dist/application/ProcessCaptureEnvironment.js +26 -0
- package/dist/application/ProcessCaptureLifecycle.js +1 -0
- package/dist/application/ProcessCheckpoints.js +5 -0
- package/dist/application/ProcessHarness.js +45 -34
- package/dist/application/ProcessNormalization.js +6 -0
- package/dist/application/ProcessReactiveCoordinator.js +10 -3
- package/dist/application/ProcessReactiveEffects.js +15 -1
- package/dist/application/ProcessReactiveHarness.js +100 -0
- package/dist/application/ProcessReactiveObservations.js +101 -16
- package/dist/application/ProjectPermissionStore.js +1 -0
- package/dist/application/ReconstructionObligationAuthority.js +72 -0
- package/dist/application/ReconstructionObligationCandidates.js +265 -0
- package/dist/application/ReconstructionObligationLedgerDiagnostics.js +47 -0
- package/dist/application/ReconstructionObligationLedgerEvaluation.js +263 -0
- package/dist/application/ReconstructionObligationLedgerProjection.js +86 -0
- package/dist/application/ReconstructionObligationLedgerService.js +72 -0
- package/dist/application/ReconstructionObligationOriginalCases.js +33 -0
- package/dist/application/ReconstructionObligationPolicies.js +132 -0
- package/dist/application/ReconstructionReadinessService.js +48 -0
- package/dist/artifacts/ArtifactProvider.js +87 -22
- package/dist/browser/BrowserScenarioSecrets.js +53 -0
- package/dist/browser/BrowserScenarioSessionPort.js +1 -0
- package/dist/browser/CdpBrowserProvider.js +2 -2
- package/dist/browser/CdpCaptureDocuments.js +57 -0
- package/dist/browser/CdpCaptureStorage.js +71 -29
- package/dist/browser/CdpCaptureStorageFingerprints.js +328 -0
- package/dist/browser/CdpEndpoint.js +8 -6
- package/dist/browser/CdpPageCapture.js +2 -0
- package/dist/browser/JavaScriptRuntimeScope.js +38 -0
- package/dist/browser/PlaywrightBrowserScenarioProvider.js +253 -0
- package/dist/browser/PlaywrightExecutionBoundary.js +42 -0
- package/dist/browser/PlaywrightScenarioActions.js +62 -0
- package/dist/browser/PlaywrightScenarioArtifacts.js +238 -0
- package/dist/browser/PlaywrightScenarioBrowser.js +144 -0
- package/dist/browser/PlaywrightScenarioEvents.js +301 -0
- package/dist/browser/PlaywrightScenarioSession.js +300 -0
- package/dist/browser/V8InspectorCaptureProjection.js +110 -0
- package/dist/browser/V8InspectorEndpoint.js +72 -0
- package/dist/browser/V8InspectorProvider.js +267 -0
- package/dist/catalogIdentity.js +8 -0
- package/dist/cli/artifactCommands.js +39 -0
- package/dist/cli/coreAnalysisCommands.js +37 -0
- package/dist/cli.js +4 -0
- package/dist/cliApplicationCommands.js +30 -2
- package/dist/cliBrowserAdvancedCommands.js +17 -5
- package/dist/cliBrowserCommands.js +1 -0
- package/dist/cliBrowserScenarioCommands.js +43 -0
- package/dist/cliCommandNames.js +8 -0
- package/dist/cliJavaScriptRuntimeCommands.js +164 -0
- package/dist/cliObservationOptions.js +4 -0
- package/dist/cliPolicyCommands.js +1 -0
- package/dist/config/environment.js +12 -0
- package/dist/config/parseConfig.js +88 -17
- package/dist/contracts/analysisSearchContract.js +14 -0
- package/dist/contracts/applicationToolContracts.js +86 -2
- package/dist/contracts/applicationWorkflowInputContracts.js +18 -0
- package/dist/contracts/artifactToolContracts.js +22 -0
- package/dist/contracts/browserProviderToolContracts.js +7 -0
- package/dist/contracts/browserScenarioToolContracts.js +81 -0
- package/dist/contracts/browserToolContracts.js +88 -98
- package/dist/contracts/enhancedInputs.js +25 -6
- package/dist/contracts/functionInstructionContract.js +8 -0
- package/dist/contracts/hopperMemoryContracts.js +22 -0
- package/dist/contracts/javascriptApplicationWorkflowExamples.js +42 -0
- package/dist/contracts/javascriptRuntimeObservationToolContracts.js +58 -0
- package/dist/contracts/reconstructionReadinessExample.js +436 -0
- package/dist/contracts/toolContractExamples.js +5 -0
- package/dist/contracts/toolContractTypes.js +1 -0
- package/dist/contracts/toolContracts.js +13 -21
- package/dist/contracts/toolEffects.js +21 -0
- package/dist/contracts/toolOutputSchemaGroups.js +70 -20
- package/dist/contracts/toolOutputSchemaPrimitives.js +40 -0
- package/dist/domain/analysisErrorProjection.js +8 -0
- package/dist/domain/analysisSnapshot.js +2 -0
- package/dist/domain/artifactGraph.js +2 -0
- package/dist/domain/artifactInspection.js +347 -0
- package/dist/domain/binaryTarget.js +3 -6
- package/dist/domain/browserCaptureComparison.js +82 -0
- package/dist/domain/browserObservation.js +8 -1
- package/dist/domain/browserObservationErrors.js +1 -0
- package/dist/domain/browserObservationSchemas.js +26 -0
- package/dist/domain/browserScenario.js +165 -0
- package/dist/domain/browserScenarioCapture.js +57 -0
- package/dist/domain/browserScenarioCaptureValues.js +204 -0
- package/dist/domain/browserScenarioDiff.js +324 -0
- package/dist/domain/browserScenarioDiffValues.js +157 -0
- package/dist/domain/browserScenarioNormalization.js +45 -0
- package/dist/domain/browserScenarioValues.js +372 -0
- package/dist/domain/evidence.js +2 -0
- package/dist/domain/hopperValues.js +10 -0
- package/dist/domain/javascriptRuntimeObservation.js +170 -0
- package/dist/domain/javascriptRuntimeReconciliationParsing.js +120 -2
- package/dist/domain/javascriptRuntimeReconciliationResult.js +3 -3
- package/dist/domain/javascriptRuntimeReconciliationRuntime.js +2 -2
- package/dist/domain/javascriptRuntimeReconciliationSchemas.js +1 -1
- package/dist/domain/javascriptSemanticAnalysis.js +5 -4
- package/dist/domain/javascriptSemanticAsyncEffects.js +253 -0
- package/dist/domain/javascriptSemanticChildProcesses.js +237 -0
- package/dist/domain/javascriptSemanticDataEffectHelpers.js +125 -0
- package/dist/domain/javascriptSemanticDataEffects.js +284 -0
- package/dist/domain/javascriptSemanticDerivedAnalysis.js +41 -0
- package/dist/domain/javascriptSemanticFingerprints.js +174 -0
- package/dist/domain/javascriptSemanticIr.js +21 -1
- package/dist/domain/javascriptSemanticObjects.js +115 -0
- package/dist/domain/javascriptSemanticPromises.js +290 -0
- package/dist/domain/javascriptSemanticResources.js +136 -0
- package/dist/domain/javascriptStaticAnalysis.js +4 -3
- package/dist/domain/javascriptStaticAnalysisBundler.js +38 -0
- package/dist/domain/javascriptStaticAnalysisCalls.js +23 -1
- package/dist/domain/javascriptStaticAnalysisHelpers.js +8 -0
- package/dist/domain/processCapture.js +71 -1
- package/dist/domain/processCaptureReactiveValidation.js +175 -0
- package/dist/domain/processCaptureValidation.js +2 -0
- package/dist/domain/processObservation.js +15 -6
- package/dist/domain/processReactiveRuntime.js +21 -10
- package/dist/domain/processReactiveScenario.js +1 -0
- package/dist/domain/processReactiveTransition.js +17 -10
- package/dist/domain/processScenario.js +21 -0
- package/dist/domain/providerCleanupError.js +11 -0
- package/dist/domain/reconstructionObligationLedgerSchemas.js +278 -0
- package/dist/domain/reconstructionReadiness.js +121 -0
- package/dist/domain/reconstructionReadinessFindingHelpers.js +17 -0
- package/dist/domain/reconstructionReadinessIntegrityFindings.js +118 -0
- package/dist/domain/reconstructionReadinessJourneyFindings.js +193 -0
- package/dist/domain/reconstructionReadinessSchemas.js +240 -0
- package/dist/domain/sourceToBundleComparison.js +335 -0
- package/dist/domain/sourceToBundleComparisonSchemas.js +133 -0
- package/dist/domain/sourceToBundleSignals.js +202 -0
- package/dist/domain/webCaptureDiff.js +141 -27
- package/dist/domain/webScreenshot.js +1 -1
- package/dist/domain/zipPackageFormat.js +20 -0
- package/dist/generatedPackageMetadata.js +1 -1
- package/dist/ghidra/GhidraDefaults.js +1 -1
- package/dist/ghidra/GhidraFunctionValues.js +13 -1
- package/dist/ghidra/GhidraProviderCapabilities.js +7 -0
- package/dist/hopper/HopperCleanup.js +158 -0
- package/dist/hopper/HopperClient.js +69 -99
- package/dist/hopper/HopperProvider.js +20 -1
- package/dist/hopper/HopperRequestQueue.js +187 -0
- package/dist/hopper/HopperResponseStream.js +46 -0
- package/dist/hopper/protocol.js +1 -0
- package/dist/main/transport.js +24 -24
- package/dist/main.js +6 -0
- package/dist/mcpDoctor.js +25 -2
- package/dist/native/NativeMacOSProvider.js +1 -0
- package/dist/process/ProcessCommandIdentity.js +19 -0
- package/dist/process/ProcessOwnership.js +11 -8
- package/dist/server/DynamicToolAvailability.js +70 -0
- package/dist/server/createServer.js +46 -1
- package/dist/server/lifecycleProgress.js +10 -0
- package/dist/server/permissionFailure.js +12 -0
- package/dist/server/registerApplicationTools/compareSourceToBundle.js +35 -0
- package/dist/server/registerApplicationTools/helpers.js +11 -7
- package/dist/server/registerApplicationTools/obligationLedger.js +27 -0
- package/dist/server/registerApplicationTools/readiness.js +55 -0
- package/dist/server/registerApplicationTools.js +6 -0
- package/dist/server/registerArtifactTools.js +9 -1
- package/dist/server/registerBrowserScenarioTool.js +25 -0
- package/dist/server/registerBrowserTools.js +2 -2
- package/dist/server/registerCloseLifecycleTool.js +57 -0
- package/dist/server/registerEnhancedTools.js +16 -5
- package/dist/server/registerEvidenceResources.js +4 -0
- package/dist/server/registerEvidenceTools.js +9 -2
- package/dist/server/registerJavaScriptRuntimeObservationTools.js +37 -0
- package/dist/server/registerReconstructionObligationLedgerResource.js +39 -0
- package/dist/server/registerReconstructionReadinessResource.js +39 -0
- package/dist/server/registerSessionStatusTool.js +11 -8
- package/dist/server/registerSessionTools.js +11 -57
- package/dist/server/sessionAvailabilityPolicy.js +10 -8
- package/package.json +12 -6
- package/skills/reverse-engineer-anything/SKILL.md +4 -3
- package/skills/reverse-engineer-anything/references/native-and-artifacts.md +2 -2
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { sanitizeBrowserUrl } from "../domain/browserObservation.js";
|
|
2
|
+
import { browserScenarioEventSchema, } from "../domain/browserScenarioCapture.js";
|
|
3
|
+
/** Bounded, arrival-ordered Playwright event capture with current-step attribution. */
|
|
4
|
+
export class PlaywrightScenarioEvents {
|
|
5
|
+
items = [];
|
|
6
|
+
truncated = new Set();
|
|
7
|
+
admitted = {
|
|
8
|
+
frames: new WeakSet(),
|
|
9
|
+
workers: new WeakSet(),
|
|
10
|
+
popups: new WeakSet(),
|
|
11
|
+
websockets: new WeakSet(),
|
|
12
|
+
};
|
|
13
|
+
rejected = {
|
|
14
|
+
frames: new WeakSet(),
|
|
15
|
+
workers: new WeakSet(),
|
|
16
|
+
popups: new WeakSet(),
|
|
17
|
+
websockets: new WeakSet(),
|
|
18
|
+
};
|
|
19
|
+
counts = {
|
|
20
|
+
frames: 0,
|
|
21
|
+
workers: 0,
|
|
22
|
+
popups: 0,
|
|
23
|
+
websockets: 0,
|
|
24
|
+
};
|
|
25
|
+
dropped = 0;
|
|
26
|
+
stepIndex = 0;
|
|
27
|
+
sequence = 0;
|
|
28
|
+
enabled;
|
|
29
|
+
limits;
|
|
30
|
+
secrets;
|
|
31
|
+
budget;
|
|
32
|
+
allowedOrigins;
|
|
33
|
+
constructor(options) {
|
|
34
|
+
this.enabled = options.enabled;
|
|
35
|
+
this.limits = options.limits;
|
|
36
|
+
this.secrets = options.secrets;
|
|
37
|
+
this.budget = options.budget;
|
|
38
|
+
this.allowedOrigins = new Set(options.allowedOrigins);
|
|
39
|
+
this.observePage(options.page);
|
|
40
|
+
}
|
|
41
|
+
setStep(index) {
|
|
42
|
+
this.stepIndex = index;
|
|
43
|
+
}
|
|
44
|
+
nextSequence() {
|
|
45
|
+
return this.sequence + 1;
|
|
46
|
+
}
|
|
47
|
+
lastSequence() {
|
|
48
|
+
return this.sequence;
|
|
49
|
+
}
|
|
50
|
+
result() {
|
|
51
|
+
return {
|
|
52
|
+
retained: this.items.length,
|
|
53
|
+
dropped: this.dropped,
|
|
54
|
+
items: this.items,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
truncationSections() {
|
|
58
|
+
return [...this.truncated].sort();
|
|
59
|
+
}
|
|
60
|
+
push(event) {
|
|
61
|
+
this.sequence += 1;
|
|
62
|
+
if (this.items.length >= this.limits.max_events) {
|
|
63
|
+
this.dropped += 1;
|
|
64
|
+
this.truncated.add("events");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const parsed = browserScenarioEventSchema.parse({
|
|
68
|
+
...event,
|
|
69
|
+
sequence: this.sequence,
|
|
70
|
+
step_index: this.stepIndex,
|
|
71
|
+
});
|
|
72
|
+
if (!this.budget.claimMetadata(Buffer.byteLength(JSON.stringify(parsed)))) {
|
|
73
|
+
this.dropped += 1;
|
|
74
|
+
this.truncated.add("events");
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.items.push(parsed);
|
|
78
|
+
}
|
|
79
|
+
admit(section, value, maximum) {
|
|
80
|
+
if (this.admitted[section].has(value))
|
|
81
|
+
return true;
|
|
82
|
+
if (this.rejected[section].has(value))
|
|
83
|
+
return false;
|
|
84
|
+
if (this.counts[section] >= maximum) {
|
|
85
|
+
this.rejected[section].add(value);
|
|
86
|
+
this.sequence += 1;
|
|
87
|
+
this.dropped += 1;
|
|
88
|
+
this.truncated.add("events");
|
|
89
|
+
this.truncated.add(section);
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
this.admitted[section].add(value);
|
|
93
|
+
this.counts[section] += 1;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
observePage(page) {
|
|
97
|
+
if (this.enabled.has("console"))
|
|
98
|
+
page.on("console", (message) => {
|
|
99
|
+
if (this.pageInScope(page))
|
|
100
|
+
this.console(message);
|
|
101
|
+
});
|
|
102
|
+
if (this.enabled.has("page-errors"))
|
|
103
|
+
page.on("pageerror", (error) => {
|
|
104
|
+
if (this.pageInScope(page))
|
|
105
|
+
this.push({
|
|
106
|
+
kind: "page-error",
|
|
107
|
+
message: this.secrets.redact(error.message).slice(0, 65_536),
|
|
108
|
+
stack: error.stack === undefined
|
|
109
|
+
? null
|
|
110
|
+
: this.secrets.redact(error.stack).slice(0, 262_144),
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
if (this.enabled.has("network")) {
|
|
114
|
+
page.on("request", (request) => {
|
|
115
|
+
if (this.pageInScope(page))
|
|
116
|
+
this.request("request", request);
|
|
117
|
+
});
|
|
118
|
+
page.on("response", (response) => {
|
|
119
|
+
if (this.pageInScope(page))
|
|
120
|
+
this.response(response);
|
|
121
|
+
});
|
|
122
|
+
page.on("requestfailed", (request) => {
|
|
123
|
+
if (this.pageInScope(page))
|
|
124
|
+
this.request("request-failed", request);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (this.enabled.has("websockets"))
|
|
128
|
+
page.on("websocket", (socket) => {
|
|
129
|
+
if (this.pageInScope(page))
|
|
130
|
+
this.webSocket(page, socket);
|
|
131
|
+
});
|
|
132
|
+
if (this.enabled.has("frames")) {
|
|
133
|
+
page.on("frameattached", (frame) => {
|
|
134
|
+
if (this.pageInScope(page))
|
|
135
|
+
this.frame("frame-attached", frame);
|
|
136
|
+
});
|
|
137
|
+
page.on("framedetached", (frame) => {
|
|
138
|
+
if (this.pageInScope(page))
|
|
139
|
+
this.frame("frame-detached", frame);
|
|
140
|
+
});
|
|
141
|
+
page.on("framenavigated", (frame) => {
|
|
142
|
+
if (this.pageInScope(page))
|
|
143
|
+
this.frame("frame-navigated", frame);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (this.enabled.has("workers"))
|
|
147
|
+
page.on("worker", (worker) => {
|
|
148
|
+
if (this.pageInScope(page))
|
|
149
|
+
this.worker(page, worker);
|
|
150
|
+
});
|
|
151
|
+
if (this.enabled.has("popups"))
|
|
152
|
+
page.on("popup", (popup) => {
|
|
153
|
+
if (this.pageInScope(page))
|
|
154
|
+
this.popup(popup);
|
|
155
|
+
});
|
|
156
|
+
if (this.enabled.has("downloads"))
|
|
157
|
+
page.on("download", (download) => {
|
|
158
|
+
if (this.pageInScope(page))
|
|
159
|
+
this.download(download);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
pageInScope(page) {
|
|
163
|
+
try {
|
|
164
|
+
return this.allowedOrigins.has(new URL(page.url()).origin);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
safeUrl(value) {
|
|
171
|
+
return sanitizeBrowserUrl(this.secrets.redact(value));
|
|
172
|
+
}
|
|
173
|
+
console(message) {
|
|
174
|
+
const location = message.location();
|
|
175
|
+
this.push({
|
|
176
|
+
kind: "console",
|
|
177
|
+
level: this.secrets.redact(message.type()).slice(0, 64),
|
|
178
|
+
text: this.secrets.redact(message.text()).slice(0, 65_536),
|
|
179
|
+
url: location.url === "" ? null : this.safeUrl(location.url),
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
request(kind, request) {
|
|
183
|
+
this.push({
|
|
184
|
+
kind,
|
|
185
|
+
method: this.secrets.redact(request.method()).slice(0, 32),
|
|
186
|
+
url: this.safeUrl(request.url()),
|
|
187
|
+
resource_type: this.secrets.redact(request.resourceType()).slice(0, 64),
|
|
188
|
+
status: null,
|
|
189
|
+
header_names: Object.keys(request.headers())
|
|
190
|
+
.map((name) => this.secrets.redact(name).slice(0, 256))
|
|
191
|
+
.sort()
|
|
192
|
+
.slice(0, 256),
|
|
193
|
+
failure: kind === "request-failed"
|
|
194
|
+
? this.secrets
|
|
195
|
+
.redact(request.failure()?.errorText ?? "unknown")
|
|
196
|
+
.slice(0, 1_024)
|
|
197
|
+
: null,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
response(response) {
|
|
201
|
+
const request = response.request();
|
|
202
|
+
this.push({
|
|
203
|
+
kind: "response",
|
|
204
|
+
method: this.secrets.redact(request.method()).slice(0, 32),
|
|
205
|
+
url: this.safeUrl(response.url()),
|
|
206
|
+
resource_type: this.secrets.redact(request.resourceType()).slice(0, 64),
|
|
207
|
+
status: response.status(),
|
|
208
|
+
header_names: Object.keys(response.headers())
|
|
209
|
+
.map((name) => this.secrets.redact(name).slice(0, 256))
|
|
210
|
+
.sort()
|
|
211
|
+
.slice(0, 256),
|
|
212
|
+
failure: null,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
webSocket(page, socket) {
|
|
216
|
+
if (!this.admit("websockets", socket, this.limits.max_websockets))
|
|
217
|
+
return;
|
|
218
|
+
const url = this.safeUrl(socket.url());
|
|
219
|
+
this.push({ kind: "websocket-opened", url });
|
|
220
|
+
socket.on("framesent", ({ payload }) => {
|
|
221
|
+
if (this.pageInScope(page))
|
|
222
|
+
this.webSocketFrame("websocket-frame-sent", url, payload);
|
|
223
|
+
});
|
|
224
|
+
socket.on("framereceived", ({ payload }) => {
|
|
225
|
+
if (this.pageInScope(page))
|
|
226
|
+
this.webSocketFrame("websocket-frame-received", url, payload);
|
|
227
|
+
});
|
|
228
|
+
socket.on("close", () => {
|
|
229
|
+
if (this.pageInScope(page))
|
|
230
|
+
this.push({ kind: "websocket-closed", url });
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
webSocketFrame(kind, url, payload) {
|
|
234
|
+
const bytes = Buffer.byteLength(payload);
|
|
235
|
+
const isText = typeof payload === "string";
|
|
236
|
+
const text = isText ? this.secrets.redact(payload).slice(0, 65_536) : null;
|
|
237
|
+
this.push({
|
|
238
|
+
kind,
|
|
239
|
+
url,
|
|
240
|
+
payload_type: isText ? "text" : "binary",
|
|
241
|
+
payload_bytes: bytes,
|
|
242
|
+
payload_text: text,
|
|
243
|
+
truncated: isText && text !== null && text.length < payload.length,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
frame(kind, frame) {
|
|
247
|
+
if (!this.admit("frames", frame, this.limits.max_frames))
|
|
248
|
+
return;
|
|
249
|
+
this.push({
|
|
250
|
+
kind,
|
|
251
|
+
url: frame.url() === "" ? null : this.safeUrl(frame.url()),
|
|
252
|
+
name: frame.name() === ""
|
|
253
|
+
? null
|
|
254
|
+
: this.secrets.redact(frame.name()).slice(0, 1_024),
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
worker(page, worker) {
|
|
258
|
+
if (!this.admit("workers", worker, this.limits.max_workers))
|
|
259
|
+
return;
|
|
260
|
+
const details = {
|
|
261
|
+
url: this.safeUrl(worker.url()),
|
|
262
|
+
name: null,
|
|
263
|
+
};
|
|
264
|
+
this.push({ kind: "worker-created", ...details });
|
|
265
|
+
worker.on("close", () => {
|
|
266
|
+
if (this.pageInScope(page))
|
|
267
|
+
this.push({ kind: "worker-closed", ...details });
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
popup(page) {
|
|
271
|
+
if (!this.pageInScope(page)) {
|
|
272
|
+
void page.close().catch(() => undefined);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (!this.admit("popups", page, this.limits.max_popups))
|
|
276
|
+
return;
|
|
277
|
+
const opened = {
|
|
278
|
+
url: page.url() === "" ? null : this.safeUrl(page.url()),
|
|
279
|
+
name: null,
|
|
280
|
+
};
|
|
281
|
+
this.push({ kind: "popup-opened", ...opened });
|
|
282
|
+
page.on("close", () => this.pageInScope(page)
|
|
283
|
+
? this.push({
|
|
284
|
+
kind: "popup-closed",
|
|
285
|
+
url: page.url() === "" ? null : this.safeUrl(page.url()),
|
|
286
|
+
name: null,
|
|
287
|
+
})
|
|
288
|
+
: undefined);
|
|
289
|
+
this.observePage(page);
|
|
290
|
+
}
|
|
291
|
+
download(download) {
|
|
292
|
+
this.push({
|
|
293
|
+
kind: "download-cancelled",
|
|
294
|
+
suggested_filename: this.secrets
|
|
295
|
+
.redact(download.suggestedFilename())
|
|
296
|
+
.slice(0, 1_024),
|
|
297
|
+
url: this.safeUrl(download.url()),
|
|
298
|
+
});
|
|
299
|
+
void download.cancel().catch(() => undefined);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import {} from "playwright-core";
|
|
2
|
+
import { BrowserObservationError } from "../domain/errors.js";
|
|
3
|
+
import { BrowserScenarioSecrets } from "./BrowserScenarioSecrets.js";
|
|
4
|
+
import { closePlaywrightScenarioBrowser, openPlaywrightScenarioBrowser, } from "./PlaywrightScenarioBrowser.js";
|
|
5
|
+
import { performPlaywrightScenarioAction } from "./PlaywrightScenarioActions.js";
|
|
6
|
+
import { BrowserScenarioCaptureBudget, capturePlaywrightStepArtifacts, } from "./PlaywrightScenarioArtifacts.js";
|
|
7
|
+
import { PlaywrightScenarioEvents } from "./PlaywrightScenarioEvents.js";
|
|
8
|
+
import { withPlaywrightExecutionBoundary } from "./PlaywrightExecutionBoundary.js";
|
|
9
|
+
const OPERATION = "capture_browser_scenario";
|
|
10
|
+
const originAllowed = (value, allowedOrigins) => {
|
|
11
|
+
try {
|
|
12
|
+
return allowedOrigins.has(new URL(value).origin);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const storageSeeds = (blocks, secrets) => {
|
|
19
|
+
const seeds = {};
|
|
20
|
+
for (const { origin, entries } of blocks)
|
|
21
|
+
(seeds[origin] ??= []).push(...entries.map(({ name, value }) => [name, secrets.value(value)]));
|
|
22
|
+
return seeds;
|
|
23
|
+
};
|
|
24
|
+
const installStorageSeeds = async (context, page, scenario, secrets) => {
|
|
25
|
+
await context.addCookies(scenario.storage.cookies.map((cookie) => ({
|
|
26
|
+
name: cookie.name,
|
|
27
|
+
value: secrets.value(cookie.value),
|
|
28
|
+
url: secrets.url(cookie.destination),
|
|
29
|
+
httpOnly: cookie.http_only,
|
|
30
|
+
secure: cookie.secure,
|
|
31
|
+
sameSite: cookie.same_site,
|
|
32
|
+
})));
|
|
33
|
+
const storage = {
|
|
34
|
+
local: storageSeeds(scenario.storage.local_storage, secrets),
|
|
35
|
+
session: storageSeeds(scenario.storage.session_storage, secrets),
|
|
36
|
+
};
|
|
37
|
+
const payload = JSON.stringify(storage).replaceAll("<", "\\u003c");
|
|
38
|
+
await page.addInitScript(`(() => {
|
|
39
|
+
const seeds = ${payload};
|
|
40
|
+
const local = seeds.local[window.location.origin] ?? [];
|
|
41
|
+
const session = seeds.session[window.location.origin] ?? [];
|
|
42
|
+
for (const [name, value] of local) window.localStorage.setItem(name, value);
|
|
43
|
+
for (const [name, value] of session)
|
|
44
|
+
window.sessionStorage.setItem(name, value);
|
|
45
|
+
})()`);
|
|
46
|
+
};
|
|
47
|
+
const installHttpPolicy = async (input) => {
|
|
48
|
+
const { context, scenario, secrets, ownedPages, claimOwnedPage } = input;
|
|
49
|
+
const routes = scenario.request_replay.mode === "exact"
|
|
50
|
+
? new Map(scenario.request_replay.routes.map((route) => [
|
|
51
|
+
`${route.method} ${secrets.url(route.request)}`,
|
|
52
|
+
route,
|
|
53
|
+
]))
|
|
54
|
+
: new Map();
|
|
55
|
+
await context.route("**/*", async (route, request) => {
|
|
56
|
+
let requestPage;
|
|
57
|
+
try {
|
|
58
|
+
requestPage = request.frame().page();
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
requestPage = undefined;
|
|
62
|
+
}
|
|
63
|
+
if (scenario.browser.mode === "connect" &&
|
|
64
|
+
requestPage !== undefined &&
|
|
65
|
+
!ownedPages.has(requestPage))
|
|
66
|
+
await claimOwnedPage(requestPage);
|
|
67
|
+
if (scenario.browser.mode === "connect" &&
|
|
68
|
+
(requestPage === undefined || !ownedPages.has(requestPage))) {
|
|
69
|
+
await route.continue();
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (!originAllowed(request.url(), new Set(scenario.allowed_origins))) {
|
|
73
|
+
await route.abort("blockedbyclient");
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const replay = routes.get(`${request.method()} ${request.url()}`);
|
|
77
|
+
if (replay !== undefined) {
|
|
78
|
+
await fulfillReplayRoute(route, replay.response, secrets);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (scenario.request_replay.mode === "exact" &&
|
|
82
|
+
scenario.request_replay.unmatched === "abort") {
|
|
83
|
+
await route.abort("blockedbyclient");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
await route.continue();
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
const fulfillReplayRoute = async (route, response, secrets) => {
|
|
90
|
+
if (response.kind === "redirect") {
|
|
91
|
+
await route.fulfill({
|
|
92
|
+
status: response.status,
|
|
93
|
+
headers: { location: secrets.url(response.destination) },
|
|
94
|
+
});
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
await route.fulfill({
|
|
98
|
+
status: response.status,
|
|
99
|
+
headers: Object.fromEntries(response.headers.map(({ name, value }) => [name, secrets.value(value)])),
|
|
100
|
+
...(response.body === undefined
|
|
101
|
+
? {}
|
|
102
|
+
: { body: secrets.value(response.body) }),
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
const installWebSocketPolicy = async (owner, scenario) => {
|
|
106
|
+
const allowed = new Set(scenario.allowed_origins);
|
|
107
|
+
await owner.routeWebSocket("**/*", async (route) => {
|
|
108
|
+
const url = new URL(route.url());
|
|
109
|
+
const httpOrigin = `${url.protocol === "wss:" ? "https:" : "http:"}//${url.host}`;
|
|
110
|
+
if (!allowed.has(httpOrigin) ||
|
|
111
|
+
(scenario.request_replay.mode === "exact" &&
|
|
112
|
+
scenario.request_replay.unmatched === "abort")) {
|
|
113
|
+
await route.close({ code: 1008, reason: "outside scenario policy" });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
route.connectToServer();
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
const blockAttachedServiceWorkers = async (page) => {
|
|
120
|
+
const controller = await page.evaluate("Boolean(navigator.serviceWorker?.controller)");
|
|
121
|
+
if (controller)
|
|
122
|
+
throw new BrowserObservationError(OPERATION, "target_not_allowed");
|
|
123
|
+
const blockRegistration = `(() => {
|
|
124
|
+
if (!("serviceWorker" in navigator)) return;
|
|
125
|
+
void navigator.serviceWorker.getRegistrations()
|
|
126
|
+
.then((registrations) => Promise.all(registrations.map((item) => item.unregister())));
|
|
127
|
+
Object.defineProperty(ServiceWorkerContainer.prototype, "register", {
|
|
128
|
+
configurable: false,
|
|
129
|
+
value: () => Promise.reject(new Error("service workers are blocked by scenario policy"))
|
|
130
|
+
});
|
|
131
|
+
})()`;
|
|
132
|
+
await page.addInitScript(blockRegistration);
|
|
133
|
+
await page.evaluate(blockRegistration);
|
|
134
|
+
};
|
|
135
|
+
const initializePage = async (context, page, scenario, secrets) => {
|
|
136
|
+
context.setDefaultTimeout(scenario.limits.action_timeout_ms);
|
|
137
|
+
context.setDefaultNavigationTimeout(scenario.limits.navigation_timeout_ms);
|
|
138
|
+
const ownedPages = new Set([page]);
|
|
139
|
+
if (scenario.browser.mode === "connect")
|
|
140
|
+
await blockAttachedServiceWorkers(page);
|
|
141
|
+
await installWebSocketPolicy(scenario.browser.mode === "launch" ? context : page, scenario);
|
|
142
|
+
const claimOwnedPage = async (candidate) => {
|
|
143
|
+
if (ownedPages.has(candidate))
|
|
144
|
+
return true;
|
|
145
|
+
const opener = await candidate.opener();
|
|
146
|
+
if (opener === null || !ownedPages.has(opener))
|
|
147
|
+
return false;
|
|
148
|
+
await installWebSocketPolicy(candidate, scenario);
|
|
149
|
+
ownedPages.add(candidate);
|
|
150
|
+
return true;
|
|
151
|
+
};
|
|
152
|
+
await installHttpPolicy({
|
|
153
|
+
context,
|
|
154
|
+
scenario,
|
|
155
|
+
secrets,
|
|
156
|
+
ownedPages,
|
|
157
|
+
claimOwnedPage,
|
|
158
|
+
});
|
|
159
|
+
page.on("popup", (popup) => {
|
|
160
|
+
if (scenario.browser.mode === "connect")
|
|
161
|
+
void claimOwnedPage(popup).catch(async () => {
|
|
162
|
+
await popup.close().catch(() => undefined);
|
|
163
|
+
});
|
|
164
|
+
else
|
|
165
|
+
ownedPages.add(popup);
|
|
166
|
+
});
|
|
167
|
+
await installStorageSeeds(context, page, scenario, secrets);
|
|
168
|
+
return ownedPages;
|
|
169
|
+
};
|
|
170
|
+
export class PlaywrightScenarioSession {
|
|
171
|
+
opened;
|
|
172
|
+
scenario;
|
|
173
|
+
secrets;
|
|
174
|
+
eventCapture;
|
|
175
|
+
mode;
|
|
176
|
+
processOwnership;
|
|
177
|
+
product = "Chromium";
|
|
178
|
+
version;
|
|
179
|
+
initialUrl;
|
|
180
|
+
closed = false;
|
|
181
|
+
constructor(opened, scenario, secrets, eventCapture) {
|
|
182
|
+
this.opened = opened;
|
|
183
|
+
this.scenario = scenario;
|
|
184
|
+
this.secrets = secrets;
|
|
185
|
+
this.eventCapture = eventCapture;
|
|
186
|
+
this.mode = scenario.browser.mode;
|
|
187
|
+
this.processOwnership =
|
|
188
|
+
scenario.browser.mode === "launch" ? "provider-owned" : "external";
|
|
189
|
+
this.version = opened.browser.version();
|
|
190
|
+
this.initialUrl = opened.page.url();
|
|
191
|
+
}
|
|
192
|
+
static async open(scenario, environment, options) {
|
|
193
|
+
const remaining = () => options.deadlineAt - Date.now();
|
|
194
|
+
if (options.signal?.aborted === true)
|
|
195
|
+
throw new BrowserObservationError(OPERATION, "cancelled");
|
|
196
|
+
const secrets = BrowserScenarioSecrets.resolve(scenario, environment);
|
|
197
|
+
if (secrets === undefined)
|
|
198
|
+
throw new BrowserObservationError(OPERATION, "secret_unavailable");
|
|
199
|
+
const opening = openPlaywrightScenarioBrowser(scenario, environment, remaining());
|
|
200
|
+
let opened;
|
|
201
|
+
try {
|
|
202
|
+
opened = await withPlaywrightExecutionBoundary(() => opening, remaining(), options.signal);
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
void opening
|
|
206
|
+
.then((lateOpened) => closePlaywrightScenarioBrowser(lateOpened))
|
|
207
|
+
.catch(() => undefined);
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
await withPlaywrightExecutionBoundary(() => initializePage(opened.context, opened.page, scenario, secrets), remaining(), options.signal);
|
|
212
|
+
const events = new PlaywrightScenarioEvents({
|
|
213
|
+
page: opened.page,
|
|
214
|
+
enabled: new Set(scenario.capture.events),
|
|
215
|
+
limits: scenario.limits,
|
|
216
|
+
secrets,
|
|
217
|
+
budget: options.budget,
|
|
218
|
+
allowedOrigins: scenario.allowed_origins,
|
|
219
|
+
});
|
|
220
|
+
const session = new PlaywrightScenarioSession(opened, scenario, secrets, events);
|
|
221
|
+
await withPlaywrightExecutionBoundary(() => opened.page.goto(secrets.url(scenario.start_url), {
|
|
222
|
+
waitUntil: "load",
|
|
223
|
+
timeout: Math.min(scenario.limits.navigation_timeout_ms, remaining()),
|
|
224
|
+
}), remaining(), options.signal);
|
|
225
|
+
return session;
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
await closePlaywrightScenarioBrowser(opened);
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
currentUrl() {
|
|
233
|
+
return this.opened.page.url();
|
|
234
|
+
}
|
|
235
|
+
setStep(index) {
|
|
236
|
+
this.eventCapture.setStep(index);
|
|
237
|
+
}
|
|
238
|
+
nextEventSequence() {
|
|
239
|
+
return this.eventCapture.nextSequence();
|
|
240
|
+
}
|
|
241
|
+
lastEventSequence() {
|
|
242
|
+
return this.eventCapture.lastSequence();
|
|
243
|
+
}
|
|
244
|
+
events() {
|
|
245
|
+
return this.eventCapture.result();
|
|
246
|
+
}
|
|
247
|
+
eventTruncationSections() {
|
|
248
|
+
return this.eventCapture.truncationSections();
|
|
249
|
+
}
|
|
250
|
+
async perform(action, maximumTimeoutMs, signal) {
|
|
251
|
+
await withPlaywrightExecutionBoundary(() => performPlaywrightScenarioAction({
|
|
252
|
+
page: this.opened.page,
|
|
253
|
+
action,
|
|
254
|
+
secrets: this.secrets,
|
|
255
|
+
defaultTimeoutMs: this.scenario.limits.action_timeout_ms,
|
|
256
|
+
maximumTimeoutMs,
|
|
257
|
+
}), maximumTimeoutMs, signal);
|
|
258
|
+
}
|
|
259
|
+
async capture(requested, budget, maximumTimeoutMs, signal) {
|
|
260
|
+
return withPlaywrightExecutionBoundary(() => capturePlaywrightStepArtifacts({
|
|
261
|
+
context: this.opened.context,
|
|
262
|
+
page: this.opened.page,
|
|
263
|
+
scenario: this.scenario,
|
|
264
|
+
secrets: this.secrets,
|
|
265
|
+
requested,
|
|
266
|
+
budget,
|
|
267
|
+
}), maximumTimeoutMs, signal);
|
|
268
|
+
}
|
|
269
|
+
async close() {
|
|
270
|
+
if (this.closed)
|
|
271
|
+
return this.mode === "launch"
|
|
272
|
+
? "terminated-owned-process"
|
|
273
|
+
: "disconnected-external";
|
|
274
|
+
this.closed = true;
|
|
275
|
+
await closePlaywrightScenarioBrowser(this.opened);
|
|
276
|
+
return this.mode === "launch"
|
|
277
|
+
? "terminated-owned-process"
|
|
278
|
+
: "disconnected-external";
|
|
279
|
+
}
|
|
280
|
+
redactError(error) {
|
|
281
|
+
return this.secrets
|
|
282
|
+
.redact(error instanceof Error ? error.message : "browser action failed")
|
|
283
|
+
.slice(0, 4_096);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/** Production Playwright/CDP session factory. */
|
|
287
|
+
export class PlaywrightScenarioSessionFactory {
|
|
288
|
+
environment;
|
|
289
|
+
constructor(environment = process.env) {
|
|
290
|
+
this.environment = environment;
|
|
291
|
+
}
|
|
292
|
+
open(scenario, options = {}) {
|
|
293
|
+
return PlaywrightScenarioSession.open(scenario, this.environment, {
|
|
294
|
+
...(options.signal === undefined ? {} : { signal: options.signal }),
|
|
295
|
+
budget: options.budget ??
|
|
296
|
+
new BrowserScenarioCaptureBudget(scenario.limits.max_screenshots, scenario.limits.max_total_metadata_bytes),
|
|
297
|
+
deadlineAt: options.deadlineAt ?? Date.now() + scenario.limits.max_duration_ms,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|