@mercuryo-ai/agentbrowse 0.2.50
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 +15 -0
- package/README.md +335 -0
- package/dist/assistive-runtime.d.ts +110 -0
- package/dist/assistive-runtime.d.ts.map +1 -0
- package/dist/assistive-runtime.js +79 -0
- package/dist/assistive-runtime.test-support.d.ts +7 -0
- package/dist/assistive-runtime.test-support.d.ts.map +1 -0
- package/dist/assistive-runtime.test-support.js +106 -0
- package/dist/assistive-stagehand.d.ts +12 -0
- package/dist/assistive-stagehand.d.ts.map +1 -0
- package/dist/assistive-stagehand.js +10 -0
- package/dist/browser-session-state.d.ts +95 -0
- package/dist/browser-session-state.d.ts.map +1 -0
- package/dist/browser-session-state.js +279 -0
- package/dist/client-bindings.d.ts +10 -0
- package/dist/client-bindings.d.ts.map +1 -0
- package/dist/client-bindings.js +18 -0
- package/dist/client.d.ts +49 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +63 -0
- package/dist/command-api-tracing.d.ts +20 -0
- package/dist/command-api-tracing.d.ts.map +1 -0
- package/dist/command-api-tracing.js +149 -0
- package/dist/command-name.d.ts +3 -0
- package/dist/command-name.d.ts.map +1 -0
- package/dist/command-name.js +11 -0
- package/dist/commands/act.d.ts +43 -0
- package/dist/commands/act.d.ts.map +1 -0
- package/dist/commands/act.js +1107 -0
- package/dist/commands/action-acceptance.d.ts +93 -0
- package/dist/commands/action-acceptance.d.ts.map +1 -0
- package/dist/commands/action-acceptance.js +1938 -0
- package/dist/commands/action-artifacts.d.ts +33 -0
- package/dist/commands/action-artifacts.d.ts.map +1 -0
- package/dist/commands/action-artifacts.js +104 -0
- package/dist/commands/action-execution-guards.d.ts +5 -0
- package/dist/commands/action-execution-guards.d.ts.map +1 -0
- package/dist/commands/action-execution-guards.js +3 -0
- package/dist/commands/action-executor-helpers.d.ts +21 -0
- package/dist/commands/action-executor-helpers.d.ts.map +1 -0
- package/dist/commands/action-executor-helpers.js +265 -0
- package/dist/commands/action-executor.d.ts +14 -0
- package/dist/commands/action-executor.d.ts.map +1 -0
- package/dist/commands/action-executor.js +46 -0
- package/dist/commands/action-fallbacks.d.ts +6 -0
- package/dist/commands/action-fallbacks.d.ts.map +1 -0
- package/dist/commands/action-fallbacks.js +43 -0
- package/dist/commands/action-result-resolution.d.ts +17 -0
- package/dist/commands/action-result-resolution.d.ts.map +1 -0
- package/dist/commands/action-result-resolution.js +132 -0
- package/dist/commands/action-value-projection.d.ts +32 -0
- package/dist/commands/action-value-projection.d.ts.map +1 -0
- package/dist/commands/action-value-projection.js +151 -0
- package/dist/commands/attach.d.ts +41 -0
- package/dist/commands/attach.d.ts.map +1 -0
- package/dist/commands/attach.js +103 -0
- package/dist/commands/browse-actions.d.ts +4 -0
- package/dist/commands/browse-actions.d.ts.map +1 -0
- package/dist/commands/browse-actions.js +4 -0
- package/dist/commands/browser-status.d.ts +57 -0
- package/dist/commands/browser-status.d.ts.map +1 -0
- package/dist/commands/browser-status.js +243 -0
- package/dist/commands/click-action-executor.d.ts +12 -0
- package/dist/commands/click-action-executor.d.ts.map +1 -0
- package/dist/commands/click-action-executor.js +111 -0
- package/dist/commands/click-activation-policy.d.ts +5 -0
- package/dist/commands/click-activation-policy.d.ts.map +1 -0
- package/dist/commands/click-activation-policy.js +13 -0
- package/dist/commands/close.d.ts +26 -0
- package/dist/commands/close.d.ts.map +1 -0
- package/dist/commands/close.js +124 -0
- package/dist/commands/datepicker-action-executor.d.ts +12 -0
- package/dist/commands/datepicker-action-executor.d.ts.map +1 -0
- package/dist/commands/datepicker-action-executor.js +218 -0
- package/dist/commands/descriptor-validation.d.ts +27 -0
- package/dist/commands/descriptor-validation.d.ts.map +1 -0
- package/dist/commands/descriptor-validation.js +192 -0
- package/dist/commands/extract-scope-resolution.d.ts +20 -0
- package/dist/commands/extract-scope-resolution.d.ts.map +1 -0
- package/dist/commands/extract-scope-resolution.js +109 -0
- package/dist/commands/extract-scoped-dialog-text.d.ts +3 -0
- package/dist/commands/extract-scoped-dialog-text.d.ts.map +1 -0
- package/dist/commands/extract-scoped-dialog-text.js +210 -0
- package/dist/commands/extract-snapshot-sanitizer.d.ts +5 -0
- package/dist/commands/extract-snapshot-sanitizer.d.ts.map +1 -0
- package/dist/commands/extract-snapshot-sanitizer.js +98 -0
- package/dist/commands/extract-stagehand-executor.d.ts +17 -0
- package/dist/commands/extract-stagehand-executor.d.ts.map +1 -0
- package/dist/commands/extract-stagehand-executor.js +112 -0
- package/dist/commands/extract.d.ts +57 -0
- package/dist/commands/extract.d.ts.map +1 -0
- package/dist/commands/extract.js +668 -0
- package/dist/commands/interaction-kernel.d.ts +46 -0
- package/dist/commands/interaction-kernel.d.ts.map +1 -0
- package/dist/commands/interaction-kernel.js +215 -0
- package/dist/commands/launch.d.ts +41 -0
- package/dist/commands/launch.d.ts.map +1 -0
- package/dist/commands/launch.js +182 -0
- package/dist/commands/navigate.d.ts +31 -0
- package/dist/commands/navigate.d.ts.map +1 -0
- package/dist/commands/navigate.js +202 -0
- package/dist/commands/observe-accessibility.d.ts +22 -0
- package/dist/commands/observe-accessibility.d.ts.map +1 -0
- package/dist/commands/observe-accessibility.js +566 -0
- package/dist/commands/observe-display-label.d.ts +4 -0
- package/dist/commands/observe-display-label.d.ts.map +1 -0
- package/dist/commands/observe-display-label.js +26 -0
- package/dist/commands/observe-dom-label-contract.d.ts +2 -0
- package/dist/commands/observe-dom-label-contract.d.ts.map +1 -0
- package/dist/commands/observe-dom-label-contract.js +564 -0
- package/dist/commands/observe-fallback-semantics.d.ts +6 -0
- package/dist/commands/observe-fallback-semantics.d.ts.map +1 -0
- package/dist/commands/observe-fallback-semantics.js +86 -0
- package/dist/commands/observe-inventory.d.ts +149 -0
- package/dist/commands/observe-inventory.d.ts.map +1 -0
- package/dist/commands/observe-inventory.js +3545 -0
- package/dist/commands/observe-label-policy.d.ts +8 -0
- package/dist/commands/observe-label-policy.d.ts.map +1 -0
- package/dist/commands/observe-label-policy.js +21 -0
- package/dist/commands/observe-page-state.d.ts +11 -0
- package/dist/commands/observe-page-state.d.ts.map +1 -0
- package/dist/commands/observe-page-state.js +89 -0
- package/dist/commands/observe-persistence.d.ts +15 -0
- package/dist/commands/observe-persistence.d.ts.map +1 -0
- package/dist/commands/observe-persistence.js +238 -0
- package/dist/commands/observe-projection.d.ts +119 -0
- package/dist/commands/observe-projection.d.ts.map +1 -0
- package/dist/commands/observe-projection.js +726 -0
- package/dist/commands/observe-protected.d.ts +6 -0
- package/dist/commands/observe-protected.d.ts.map +1 -0
- package/dist/commands/observe-protected.js +31 -0
- package/dist/commands/observe-semantics.d.ts +10 -0
- package/dist/commands/observe-semantics.d.ts.map +1 -0
- package/dist/commands/observe-semantics.js +535 -0
- package/dist/commands/observe-signals.d.ts +48 -0
- package/dist/commands/observe-signals.d.ts.map +1 -0
- package/dist/commands/observe-signals.js +461 -0
- package/dist/commands/observe-stagehand.d.ts +49 -0
- package/dist/commands/observe-stagehand.d.ts.map +1 -0
- package/dist/commands/observe-stagehand.js +94 -0
- package/dist/commands/observe-surfaces.d.ts +11 -0
- package/dist/commands/observe-surfaces.d.ts.map +1 -0
- package/dist/commands/observe-surfaces.js +290 -0
- package/dist/commands/observe.d.ts +113 -0
- package/dist/commands/observe.d.ts.map +1 -0
- package/dist/commands/observe.js +556 -0
- package/dist/commands/screenshot.d.ts +37 -0
- package/dist/commands/screenshot.d.ts.map +1 -0
- package/dist/commands/screenshot.js +269 -0
- package/dist/commands/select-action-executor.d.ts +10 -0
- package/dist/commands/select-action-executor.d.ts.map +1 -0
- package/dist/commands/select-action-executor.js +156 -0
- package/dist/commands/semantic-observe-lexical.d.ts +31 -0
- package/dist/commands/semantic-observe-lexical.d.ts.map +1 -0
- package/dist/commands/semantic-observe-lexical.js +186 -0
- package/dist/commands/semantic-observe.d.ts +37 -0
- package/dist/commands/semantic-observe.d.ts.map +1 -0
- package/dist/commands/semantic-observe.js +1339 -0
- package/dist/commands/structured-grid-action-executor.d.ts +3 -0
- package/dist/commands/structured-grid-action-executor.d.ts.map +1 -0
- package/dist/commands/structured-grid-action-executor.js +4 -0
- package/dist/commands/target-resolution.d.ts +4 -0
- package/dist/commands/target-resolution.d.ts.map +1 -0
- package/dist/commands/target-resolution.js +33 -0
- package/dist/commands/text-input-action-executor.d.ts +5 -0
- package/dist/commands/text-input-action-executor.d.ts.map +1 -0
- package/dist/commands/text-input-action-executor.js +116 -0
- package/dist/commands/user-actionable.d.ts +4 -0
- package/dist/commands/user-actionable.d.ts.map +1 -0
- package/dist/commands/user-actionable.js +216 -0
- package/dist/control-semantics.d.ts +30 -0
- package/dist/control-semantics.d.ts.map +1 -0
- package/dist/control-semantics.js +419 -0
- package/dist/diagnostics.d.ts +132 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/diagnostics.js +120 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +350 -0
- package/dist/library.d.ts +17 -0
- package/dist/library.d.ts.map +1 -0
- package/dist/library.js +14 -0
- package/dist/output.d.ts +32 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +33 -0
- package/dist/owned-browser.d.ts +12 -0
- package/dist/owned-browser.d.ts.map +1 -0
- package/dist/owned-browser.js +69 -0
- package/dist/owned-process.d.ts +19 -0
- package/dist/owned-process.d.ts.map +1 -0
- package/dist/owned-process.js +145 -0
- package/dist/playwright-runtime.d.ts +43 -0
- package/dist/playwright-runtime.d.ts.map +1 -0
- package/dist/playwright-runtime.js +339 -0
- package/dist/protected-fill-browser.d.ts +22 -0
- package/dist/protected-fill-browser.d.ts.map +1 -0
- package/dist/protected-fill-browser.js +52 -0
- package/dist/protected-fill.d.ts +82 -0
- package/dist/protected-fill.d.ts.map +1 -0
- package/dist/protected-fill.js +20 -0
- package/dist/runtime-metrics.d.ts +27 -0
- package/dist/runtime-metrics.d.ts.map +1 -0
- package/dist/runtime-metrics.js +66 -0
- package/dist/runtime-page-state.d.ts +11 -0
- package/dist/runtime-page-state.d.ts.map +1 -0
- package/dist/runtime-page-state.js +62 -0
- package/dist/runtime-protected-state.d.ts +14 -0
- package/dist/runtime-protected-state.d.ts.map +1 -0
- package/dist/runtime-protected-state.js +148 -0
- package/dist/runtime-resolution.d.ts +9 -0
- package/dist/runtime-resolution.d.ts.map +1 -0
- package/dist/runtime-resolution.js +19 -0
- package/dist/runtime-state.d.ts +251 -0
- package/dist/runtime-state.d.ts.map +1 -0
- package/dist/runtime-state.js +599 -0
- package/dist/secrets/catalog-applicability.d.ts +5 -0
- package/dist/secrets/catalog-applicability.d.ts.map +1 -0
- package/dist/secrets/catalog-applicability.js +59 -0
- package/dist/secrets/field-policy.d.ts +3 -0
- package/dist/secrets/field-policy.d.ts.map +1 -0
- package/dist/secrets/field-policy.js +3 -0
- package/dist/secrets/fill-ordering.d.ts +10 -0
- package/dist/secrets/fill-ordering.d.ts.map +1 -0
- package/dist/secrets/fill-ordering.js +41 -0
- package/dist/secrets/form-matcher.d.ts +60 -0
- package/dist/secrets/form-matcher.d.ts.map +1 -0
- package/dist/secrets/form-matcher.js +948 -0
- package/dist/secrets/protected-artifact-guard.d.ts +39 -0
- package/dist/secrets/protected-artifact-guard.d.ts.map +1 -0
- package/dist/secrets/protected-artifact-guard.js +44 -0
- package/dist/secrets/protected-bindings.d.ts +14 -0
- package/dist/secrets/protected-bindings.d.ts.map +1 -0
- package/dist/secrets/protected-bindings.js +29 -0
- package/dist/secrets/protected-exact-value-redaction.d.ts +14 -0
- package/dist/secrets/protected-exact-value-redaction.d.ts.map +1 -0
- package/dist/secrets/protected-exact-value-redaction.js +360 -0
- package/dist/secrets/protected-field-semantics.d.ts +9 -0
- package/dist/secrets/protected-field-semantics.d.ts.map +1 -0
- package/dist/secrets/protected-field-semantics.js +154 -0
- package/dist/secrets/protected-field-values.d.ts +15 -0
- package/dist/secrets/protected-field-values.d.ts.map +1 -0
- package/dist/secrets/protected-field-values.js +131 -0
- package/dist/secrets/protected-fill.d.ts +47 -0
- package/dist/secrets/protected-fill.d.ts.map +1 -0
- package/dist/secrets/protected-fill.js +446 -0
- package/dist/secrets/protected-value-adapters.d.ts +4 -0
- package/dist/secrets/protected-value-adapters.d.ts.map +1 -0
- package/dist/secrets/protected-value-adapters.js +118 -0
- package/dist/secrets/types.d.ts +70 -0
- package/dist/secrets/types.d.ts.map +1 -0
- package/dist/secrets/types.js +30 -0
- package/dist/session.d.ts +19 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +120 -0
- package/dist/solver/browser-launcher.d.ts +14 -0
- package/dist/solver/browser-launcher.d.ts.map +1 -0
- package/dist/solver/browser-launcher.js +799 -0
- package/dist/solver/config.d.ts +18 -0
- package/dist/solver/config.d.ts.map +1 -0
- package/dist/solver/config.js +67 -0
- package/dist/solver/fingerprint.d.ts +9 -0
- package/dist/solver/fingerprint.d.ts.map +1 -0
- package/dist/solver/fingerprint.js +96 -0
- package/dist/solver/profile-manager.d.ts +8 -0
- package/dist/solver/profile-manager.d.ts.map +1 -0
- package/dist/solver/profile-manager.js +74 -0
- package/dist/solver/turnstile-challenge.d.ts +3 -0
- package/dist/solver/turnstile-challenge.d.ts.map +1 -0
- package/dist/solver/turnstile-challenge.js +173 -0
- package/dist/solver/types.d.ts +67 -0
- package/dist/solver/types.d.ts.map +1 -0
- package/dist/solver/types.js +1 -0
- package/dist/stagehand-runtime.d.ts +4 -0
- package/dist/stagehand-runtime.d.ts.map +1 -0
- package/dist/stagehand-runtime.js +10 -0
- package/dist/stagehand.d.ts +15 -0
- package/dist/stagehand.d.ts.map +1 -0
- package/dist/stagehand.js +19 -0
- package/dist/testing.d.ts +5 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +4 -0
- package/dist/update-check.d.ts +14 -0
- package/dist/update-check.d.ts.map +1 -0
- package/dist/update-check.js +182 -0
- package/dist/workflow-session-state.d.ts +30 -0
- package/dist/workflow-session-state.d.ts.map +1 -0
- package/dist/workflow-session-state.js +74 -0
- package/docs/README.md +25 -0
- package/docs/api-reference.md +242 -0
- package/docs/assistive-runtime.md +148 -0
- package/docs/configuration.md +287 -0
- package/docs/getting-started.md +237 -0
- package/docs/integration-checklist.md +36 -0
- package/docs/protected-fill.md +112 -0
- package/docs/testing.md +50 -0
- package/docs/troubleshooting.md +71 -0
- package/examples/README.md +18 -0
- package/examples/attach.ts +27 -0
- package/examples/basic.ts +36 -0
- package/examples/extract.ts +50 -0
- package/package.json +83 -0
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* browse observe ["<instruction>"] — Discover available actions on the page.
|
|
3
|
+
*/
|
|
4
|
+
import { canUseAgentbrowseAssistiveLlmClient } from "../assistive-runtime.js";
|
|
5
|
+
import { saveSession } from "../session.js";
|
|
6
|
+
import { ensureRuntimeState, replaceTargetsForPage } from "../runtime-state.js";
|
|
7
|
+
import { incrementMetric } from "../runtime-metrics.js";
|
|
8
|
+
import { bumpPageScopeEpoch, setCurrentPage } from "../runtime-page-state.js";
|
|
9
|
+
import { getProtectedExposure } from "../runtime-protected-state.js";
|
|
10
|
+
import { connectPlaywright, disconnectPlaywright, resolveCurrentPageContext, syncSessionPage, } from "../playwright-runtime.js";
|
|
11
|
+
import { tracedStepOperation, withApiTraceContext, } from "../command-api-tracing.js";
|
|
12
|
+
import { captureDiagnosticSnapshotBestEffort, finishDiagnosticStepBestEffort, recordCommandLifecycleEventBestEffort, startDiagnosticStep, } from "../diagnostics.js";
|
|
13
|
+
import { outputContractFailure, outputJSON, } from "../output.js";
|
|
14
|
+
import { domRuntimeResolution, stagehandRuntimeResolution, } from "../runtime-resolution.js";
|
|
15
|
+
import { withStagehand } from "../stagehand-runtime.js";
|
|
16
|
+
import { buildProtectedObserveBlockedResult } from "../secrets/protected-artifact-guard.js";
|
|
17
|
+
import { scrubProtectedExactValues } from "../secrets/protected-exact-value-redaction.js";
|
|
18
|
+
import { normalizePageSignature } from "./descriptor-validation.js";
|
|
19
|
+
import { collectDomTargets, __testDomTargetCollection as inventoryDomTargetCollection, __testStagehandDescriptor as inventoryStagehandDescriptor, } from "./observe-inventory.js";
|
|
20
|
+
import { enrichDomTargetsWithAccessibility } from "./observe-accessibility.js";
|
|
21
|
+
import { collectPageSignals } from "./observe-signals.js";
|
|
22
|
+
import { attachObservedTargetOwners, linkObservedSurfaceGraph, reconcileObservedTargetsForPage, persistObservedSurfacesForPage, toDomDescriptor, } from "./observe-persistence.js";
|
|
23
|
+
import { clearProtectedFillableFormsForPage, markProtectedFillableFormsUnknownForPage, persistProtectedFillableFormsForPage, } from "./observe-protected.js";
|
|
24
|
+
import { classifyObservePageState, shouldSuppressFillableFormsForObserve, } from "./observe-page-state.js";
|
|
25
|
+
import { annotateDomTargets, compressSemanticallyDuplicateTargets, orderBySurfaceCompetition, prioritizeGoalActionTargets, } from "./observe-semantics.js";
|
|
26
|
+
import { buildGroupedObserveScopes, buildGoalProjectionScopeRefs, buildGoalObserveInventoryCandidates, compactFillableForms, compactSignals, expandWorkflowGraphTargets, projectPersistedTargetsForGoal, selectTargetsForGoalMatches, } from "./observe-projection.js";
|
|
27
|
+
import { collectSurfaceDescriptors, selectScopesForOutput, } from "./observe-surfaces.js";
|
|
28
|
+
import { toStagehandDescriptor } from "./observe-stagehand.js";
|
|
29
|
+
import { rerankDomTargetsForGoal } from "./semantic-observe.js";
|
|
30
|
+
/** Stable top-level error codes returned by `observe(...)`. */
|
|
31
|
+
export const OBSERVE_ERROR_CODES = [
|
|
32
|
+
"browser_connection_failed",
|
|
33
|
+
"observe_failed",
|
|
34
|
+
"protected_observe_blocked",
|
|
35
|
+
];
|
|
36
|
+
/** Stable outcome categories emitted by `observe(...)`. */
|
|
37
|
+
export const OBSERVE_OUTCOME_TYPES = [
|
|
38
|
+
"blocked",
|
|
39
|
+
"observation_completed",
|
|
40
|
+
"protected_exposure_active",
|
|
41
|
+
];
|
|
42
|
+
function flattenObserveTargets(scopes) {
|
|
43
|
+
if (!Array.isArray(scopes)) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
return scopes.flatMap((scope) => {
|
|
47
|
+
if (!scope || typeof scope !== "object" || Array.isArray(scope)) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
const typedScope = scope;
|
|
51
|
+
return Array.isArray(typedScope.targets) ? typedScope.targets : [];
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function normalizeObserveSuccessPayload(payload) {
|
|
55
|
+
const scopes = Array.isArray(payload.scopes) ? payload.scopes : [];
|
|
56
|
+
const explicitTargets = Array.isArray(payload.targets) ? payload.targets : [];
|
|
57
|
+
const targets = explicitTargets.length > 0 || Array.isArray(payload.targets)
|
|
58
|
+
? explicitTargets
|
|
59
|
+
: flattenObserveTargets(scopes);
|
|
60
|
+
return {
|
|
61
|
+
...payload,
|
|
62
|
+
scopes,
|
|
63
|
+
targets,
|
|
64
|
+
signals: Array.isArray(payload.signals) ? payload.signals : [],
|
|
65
|
+
fillableForms: Array.isArray(payload.fillableForms)
|
|
66
|
+
? payload.fillableForms
|
|
67
|
+
: [],
|
|
68
|
+
targetCount: targets.length,
|
|
69
|
+
scopeCount: scopes.length,
|
|
70
|
+
projectedTargetCount: targets.length,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function tryResolveHost(url) {
|
|
74
|
+
try {
|
|
75
|
+
return new URL(url).hostname || undefined;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function buildObservePageMetadata(params) {
|
|
82
|
+
return {
|
|
83
|
+
url: params.url,
|
|
84
|
+
title: params.title,
|
|
85
|
+
...(params.protectedExposure && tryResolveHost(params.url)
|
|
86
|
+
? { host: tryResolveHost(params.url) }
|
|
87
|
+
: {}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function finalizeObserveStepBestEffort(step, options) {
|
|
91
|
+
return finishDiagnosticStepBestEffort({
|
|
92
|
+
step,
|
|
93
|
+
...options,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
async function buildObserveSuccessResult(session, step, payload) {
|
|
97
|
+
const normalizedPayload = scrubProtectedExactValues(session, normalizeObserveSuccessPayload(payload));
|
|
98
|
+
captureDiagnosticSnapshotBestEffort({
|
|
99
|
+
session,
|
|
100
|
+
step,
|
|
101
|
+
phase: "after",
|
|
102
|
+
pageRef: typeof normalizedPayload.pageRef === "string"
|
|
103
|
+
? normalizedPayload.pageRef
|
|
104
|
+
: session.runtime?.currentPageRef,
|
|
105
|
+
url: typeof normalizedPayload.url === "string"
|
|
106
|
+
? normalizedPayload.url
|
|
107
|
+
: undefined,
|
|
108
|
+
title: typeof normalizedPayload.title === "string"
|
|
109
|
+
? normalizedPayload.title
|
|
110
|
+
: undefined,
|
|
111
|
+
});
|
|
112
|
+
recordCommandLifecycleEventBestEffort({
|
|
113
|
+
step,
|
|
114
|
+
phase: "completed",
|
|
115
|
+
attributes: {
|
|
116
|
+
outcomeType: "observation_completed",
|
|
117
|
+
...(typeof normalizedPayload.pageRef === "string"
|
|
118
|
+
? { pageRef: normalizedPayload.pageRef }
|
|
119
|
+
: {}),
|
|
120
|
+
...(typeof normalizedPayload.resolvedBy === "string"
|
|
121
|
+
? { resolvedBy: normalizedPayload.resolvedBy }
|
|
122
|
+
: {}),
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
await finalizeObserveStepBestEffort(step, {
|
|
126
|
+
success: true,
|
|
127
|
+
outcomeType: "observation_completed",
|
|
128
|
+
message: typeof normalizedPayload.message === "string"
|
|
129
|
+
? normalizedPayload.message
|
|
130
|
+
: "Observe completed.",
|
|
131
|
+
});
|
|
132
|
+
return normalizedPayload;
|
|
133
|
+
}
|
|
134
|
+
async function buildObserveContractFailureResult(session, params) {
|
|
135
|
+
const step = params.step;
|
|
136
|
+
captureDiagnosticSnapshotBestEffort({
|
|
137
|
+
session,
|
|
138
|
+
step,
|
|
139
|
+
phase: "point-in-time",
|
|
140
|
+
pageRef: typeof params.pageRef === "string" ? params.pageRef : undefined,
|
|
141
|
+
});
|
|
142
|
+
recordCommandLifecycleEventBestEffort({
|
|
143
|
+
step,
|
|
144
|
+
phase: "failed",
|
|
145
|
+
attributes: {
|
|
146
|
+
...(params.outcomeType ? { outcomeType: params.outcomeType } : {}),
|
|
147
|
+
...(typeof params.pageRef === "string"
|
|
148
|
+
? { pageRef: params.pageRef }
|
|
149
|
+
: {}),
|
|
150
|
+
...(params.reason ? { reason: params.reason } : {}),
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
await finalizeObserveStepBestEffort(step, {
|
|
154
|
+
success: false,
|
|
155
|
+
outcomeType: params.outcomeType,
|
|
156
|
+
message: params.message,
|
|
157
|
+
reason: params.reason,
|
|
158
|
+
});
|
|
159
|
+
const { runId: _runId, stepId: _stepId, step: _step, ...result } = params;
|
|
160
|
+
return scrubProtectedExactValues(session, {
|
|
161
|
+
success: false,
|
|
162
|
+
...result,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
export const __testDomTargetCollection = inventoryDomTargetCollection;
|
|
166
|
+
export const __testStagehandDescriptor = {
|
|
167
|
+
...inventoryStagehandDescriptor,
|
|
168
|
+
toStagehandDescriptor,
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Observes the current page and returns the current target inventory.
|
|
172
|
+
*
|
|
173
|
+
* The success payload always includes a flat `targets` array for direct
|
|
174
|
+
* consumption and grouped `scopes` for richer container-aware workflows.
|
|
175
|
+
*/
|
|
176
|
+
export async function observeBrowser(session, instruction) {
|
|
177
|
+
const allowAssistive = Boolean(instruction);
|
|
178
|
+
const canUseAssistiveLlm = allowAssistive
|
|
179
|
+
? canUseAgentbrowseAssistiveLlmClient({ session })
|
|
180
|
+
: false;
|
|
181
|
+
const runtime = ensureRuntimeState(session);
|
|
182
|
+
let pageRef = runtime.currentPageRef;
|
|
183
|
+
let domPassError = null;
|
|
184
|
+
let stagehandFallbackReason = null;
|
|
185
|
+
let browser = null;
|
|
186
|
+
let observedScopes = [];
|
|
187
|
+
const observeStep = startDiagnosticStep({
|
|
188
|
+
runId: session.activeRunId,
|
|
189
|
+
command: "observe",
|
|
190
|
+
input: {
|
|
191
|
+
...(instruction ? { instruction } : {}),
|
|
192
|
+
},
|
|
193
|
+
refs: {
|
|
194
|
+
pageRef,
|
|
195
|
+
},
|
|
196
|
+
protectedStep: Boolean(session.runtime?.protectedExposureByPage?.[pageRef]),
|
|
197
|
+
}, { session });
|
|
198
|
+
captureDiagnosticSnapshotBestEffort({
|
|
199
|
+
session,
|
|
200
|
+
step: observeStep,
|
|
201
|
+
phase: "before",
|
|
202
|
+
pageRef,
|
|
203
|
+
});
|
|
204
|
+
recordCommandLifecycleEventBestEffort({
|
|
205
|
+
step: observeStep,
|
|
206
|
+
phase: "started",
|
|
207
|
+
attributes: {
|
|
208
|
+
...(instruction ? { instruction } : {}),
|
|
209
|
+
pageRef,
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
return withApiTraceContext({
|
|
213
|
+
runId: session.activeRunId,
|
|
214
|
+
stepId: observeStep?.stepId,
|
|
215
|
+
command: "observe",
|
|
216
|
+
}, async () => {
|
|
217
|
+
const observePhaseAttributes = {
|
|
218
|
+
"agentbrowse.observe.goal_based": Boolean(instruction),
|
|
219
|
+
};
|
|
220
|
+
const initialProtectedExposure = instruction
|
|
221
|
+
? getProtectedExposure(session, pageRef)
|
|
222
|
+
: null;
|
|
223
|
+
if (instruction && initialProtectedExposure) {
|
|
224
|
+
return buildObserveContractFailureResult(session, {
|
|
225
|
+
step: observeStep,
|
|
226
|
+
...buildProtectedObserveBlockedResult(initialProtectedExposure, "goal-rerank"),
|
|
227
|
+
pageRef,
|
|
228
|
+
runId: session.activeRunId,
|
|
229
|
+
stepId: observeStep?.stepId,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
if (!instruction) {
|
|
233
|
+
try {
|
|
234
|
+
browser = await connectPlaywright(session.cdpUrl);
|
|
235
|
+
const resolvedPage = await resolveCurrentPageContext(browser, session);
|
|
236
|
+
pageRef = resolvedPage.pageRef;
|
|
237
|
+
const page = resolvedPage.page;
|
|
238
|
+
const { url, title } = await syncSessionPage(session, pageRef, page);
|
|
239
|
+
const protectedExposure = getProtectedExposure(session, pageRef);
|
|
240
|
+
bumpPageScopeEpoch(session, pageRef);
|
|
241
|
+
setCurrentPage(session, pageRef);
|
|
242
|
+
const collectedTargets = await collectDomTargets(page);
|
|
243
|
+
let observeAccessibilityStats;
|
|
244
|
+
const domTargets = compressSemanticallyDuplicateTargets(orderBySurfaceCompetition(annotateDomTargets(await enrichDomTargetsWithAccessibility(page, collectedTargets, {
|
|
245
|
+
onStats: (stats) => {
|
|
246
|
+
observeAccessibilityStats = stats;
|
|
247
|
+
},
|
|
248
|
+
}))));
|
|
249
|
+
if (observeAccessibilityStats) {
|
|
250
|
+
incrementMetric(session, "observeAxAttempts", observeAccessibilityStats.axAttempts);
|
|
251
|
+
incrementMetric(session, "observeAxHits", observeAccessibilityStats.axHits);
|
|
252
|
+
incrementMetric(session, "observeFallbackUses", observeAccessibilityStats.fallbackUses);
|
|
253
|
+
}
|
|
254
|
+
const pageSignals = await collectPageSignals(page).catch(() => []);
|
|
255
|
+
const pageState = classifyObservePageState(pageSignals);
|
|
256
|
+
const persisted = persistObservedSurfacesForPage(session, pageRef, domTargets);
|
|
257
|
+
observedScopes = persisted.observedScopes;
|
|
258
|
+
const surfaceRefMap = persisted.surfaceRefMap;
|
|
259
|
+
if (domTargets.length > 0) {
|
|
260
|
+
const targets = replaceTargetsForPage(session, pageRef, domTargets.map((target) => toDomDescriptor(pageRef, target, surfaceRefMap)));
|
|
261
|
+
reconcileObservedTargetsForPage(session, pageRef, targets);
|
|
262
|
+
attachObservedTargetOwners(domTargets, targets);
|
|
263
|
+
observedScopes = linkObservedSurfaceGraph(session, pageRef, domTargets, targets, observedScopes, surfaceRefMap);
|
|
264
|
+
const fillableForms = shouldSuppressFillableFormsForObserve(pageState)
|
|
265
|
+
? clearProtectedFillableFormsForPage(session, pageRef)
|
|
266
|
+
: await persistProtectedFillableFormsForPage(session, pageRef, url, targets, new Date().toISOString());
|
|
267
|
+
await disconnectPlaywright(browser);
|
|
268
|
+
browser = null;
|
|
269
|
+
return buildObserveSuccessResult(session, observeStep, {
|
|
270
|
+
success: true,
|
|
271
|
+
observationMode: "deterministic_dom",
|
|
272
|
+
pageRef,
|
|
273
|
+
resolvedBy: "dom",
|
|
274
|
+
...domRuntimeResolution(),
|
|
275
|
+
scopes: buildGroupedObserveScopes({
|
|
276
|
+
pageRef,
|
|
277
|
+
title,
|
|
278
|
+
scopes: selectScopesForOutput(observedScopes, targets),
|
|
279
|
+
targets,
|
|
280
|
+
}),
|
|
281
|
+
signals: compactSignals(pageSignals),
|
|
282
|
+
fillableForms: compactFillableForms(fillableForms),
|
|
283
|
+
metrics: session.runtime?.metrics,
|
|
284
|
+
message: targets.length === 0
|
|
285
|
+
? "This observe pass returned zero targets."
|
|
286
|
+
: undefined,
|
|
287
|
+
...buildObservePageMetadata({
|
|
288
|
+
url,
|
|
289
|
+
title,
|
|
290
|
+
protectedExposure,
|
|
291
|
+
}),
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
if (!allowAssistive) {
|
|
295
|
+
await disconnectPlaywright(browser);
|
|
296
|
+
browser = null;
|
|
297
|
+
return buildObserveSuccessResult(session, observeStep, {
|
|
298
|
+
success: true,
|
|
299
|
+
observationMode: "deterministic_dom",
|
|
300
|
+
pageRef,
|
|
301
|
+
resolvedBy: "dom",
|
|
302
|
+
...domRuntimeResolution(),
|
|
303
|
+
scopes: [],
|
|
304
|
+
signals: compactSignals(pageSignals),
|
|
305
|
+
fillableForms: [],
|
|
306
|
+
metrics: session.runtime?.metrics,
|
|
307
|
+
message: "This observe pass returned zero targets.",
|
|
308
|
+
...buildObservePageMetadata({
|
|
309
|
+
url,
|
|
310
|
+
title,
|
|
311
|
+
protectedExposure,
|
|
312
|
+
}),
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
stagehandFallbackReason = "deterministic-observe-empty";
|
|
316
|
+
}
|
|
317
|
+
catch (err) {
|
|
318
|
+
domPassError = err instanceof Error ? err.message : String(err);
|
|
319
|
+
if (!allowAssistive) {
|
|
320
|
+
return buildObserveContractFailureResult(session, {
|
|
321
|
+
step: observeStep,
|
|
322
|
+
error: "observe_failed",
|
|
323
|
+
outcomeType: "blocked",
|
|
324
|
+
message: "Observe failed.",
|
|
325
|
+
reason: domPassError,
|
|
326
|
+
pageRef,
|
|
327
|
+
runId: session.activeRunId,
|
|
328
|
+
stepId: observeStep?.stepId,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
stagehandFallbackReason = "deterministic-observe-failed";
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (instruction) {
|
|
335
|
+
try {
|
|
336
|
+
if (!browser) {
|
|
337
|
+
browser = await connectPlaywright(session.cdpUrl);
|
|
338
|
+
}
|
|
339
|
+
const resolvedPage = await resolveCurrentPageContext(browser, session);
|
|
340
|
+
pageRef = resolvedPage.pageRef;
|
|
341
|
+
const page = resolvedPage.page;
|
|
342
|
+
const { url, title } = await syncSessionPage(session, pageRef, page);
|
|
343
|
+
const protectedExposure = getProtectedExposure(session, pageRef);
|
|
344
|
+
if (protectedExposure) {
|
|
345
|
+
return buildObserveContractFailureResult(session, {
|
|
346
|
+
step: observeStep,
|
|
347
|
+
...buildProtectedObserveBlockedResult(protectedExposure, "goal-rerank"),
|
|
348
|
+
pageRef,
|
|
349
|
+
runId: session.activeRunId,
|
|
350
|
+
stepId: observeStep?.stepId,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
bumpPageScopeEpoch(session, pageRef);
|
|
354
|
+
setCurrentPage(session, pageRef);
|
|
355
|
+
const collectedTargets = await collectDomTargets(page, {
|
|
356
|
+
includeActivationAffordances: true,
|
|
357
|
+
});
|
|
358
|
+
let observeAccessibilityStats;
|
|
359
|
+
const domTargets = compressSemanticallyDuplicateTargets(orderBySurfaceCompetition(annotateDomTargets(await enrichDomTargetsWithAccessibility(page, collectedTargets, {
|
|
360
|
+
onStats: (stats) => {
|
|
361
|
+
observeAccessibilityStats = stats;
|
|
362
|
+
},
|
|
363
|
+
}))));
|
|
364
|
+
if (observeAccessibilityStats) {
|
|
365
|
+
incrementMetric(session, "observeAxAttempts", observeAccessibilityStats.axAttempts);
|
|
366
|
+
incrementMetric(session, "observeAxHits", observeAccessibilityStats.axHits);
|
|
367
|
+
incrementMetric(session, "observeFallbackUses", observeAccessibilityStats.fallbackUses);
|
|
368
|
+
}
|
|
369
|
+
const pageSignals = await collectPageSignals(page).catch(() => []);
|
|
370
|
+
const pageState = classifyObservePageState(pageSignals);
|
|
371
|
+
const surfaceInputs = collectSurfaceDescriptors(pageRef, domTargets);
|
|
372
|
+
if (domTargets.length > 0) {
|
|
373
|
+
const rerankedCandidates = await tracedStepOperation(() => rerankDomTargetsForGoal(instruction, buildGoalObserveInventoryCandidates(domTargets, surfaceInputs), { session }), {
|
|
374
|
+
spanName: "agentbrowse.observe.rerank_goal_candidates",
|
|
375
|
+
attributes: {
|
|
376
|
+
...observePhaseAttributes,
|
|
377
|
+
"agentbrowse.observe.target_count": domTargets.length,
|
|
378
|
+
},
|
|
379
|
+
});
|
|
380
|
+
const { targets: goalMatchedTargets, selectedSurfaceIds } = selectTargetsForGoalMatches(domTargets, rerankedCandidates);
|
|
381
|
+
const selectedTargets = prioritizeGoalActionTargets(instruction, expandWorkflowGraphTargets(domTargets, goalMatchedTargets, {
|
|
382
|
+
selectedSurfaceIds,
|
|
383
|
+
}));
|
|
384
|
+
const persisted = persistObservedSurfacesForPage(session, pageRef, domTargets, {
|
|
385
|
+
allSurfaceInputs: surfaceInputs,
|
|
386
|
+
explicitSurfaceIds: selectedSurfaceIds,
|
|
387
|
+
});
|
|
388
|
+
observedScopes = persisted.observedScopes;
|
|
389
|
+
const surfaceRefMap = persisted.surfaceRefMap;
|
|
390
|
+
const targets = replaceTargetsForPage(session, pageRef, domTargets.map((target) => toDomDescriptor(pageRef, target, surfaceRefMap)));
|
|
391
|
+
reconcileObservedTargetsForPage(session, pageRef, targets);
|
|
392
|
+
attachObservedTargetOwners(domTargets, targets);
|
|
393
|
+
observedScopes = linkObservedSurfaceGraph(session, pageRef, domTargets, targets, observedScopes, surfaceRefMap);
|
|
394
|
+
const fillableForms = shouldSuppressFillableFormsForObserve(pageState)
|
|
395
|
+
? clearProtectedFillableFormsForPage(session, pageRef)
|
|
396
|
+
: await persistProtectedFillableFormsForPage(session, pageRef, url, targets, new Date().toISOString());
|
|
397
|
+
if (selectedTargets.length > 0 || selectedSurfaceIds.size > 0) {
|
|
398
|
+
const projectedTargets = projectPersistedTargetsForGoal(domTargets, targets, selectedTargets);
|
|
399
|
+
const explicitScopeRefs = buildGoalProjectionScopeRefs(projectedTargets, selectedSurfaceIds, surfaceRefMap);
|
|
400
|
+
await disconnectPlaywright(browser);
|
|
401
|
+
browser = null;
|
|
402
|
+
return buildObserveSuccessResult(session, observeStep, {
|
|
403
|
+
success: true,
|
|
404
|
+
observationMode: canUseAssistiveLlm
|
|
405
|
+
? "goal_assistive_rerank"
|
|
406
|
+
: "goal_heuristic_shortlist",
|
|
407
|
+
pageRef,
|
|
408
|
+
resolvedBy: "dom-rerank",
|
|
409
|
+
...domRuntimeResolution(),
|
|
410
|
+
scopes: buildGroupedObserveScopes({
|
|
411
|
+
pageRef,
|
|
412
|
+
title,
|
|
413
|
+
scopes: selectScopesForOutput(observedScopes, projectedTargets, explicitScopeRefs),
|
|
414
|
+
targets: projectedTargets,
|
|
415
|
+
}),
|
|
416
|
+
signals: compactSignals(pageSignals),
|
|
417
|
+
fillableForms: compactFillableForms(fillableForms),
|
|
418
|
+
metrics: session.runtime?.metrics,
|
|
419
|
+
url,
|
|
420
|
+
title,
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
await disconnectPlaywright(browser);
|
|
424
|
+
browser = null;
|
|
425
|
+
return buildObserveSuccessResult(session, observeStep, {
|
|
426
|
+
success: true,
|
|
427
|
+
observationMode: canUseAssistiveLlm
|
|
428
|
+
? "goal_assistive_rerank"
|
|
429
|
+
: "goal_heuristic_shortlist",
|
|
430
|
+
pageRef,
|
|
431
|
+
resolvedBy: "dom-rerank",
|
|
432
|
+
...domRuntimeResolution(),
|
|
433
|
+
scopes: [],
|
|
434
|
+
signals: compactSignals(pageSignals),
|
|
435
|
+
fillableForms: compactFillableForms(fillableForms),
|
|
436
|
+
metrics: session.runtime?.metrics,
|
|
437
|
+
message: "This goal-based observe pass returned zero matching targets.",
|
|
438
|
+
url,
|
|
439
|
+
title,
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
stagehandFallbackReason = "deterministic-observe-empty";
|
|
443
|
+
}
|
|
444
|
+
catch (err) {
|
|
445
|
+
domPassError = err instanceof Error ? err.message : String(err);
|
|
446
|
+
stagehandFallbackReason = "deterministic-observe-failed";
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
try {
|
|
450
|
+
if (!browser) {
|
|
451
|
+
browser = await connectPlaywright(session.cdpUrl);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
catch (err) {
|
|
455
|
+
const domFailure = domPassError && domPassError.length > 0
|
|
456
|
+
? `; dom observe failed: ${domPassError}`
|
|
457
|
+
: "";
|
|
458
|
+
return buildObserveContractFailureResult(session, {
|
|
459
|
+
step: observeStep,
|
|
460
|
+
error: "browser_connection_failed",
|
|
461
|
+
outcomeType: "blocked",
|
|
462
|
+
message: "Observe could not start because AgentBrowse failed to connect to the browser.",
|
|
463
|
+
reason: `${err instanceof Error ? err.message : String(err)}${domFailure}`,
|
|
464
|
+
pageRef,
|
|
465
|
+
runId: session.activeRunId,
|
|
466
|
+
stepId: observeStep?.stepId,
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
try {
|
|
470
|
+
const resolvedPage = await resolveCurrentPageContext(browser, session);
|
|
471
|
+
pageRef = resolvedPage.pageRef;
|
|
472
|
+
const page = resolvedPage.page;
|
|
473
|
+
const { url, title } = await syncSessionPage(session, pageRef, page);
|
|
474
|
+
const protectedExposure = getProtectedExposure(session, pageRef);
|
|
475
|
+
if (protectedExposure) {
|
|
476
|
+
return buildObserveContractFailureResult(session, {
|
|
477
|
+
step: observeStep,
|
|
478
|
+
...buildProtectedObserveBlockedResult(protectedExposure, "stagehand-fallback"),
|
|
479
|
+
fallbackReason: stagehandFallbackReason ?? undefined,
|
|
480
|
+
deterministicObserveError: domPassError ?? undefined,
|
|
481
|
+
pageRef,
|
|
482
|
+
runId: session.activeRunId,
|
|
483
|
+
stepId: observeStep?.stepId,
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
bumpPageScopeEpoch(session, pageRef);
|
|
487
|
+
setCurrentPage(session, pageRef);
|
|
488
|
+
const pageSignals = await collectPageSignals(page).catch(() => []);
|
|
489
|
+
const actions = await withStagehand(session, async (stagehand) => {
|
|
490
|
+
incrementMetric(session, "stagehandCalls");
|
|
491
|
+
return instruction
|
|
492
|
+
? (await stagehand.observe(instruction, {
|
|
493
|
+
page,
|
|
494
|
+
}))
|
|
495
|
+
: (await stagehand.observe({ page }));
|
|
496
|
+
});
|
|
497
|
+
const targets = replaceTargetsForPage(session, pageRef, await Promise.all(actions.map((action) => toStagehandDescriptor(pageRef, action, page, normalizePageSignature(url)))));
|
|
498
|
+
const fillableForms = markProtectedFillableFormsUnknownForPage(session, pageRef);
|
|
499
|
+
return buildObserveSuccessResult(session, observeStep, {
|
|
500
|
+
success: true,
|
|
501
|
+
observationMode: "goal_assistive_stagehand",
|
|
502
|
+
pageRef,
|
|
503
|
+
resolvedBy: "stagehand-observe",
|
|
504
|
+
...stagehandRuntimeResolution(stagehandFallbackReason ?? "deterministic-observe-failed"),
|
|
505
|
+
deterministicObserveError: domPassError ?? undefined,
|
|
506
|
+
scopes: buildGroupedObserveScopes({
|
|
507
|
+
pageRef,
|
|
508
|
+
title,
|
|
509
|
+
scopes: selectScopesForOutput(observedScopes, targets),
|
|
510
|
+
targets,
|
|
511
|
+
}),
|
|
512
|
+
signals: compactSignals(pageSignals),
|
|
513
|
+
fillableForms: compactFillableForms(fillableForms),
|
|
514
|
+
metrics: session.runtime?.metrics,
|
|
515
|
+
message: targets.length === 0
|
|
516
|
+
? "This observe pass returned zero targets."
|
|
517
|
+
: undefined,
|
|
518
|
+
url,
|
|
519
|
+
title,
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
catch (err) {
|
|
523
|
+
const stagehandError = err instanceof Error ? err.message : String(err);
|
|
524
|
+
const details = domPassError
|
|
525
|
+
? `${stagehandError} (deterministic observe failed earlier: ${domPassError})`
|
|
526
|
+
: stagehandError;
|
|
527
|
+
return buildObserveContractFailureResult(session, {
|
|
528
|
+
step: observeStep,
|
|
529
|
+
error: "observe_failed",
|
|
530
|
+
outcomeType: "blocked",
|
|
531
|
+
message: "Observe failed.",
|
|
532
|
+
reason: details,
|
|
533
|
+
pageRef,
|
|
534
|
+
runId: session.activeRunId,
|
|
535
|
+
stepId: observeStep?.stepId,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
finally {
|
|
539
|
+
if (browser) {
|
|
540
|
+
await disconnectPlaywright(browser);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
/** CLI wrapper for `observeBrowser(...)` that persists the observed runtime state. */
|
|
546
|
+
export async function observe(session, instruction) {
|
|
547
|
+
const result = await observeBrowser(session, instruction);
|
|
548
|
+
if (result.success) {
|
|
549
|
+
saveSession(session);
|
|
550
|
+
}
|
|
551
|
+
if (result.success) {
|
|
552
|
+
return outputJSON(result);
|
|
553
|
+
}
|
|
554
|
+
const { success: _success, ...failure } = result;
|
|
555
|
+
return outputContractFailure(failure);
|
|
556
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* browse screenshot [--path <file>] — Capture a screenshot of the current page.
|
|
3
|
+
*/
|
|
4
|
+
import type { BrowserCommandSession } from '../browser-session-state.js';
|
|
5
|
+
/** Stable top-level error codes returned by `screenshot(...)`. */
|
|
6
|
+
export declare const SCREENSHOT_ERROR_CODES: readonly ["browser_connection_failed", "protected_screenshot_blocked", "screenshot_failed"];
|
|
7
|
+
/** Stable outcome categories emitted by `screenshot(...)`. */
|
|
8
|
+
export declare const SCREENSHOT_OUTCOME_TYPES: readonly ["blocked", "protected_exposure_active", "screenshot_captured"];
|
|
9
|
+
export type ScreenshotErrorCode = (typeof SCREENSHOT_ERROR_CODES)[number];
|
|
10
|
+
export type ScreenshotOutcomeType = (typeof SCREENSHOT_OUTCOME_TYPES)[number];
|
|
11
|
+
/** Successful screenshot capture result. */
|
|
12
|
+
export type ScreenshotSuccessResult = {
|
|
13
|
+
success: true;
|
|
14
|
+
pageRef: string;
|
|
15
|
+
path: string;
|
|
16
|
+
url: string;
|
|
17
|
+
title: string;
|
|
18
|
+
};
|
|
19
|
+
/** Failed screenshot capture result. */
|
|
20
|
+
export type ScreenshotFailureResult = {
|
|
21
|
+
success: false;
|
|
22
|
+
error: ScreenshotErrorCode;
|
|
23
|
+
outcomeType: Extract<ScreenshotOutcomeType, 'blocked' | 'protected_exposure_active'>;
|
|
24
|
+
message: string;
|
|
25
|
+
reason: string;
|
|
26
|
+
pageRef?: string;
|
|
27
|
+
fillRef?: string;
|
|
28
|
+
requestId?: string;
|
|
29
|
+
activatedAt?: string;
|
|
30
|
+
exposureReason?: string;
|
|
31
|
+
};
|
|
32
|
+
export type ScreenshotResult = ScreenshotSuccessResult | ScreenshotFailureResult;
|
|
33
|
+
/** Captures a screenshot of the currently active page. */
|
|
34
|
+
export declare function screenshotBrowser(session: BrowserCommandSession, filePath?: string): Promise<ScreenshotResult>;
|
|
35
|
+
/** CLI wrapper for `screenshotBrowser(...)` that persists session changes and writes JSON output. */
|
|
36
|
+
export declare function screenshot(session: BrowserCommandSession, filePath?: string): Promise<void>;
|
|
37
|
+
//# sourceMappingURL=screenshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screenshot.d.ts","sourceRoot":"","sources":["../../src/commands/screenshot.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAqBzE,kEAAkE;AAClE,eAAO,MAAM,sBAAsB,6FAIzB,CAAC;AAEX,8DAA8D;AAC9D,eAAO,MAAM,wBAAwB,0EAI3B,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC1E,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9E,4CAA4C;AAC5C,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,wCAAwC;AACxC,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,mBAAmB,CAAC;IAC3B,WAAW,EAAE,OAAO,CAAC,qBAAqB,EAAE,SAAS,GAAG,2BAA2B,CAAC,CAAC;IACrF,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,uBAAuB,GAAG,uBAAuB,CAAC;AAkJjF,0DAA0D;AAC1D,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,qBAAqB,EAC9B,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,gBAAgB,CAAC,CAwH3B;AAED,qGAAqG;AACrG,wBAAsB,UAAU,CAAC,OAAO,EAAE,qBAAqB,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAmBjG"}
|