browser-use 0.2.0 → 0.4.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 +295 -686
- package/dist/actor/element.d.ts +19 -0
- package/dist/actor/element.js +46 -0
- package/dist/actor/index.d.ts +4 -0
- package/dist/actor/index.js +4 -0
- package/dist/actor/mouse.d.ts +19 -0
- package/dist/actor/mouse.js +39 -0
- package/dist/actor/page.d.ts +29 -0
- package/dist/actor/page.js +88 -0
- package/dist/actor/utils.d.ts +4 -0
- package/dist/actor/utils.js +35 -0
- package/dist/agent/cloud-events.d.ts +18 -0
- package/dist/agent/cloud-events.js +65 -2
- package/dist/agent/gif.d.ts +1 -0
- package/dist/agent/gif.js +24 -2
- package/dist/agent/judge.d.ts +17 -0
- package/dist/agent/judge.js +197 -0
- package/dist/agent/message-manager/service.d.ts +12 -4
- package/dist/agent/message-manager/service.js +205 -39
- package/dist/agent/message-manager/utils.js +0 -1
- package/dist/agent/message-manager/views.d.ts +4 -0
- package/dist/agent/message-manager/views.js +11 -7
- package/dist/agent/prompts.d.ts +24 -3
- package/dist/agent/prompts.js +274 -59
- package/dist/agent/service.d.ts +103 -41
- package/dist/agent/service.js +2336 -472
- package/dist/agent/variable-detector.d.ts +12 -0
- package/dist/agent/variable-detector.js +211 -0
- package/dist/agent/views.d.ts +237 -18
- package/dist/agent/views.js +446 -33
- package/dist/browser/cloud/cloud.d.ts +20 -0
- package/dist/browser/cloud/cloud.js +129 -0
- package/dist/browser/cloud/index.d.ts +2 -0
- package/dist/browser/cloud/index.js +2 -0
- package/dist/browser/cloud/views.d.ts +41 -0
- package/dist/browser/cloud/views.js +35 -0
- package/dist/browser/events.d.ts +345 -0
- package/dist/browser/events.js +566 -0
- package/dist/browser/extensions.js +17 -17
- package/dist/browser/index.d.ts +4 -0
- package/dist/browser/index.js +4 -0
- package/dist/browser/profile.d.ts +10 -4
- package/dist/browser/profile.js +79 -12
- package/dist/browser/session-manager.d.ts +85 -0
- package/dist/browser/session-manager.js +208 -0
- package/dist/browser/session.d.ts +105 -9
- package/dist/browser/session.js +1166 -95
- package/dist/browser/types.d.ts +153 -156
- package/dist/browser/views.d.ts +39 -0
- package/dist/browser/views.js +32 -0
- package/dist/browser/watchdogs/aboutblank-watchdog.d.ts +12 -0
- package/dist/browser/watchdogs/aboutblank-watchdog.js +131 -0
- package/dist/browser/watchdogs/base.d.ts +21 -0
- package/dist/browser/watchdogs/base.js +81 -0
- package/dist/browser/watchdogs/cdp-session-watchdog.d.ts +14 -0
- package/dist/browser/watchdogs/cdp-session-watchdog.js +177 -0
- package/dist/browser/watchdogs/crash-watchdog.d.ts +38 -0
- package/dist/browser/watchdogs/crash-watchdog.js +296 -0
- package/dist/browser/watchdogs/default-action-watchdog.d.ts +49 -0
- package/dist/browser/watchdogs/default-action-watchdog.js +212 -0
- package/dist/browser/watchdogs/dom-watchdog.d.ts +8 -0
- package/dist/browser/watchdogs/dom-watchdog.js +31 -0
- package/dist/browser/watchdogs/downloads-watchdog.d.ts +77 -0
- package/dist/browser/watchdogs/downloads-watchdog.js +409 -0
- package/dist/browser/watchdogs/har-recording-watchdog.d.ts +19 -0
- package/dist/browser/watchdogs/har-recording-watchdog.js +317 -0
- package/dist/browser/watchdogs/index.d.ts +15 -0
- package/dist/browser/watchdogs/index.js +15 -0
- package/dist/browser/watchdogs/local-browser-watchdog.d.ts +10 -0
- package/dist/browser/watchdogs/local-browser-watchdog.js +32 -0
- package/dist/browser/watchdogs/permissions-watchdog.d.ts +8 -0
- package/dist/browser/watchdogs/permissions-watchdog.js +73 -0
- package/dist/browser/watchdogs/popups-watchdog.d.ts +13 -0
- package/dist/browser/watchdogs/popups-watchdog.js +77 -0
- package/dist/browser/watchdogs/recording-watchdog.d.ts +27 -0
- package/dist/browser/watchdogs/recording-watchdog.js +249 -0
- package/dist/browser/watchdogs/screenshot-watchdog.d.ts +6 -0
- package/dist/browser/watchdogs/screenshot-watchdog.js +13 -0
- package/dist/browser/watchdogs/security-watchdog.d.ts +10 -0
- package/dist/browser/watchdogs/security-watchdog.js +84 -0
- package/dist/browser/watchdogs/storage-state-watchdog.d.ts +24 -0
- package/dist/browser/watchdogs/storage-state-watchdog.js +288 -0
- package/dist/cli.d.ts +7 -2
- package/dist/cli.js +182 -25
- package/dist/code-use/formatting.d.ts +3 -0
- package/dist/code-use/formatting.js +18 -0
- package/dist/code-use/index.d.ts +6 -0
- package/dist/code-use/index.js +6 -0
- package/dist/code-use/namespace.d.ts +5 -0
- package/dist/code-use/namespace.js +81 -0
- package/dist/code-use/notebook-export.d.ts +3 -0
- package/dist/code-use/notebook-export.js +56 -0
- package/dist/code-use/service.d.ts +24 -0
- package/dist/code-use/service.js +104 -0
- package/dist/code-use/utils.d.ts +4 -0
- package/dist/code-use/utils.js +98 -0
- package/dist/code-use/views.d.ts +108 -0
- package/dist/code-use/views.js +165 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.js +109 -7
- package/dist/controller/registry/service.d.ts +10 -1
- package/dist/controller/registry/service.js +266 -10
- package/dist/controller/registry/views.d.ts +4 -1
- package/dist/controller/registry/views.js +25 -2
- package/dist/controller/service.d.ts +10 -1
- package/dist/controller/service.js +1814 -268
- package/dist/controller/views.d.ts +78 -155
- package/dist/controller/views.js +61 -12
- package/dist/dom/history-tree-processor/service.d.ts +5 -0
- package/dist/dom/history-tree-processor/service.js +169 -14
- package/dist/dom/history-tree-processor/view.d.ts +7 -1
- package/dist/dom/history-tree-processor/view.js +10 -1
- package/dist/dom/markdown-extractor.d.ts +37 -0
- package/dist/dom/markdown-extractor.js +345 -0
- package/dist/dom/service.d.ts +3 -1
- package/dist/dom/service.js +76 -0
- package/dist/dom/views.d.ts +1 -0
- package/dist/dom/views.js +45 -0
- package/dist/event-bus.d.ts +107 -7
- package/dist/event-bus.js +313 -10
- package/dist/exceptions.d.ts +0 -3
- package/dist/exceptions.js +0 -7
- package/dist/filesystem/file-system.d.ts +18 -0
- package/dist/filesystem/file-system.js +503 -42
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/integrations/gmail/actions.d.ts +3 -3
- package/dist/integrations/gmail/actions.js +4 -4
- package/dist/llm/anthropic/chat.d.ts +18 -1
- package/dist/llm/anthropic/chat.js +123 -55
- package/dist/llm/anthropic/serializer.d.ts +2 -0
- package/dist/llm/anthropic/serializer.js +81 -9
- package/dist/llm/aws/chat-anthropic.d.ts +17 -0
- package/dist/llm/aws/chat-anthropic.js +126 -26
- package/dist/llm/aws/chat-bedrock.d.ts +28 -1
- package/dist/llm/aws/chat-bedrock.js +161 -34
- package/dist/llm/aws/serializer.d.ts +13 -1
- package/dist/llm/aws/serializer.js +56 -17
- package/dist/llm/azure/chat.d.ts +53 -2
- package/dist/llm/azure/chat.js +366 -54
- package/dist/llm/base.d.ts +2 -0
- package/dist/llm/browser-use/chat.d.ts +40 -0
- package/dist/llm/browser-use/chat.js +305 -0
- package/dist/llm/browser-use/index.d.ts +1 -0
- package/dist/llm/browser-use/index.js +1 -0
- package/dist/llm/cerebras/chat.d.ts +39 -0
- package/dist/llm/cerebras/chat.js +178 -0
- package/dist/llm/cerebras/index.d.ts +2 -0
- package/dist/llm/cerebras/index.js +2 -0
- package/dist/llm/cerebras/serializer.d.ts +7 -0
- package/dist/llm/cerebras/serializer.js +82 -0
- package/dist/llm/deepseek/chat.d.ts +19 -2
- package/dist/llm/deepseek/chat.js +138 -25
- package/dist/llm/google/chat.d.ts +46 -2
- package/dist/llm/google/chat.js +267 -64
- package/dist/llm/google/serializer.d.ts +9 -1
- package/dist/llm/google/serializer.js +141 -34
- package/dist/llm/groq/chat.d.ts +21 -2
- package/dist/llm/groq/chat.js +125 -26
- package/dist/llm/groq/parser.js +3 -1
- package/dist/llm/mistral/chat.d.ts +43 -0
- package/dist/llm/mistral/chat.js +154 -0
- package/dist/llm/mistral/index.d.ts +2 -0
- package/dist/llm/mistral/index.js +2 -0
- package/dist/llm/mistral/schema.d.ts +8 -0
- package/dist/llm/mistral/schema.js +27 -0
- package/dist/llm/models.d.ts +2 -0
- package/dist/llm/models.js +317 -0
- package/dist/llm/ollama/chat.d.ts +13 -1
- package/dist/llm/ollama/chat.js +110 -19
- package/dist/llm/ollama/serializer.d.ts +1 -0
- package/dist/llm/ollama/serializer.js +34 -12
- package/dist/llm/openai/chat.d.ts +16 -0
- package/dist/llm/openai/chat.js +94 -44
- package/dist/llm/openai/like.d.ts +5 -3
- package/dist/llm/openai/like.js +7 -3
- package/dist/llm/openai/responses-serializer.d.ts +18 -0
- package/dist/llm/openai/responses-serializer.js +72 -0
- package/dist/llm/openrouter/chat.d.ts +28 -2
- package/dist/llm/openrouter/chat.js +115 -29
- package/dist/llm/schema.d.ts +11 -1
- package/dist/llm/schema.js +109 -4
- package/dist/llm/vercel/chat.d.ts +50 -0
- package/dist/llm/vercel/chat.js +276 -0
- package/dist/llm/vercel/index.d.ts +1 -0
- package/dist/llm/vercel/index.js +1 -0
- package/dist/llm/vercel/serializer.d.ts +5 -0
- package/dist/llm/vercel/serializer.js +7 -0
- package/dist/llm/views.d.ts +2 -1
- package/dist/llm/views.js +3 -1
- package/dist/logging-config.d.ts +2 -0
- package/dist/logging-config.js +82 -29
- package/dist/mcp/client.d.ts +10 -5
- package/dist/mcp/client.js +14 -9
- package/dist/mcp/controller.d.ts +42 -3
- package/dist/mcp/controller.js +56 -31
- package/dist/mcp/server.d.ts +15 -0
- package/dist/mcp/server.js +261 -52
- package/dist/observability.js +10 -4
- package/dist/sandbox/index.d.ts +2 -0
- package/dist/sandbox/index.js +2 -0
- package/dist/sandbox/sandbox.d.ts +19 -0
- package/dist/sandbox/sandbox.js +140 -0
- package/dist/sandbox/views.d.ts +67 -0
- package/dist/sandbox/views.js +121 -0
- package/dist/skill-cli/index.d.ts +3 -0
- package/dist/skill-cli/index.js +3 -0
- package/dist/skill-cli/protocol.d.ts +30 -0
- package/dist/skill-cli/protocol.js +48 -0
- package/dist/skill-cli/server.d.ts +11 -0
- package/dist/skill-cli/server.js +85 -0
- package/dist/skill-cli/sessions.d.ts +24 -0
- package/dist/skill-cli/sessions.js +47 -0
- package/dist/skills/index.d.ts +3 -0
- package/dist/skills/index.js +3 -0
- package/dist/skills/service.d.ts +27 -0
- package/dist/skills/service.js +266 -0
- package/dist/skills/utils.d.ts +6 -0
- package/dist/skills/utils.js +53 -0
- package/dist/skills/views.d.ts +40 -0
- package/dist/skills/views.js +10 -0
- package/dist/sync/auth.js +8 -3
- package/dist/sync/service.d.ts +6 -6
- package/dist/sync/service.js +54 -89
- package/dist/telemetry/views.d.ts +20 -6
- package/dist/telemetry/views.js +23 -5
- package/dist/tokens/custom-pricing.d.ts +2 -0
- package/dist/tokens/custom-pricing.js +22 -0
- package/dist/tokens/index.d.ts +2 -0
- package/dist/tokens/index.js +2 -0
- package/dist/tokens/mappings.d.ts +1 -0
- package/dist/tokens/mappings.js +3 -0
- package/dist/tokens/service.js +27 -8
- package/dist/tools/extraction/index.d.ts +2 -0
- package/dist/tools/extraction/index.js +2 -0
- package/dist/tools/extraction/schema-utils.d.ts +6 -0
- package/dist/tools/extraction/schema-utils.js +237 -0
- package/dist/tools/extraction/views.d.ts +7 -0
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/index.js +5 -0
- package/dist/tools/registry/index.d.ts +2 -0
- package/dist/tools/registry/index.js +2 -0
- package/dist/tools/registry/service.d.ts +1 -0
- package/dist/tools/registry/service.js +1 -0
- package/dist/tools/registry/views.d.ts +1 -0
- package/dist/tools/registry/views.js +1 -0
- package/dist/tools/service.d.ts +2 -0
- package/dist/tools/service.js +1 -0
- package/dist/tools/utils.d.ts +2 -0
- package/dist/tools/utils.js +57 -0
- package/dist/tools/views.d.ts +1 -0
- package/dist/tools/views.js +1 -0
- package/dist/utils.d.ts +10 -1
- package/dist/utils.js +70 -3
- package/package.json +116 -49
- package/dist/dom/playground/process-dom.js +0 -5
- package/dist/dom/playground/test-accessibility.d.ts +0 -44
- package/dist/dom/playground/test-accessibility.js +0 -111
- /package/dist/{dom/playground/process-dom.d.ts → tools/extraction/views.js} +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AgentHistoryList, DetectedVariable } from './views.js';
|
|
2
|
+
import type { DOMHistoryElement } from '../dom/history-tree-processor/view.js';
|
|
3
|
+
export declare const detect_variables_in_history: (history: AgentHistoryList | {
|
|
4
|
+
history: any[];
|
|
5
|
+
}) => Record<string, DetectedVariable>;
|
|
6
|
+
export declare const substitute_in_dict: (data: Record<string, unknown>, replacements: Record<string, string>) => number;
|
|
7
|
+
export declare const _private_for_tests: {
|
|
8
|
+
detectFromAttributes: (attributes: Record<string, string>) => [string, string | null] | null;
|
|
9
|
+
detectFromValuePattern: (value: string) => [string, string | null] | null;
|
|
10
|
+
detectVariableType: (value: string, element: DOMHistoryElement | null) => [string, string | null] | null;
|
|
11
|
+
ensureUniqueName: (baseName: string, existing: Record<string, DetectedVariable>) => string;
|
|
12
|
+
};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { DetectedVariable as DetectedVariableModel } from './views.js';
|
|
2
|
+
const ACTION_FIELDS_TO_CHECK = ['text', 'query'];
|
|
3
|
+
const getActionPayload = (action) => {
|
|
4
|
+
if (action && typeof action.model_dump === 'function') {
|
|
5
|
+
return action.model_dump();
|
|
6
|
+
}
|
|
7
|
+
if (action && typeof action === 'object' && !Array.isArray(action)) {
|
|
8
|
+
return action;
|
|
9
|
+
}
|
|
10
|
+
return {};
|
|
11
|
+
};
|
|
12
|
+
const ensureUniqueName = (baseName, existing) => {
|
|
13
|
+
if (!(baseName in existing)) {
|
|
14
|
+
return baseName;
|
|
15
|
+
}
|
|
16
|
+
let counter = 2;
|
|
17
|
+
while (`${baseName}_${counter}` in existing) {
|
|
18
|
+
counter += 1;
|
|
19
|
+
}
|
|
20
|
+
return `${baseName}_${counter}`;
|
|
21
|
+
};
|
|
22
|
+
const detectFromAttributes = (attributes) => {
|
|
23
|
+
const inputType = String(attributes.type ?? '').toLowerCase();
|
|
24
|
+
if (inputType === 'email')
|
|
25
|
+
return ['email', 'email'];
|
|
26
|
+
if (inputType === 'tel')
|
|
27
|
+
return ['phone', 'phone'];
|
|
28
|
+
if (inputType === 'date')
|
|
29
|
+
return ['date', 'date'];
|
|
30
|
+
if (inputType === 'number')
|
|
31
|
+
return ['number', 'number'];
|
|
32
|
+
if (inputType === 'url')
|
|
33
|
+
return ['url', 'url'];
|
|
34
|
+
const semanticFields = [
|
|
35
|
+
attributes.id ?? '',
|
|
36
|
+
attributes.name ?? '',
|
|
37
|
+
attributes.placeholder ?? '',
|
|
38
|
+
attributes['aria-label'] ?? '',
|
|
39
|
+
];
|
|
40
|
+
const combined = semanticFields.join(' ').toLowerCase();
|
|
41
|
+
if (['address', 'street', 'addr'].some((needle) => combined.includes(needle))) {
|
|
42
|
+
if (combined.includes('billing'))
|
|
43
|
+
return ['billing_address', null];
|
|
44
|
+
if (combined.includes('shipping'))
|
|
45
|
+
return ['shipping_address', null];
|
|
46
|
+
return ['address', null];
|
|
47
|
+
}
|
|
48
|
+
if (['comment', 'note', 'message', 'description'].some((needle) => combined.includes(needle))) {
|
|
49
|
+
return ['comment', null];
|
|
50
|
+
}
|
|
51
|
+
if (combined.includes('email') || combined.includes('e-mail')) {
|
|
52
|
+
return ['email', 'email'];
|
|
53
|
+
}
|
|
54
|
+
if (['phone', 'tel', 'mobile', 'cell'].some((needle) => combined.includes(needle))) {
|
|
55
|
+
return ['phone', 'phone'];
|
|
56
|
+
}
|
|
57
|
+
if (combined.includes('first') && combined.includes('name')) {
|
|
58
|
+
return ['first_name', null];
|
|
59
|
+
}
|
|
60
|
+
if (combined.includes('last') && combined.includes('name')) {
|
|
61
|
+
return ['last_name', null];
|
|
62
|
+
}
|
|
63
|
+
if (combined.includes('full') && combined.includes('name')) {
|
|
64
|
+
return ['full_name', null];
|
|
65
|
+
}
|
|
66
|
+
if (combined.includes('name')) {
|
|
67
|
+
return ['name', null];
|
|
68
|
+
}
|
|
69
|
+
if (['date', 'dob', 'birth'].some((needle) => combined.includes(needle))) {
|
|
70
|
+
return ['date', 'date'];
|
|
71
|
+
}
|
|
72
|
+
if (combined.includes('city'))
|
|
73
|
+
return ['city', null];
|
|
74
|
+
if (combined.includes('state') || combined.includes('province')) {
|
|
75
|
+
return ['state', null];
|
|
76
|
+
}
|
|
77
|
+
if (combined.includes('country'))
|
|
78
|
+
return ['country', null];
|
|
79
|
+
if (['zip', 'postal', 'postcode'].some((needle) => combined.includes(needle))) {
|
|
80
|
+
return ['zip_code', 'postal_code'];
|
|
81
|
+
}
|
|
82
|
+
if (combined.includes('company') || combined.includes('organization')) {
|
|
83
|
+
return ['company', null];
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
};
|
|
87
|
+
const detectFromValuePattern = (value) => {
|
|
88
|
+
if (/^[\w.-]+@[\w.-]+\.\w+$/.test(value)) {
|
|
89
|
+
return ['email', 'email'];
|
|
90
|
+
}
|
|
91
|
+
if (/^[\d\s\-()+]+$/.test(value)) {
|
|
92
|
+
const digitsOnly = value.replace(/[\s\-()+]/g, '');
|
|
93
|
+
if (digitsOnly.length >= 10) {
|
|
94
|
+
return ['phone', 'phone'];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
98
|
+
return ['date', 'date'];
|
|
99
|
+
}
|
|
100
|
+
const stripped = value.replace(/[\s-]/g, '');
|
|
101
|
+
if (value.length >= 2 &&
|
|
102
|
+
value.length <= 30 &&
|
|
103
|
+
value[0] === value[0].toUpperCase() &&
|
|
104
|
+
/^[A-Za-z]+$/.test(stripped)) {
|
|
105
|
+
const words = value.trim().split(/\s+/);
|
|
106
|
+
if (words.length === 1)
|
|
107
|
+
return ['first_name', null];
|
|
108
|
+
if (words.length === 2)
|
|
109
|
+
return ['full_name', null];
|
|
110
|
+
return ['name', null];
|
|
111
|
+
}
|
|
112
|
+
if (/^\d{1,9}$/.test(value)) {
|
|
113
|
+
return ['number', 'number'];
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
};
|
|
117
|
+
const detectVariableType = (value, element) => {
|
|
118
|
+
const attrs = element?.attributes;
|
|
119
|
+
if (attrs && typeof attrs === 'object') {
|
|
120
|
+
const normalizedAttrs = Object.fromEntries(Object.entries(attrs).map(([key, attrValue]) => [key, String(attrValue)]));
|
|
121
|
+
const attrMatch = detectFromAttributes(normalizedAttrs);
|
|
122
|
+
if (attrMatch) {
|
|
123
|
+
return attrMatch;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return detectFromValuePattern(value);
|
|
127
|
+
};
|
|
128
|
+
const detectInAction = (actionPayload, element, detected, detectedValues) => {
|
|
129
|
+
for (const params of Object.values(actionPayload)) {
|
|
130
|
+
if (!params || typeof params !== 'object' || Array.isArray(params)) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
for (const field of ACTION_FIELDS_TO_CHECK) {
|
|
134
|
+
const value = params[field];
|
|
135
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (detectedValues.has(value)) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const variableInfo = detectVariableType(value, element);
|
|
142
|
+
if (!variableInfo) {
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const [baseName, format] = variableInfo;
|
|
146
|
+
const uniqueName = ensureUniqueName(baseName, detected);
|
|
147
|
+
detected[uniqueName] = new DetectedVariableModel(uniqueName, value, 'string', format);
|
|
148
|
+
detectedValues.add(value);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
export const detect_variables_in_history = (history) => {
|
|
153
|
+
const detected = {};
|
|
154
|
+
const detectedValues = new Set();
|
|
155
|
+
const historyItems = Array.isArray(history?.history)
|
|
156
|
+
? history.history
|
|
157
|
+
: [];
|
|
158
|
+
for (const historyItem of historyItems) {
|
|
159
|
+
const actions = historyItem?.model_output?.action;
|
|
160
|
+
if (!Array.isArray(actions)) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const interactedElements = Array.isArray(historyItem?.state?.interacted_element)
|
|
164
|
+
? historyItem.state.interacted_element
|
|
165
|
+
: [];
|
|
166
|
+
for (let actionIndex = 0; actionIndex < actions.length; actionIndex += 1) {
|
|
167
|
+
const actionPayload = getActionPayload(actions[actionIndex]);
|
|
168
|
+
const element = interactedElements[actionIndex] ?? null;
|
|
169
|
+
detectInAction(actionPayload, element, detected, detectedValues);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return detected;
|
|
173
|
+
};
|
|
174
|
+
export const substitute_in_dict = (data, replacements) => {
|
|
175
|
+
let count = 0;
|
|
176
|
+
for (const [key, value] of Object.entries(data)) {
|
|
177
|
+
if (typeof value === 'string') {
|
|
178
|
+
if (value in replacements) {
|
|
179
|
+
data[key] = replacements[value];
|
|
180
|
+
count += 1;
|
|
181
|
+
}
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
185
|
+
count += substitute_in_dict(value, replacements);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (Array.isArray(value)) {
|
|
189
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
190
|
+
const item = value[index];
|
|
191
|
+
if (typeof item === 'string') {
|
|
192
|
+
if (item in replacements) {
|
|
193
|
+
value[index] = replacements[item];
|
|
194
|
+
count += 1;
|
|
195
|
+
}
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (item && typeof item === 'object' && !Array.isArray(item)) {
|
|
199
|
+
count += substitute_in_dict(item, replacements);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return count;
|
|
205
|
+
};
|
|
206
|
+
export const _private_for_tests = {
|
|
207
|
+
detectFromAttributes,
|
|
208
|
+
detectFromValuePattern,
|
|
209
|
+
detectVariableType,
|
|
210
|
+
ensureUniqueName,
|
|
211
|
+
};
|