@web-auto/camo 0.2.0 → 0.2.2

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.
Files changed (114) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +586 -586
  3. package/bin/browser-service.mjs +11 -11
  4. package/bin/camo.mjs +22 -22
  5. package/package.json +48 -48
  6. package/scripts/build.mjs +19 -19
  7. package/scripts/bump-version.mjs +34 -34
  8. package/scripts/check-file-size.mjs +80 -80
  9. package/scripts/file-size-policy.json +12 -2
  10. package/scripts/install.mjs +76 -76
  11. package/scripts/release.sh +54 -54
  12. package/src/autoscript/action-providers/index.mjs +6 -6
  13. package/src/autoscript/impact-engine.mjs +78 -78
  14. package/src/autoscript/runtime.mjs +1017 -1017
  15. package/src/autoscript/schema.mjs +376 -376
  16. package/src/cli.mjs +405 -405
  17. package/src/commands/attach.mjs +141 -141
  18. package/src/commands/autoscript.mjs +1011 -1011
  19. package/src/commands/browser.mjs +1255 -1255
  20. package/src/commands/container.mjs +401 -401
  21. package/src/commands/cookies.mjs +69 -69
  22. package/src/commands/create.mjs +98 -98
  23. package/src/commands/devtools.mjs +349 -349
  24. package/src/commands/events.mjs +152 -152
  25. package/src/commands/highlight-mode.mjs +24 -24
  26. package/src/commands/init.mjs +68 -68
  27. package/src/commands/lifecycle.mjs +275 -275
  28. package/src/commands/mouse.mjs +45 -45
  29. package/src/commands/profile.mjs +46 -46
  30. package/src/commands/record.mjs +115 -115
  31. package/src/commands/system.mjs +14 -14
  32. package/src/commands/window.mjs +123 -123
  33. package/src/container/change-notifier.mjs +362 -362
  34. package/src/container/element-filter.mjs +143 -143
  35. package/src/container/index.mjs +3 -3
  36. package/src/container/runtime-core/checkpoint.mjs +209 -209
  37. package/src/container/runtime-core/index.mjs +21 -21
  38. package/src/container/runtime-core/operations/index.mjs +774 -774
  39. package/src/container/runtime-core/operations/selector-scripts.mjs +277 -277
  40. package/src/container/runtime-core/operations/tab-pool.mjs +746 -746
  41. package/src/container/runtime-core/operations/viewport.mjs +189 -189
  42. package/src/container/runtime-core/search.mjs +190 -190
  43. package/src/container/runtime-core/subscription.mjs +224 -224
  44. package/src/container/runtime-core/utils.mjs +94 -94
  45. package/src/container/runtime-core/validation.mjs +127 -127
  46. package/src/container/runtime-core.mjs +1 -1
  47. package/src/container/subscription-registry.mjs +459 -459
  48. package/src/core/actions.mjs +561 -561
  49. package/src/core/browser.mjs +266 -266
  50. package/src/core/index.mjs +52 -52
  51. package/src/core/utils.mjs +91 -91
  52. package/src/events/daemon-entry.mjs +33 -33
  53. package/src/events/daemon.mjs +80 -80
  54. package/src/events/progress-log.mjs +109 -109
  55. package/src/events/ws-server.mjs +239 -239
  56. package/src/lib/client.mjs +200 -200
  57. package/src/lifecycle/cleanup.mjs +83 -83
  58. package/src/lifecycle/lock.mjs +126 -126
  59. package/src/lifecycle/session-registry.mjs +279 -279
  60. package/src/lifecycle/session-view.mjs +76 -76
  61. package/src/lifecycle/session-watchdog.mjs +281 -281
  62. package/src/services/browser-service/index.js +671 -671
  63. package/src/services/browser-service/internal/BrowserSession.input.test.js +389 -389
  64. package/src/services/browser-service/internal/BrowserSession.js +325 -304
  65. package/src/services/browser-service/internal/ElementRegistry.js +60 -60
  66. package/src/services/browser-service/internal/ProfileLock.js +84 -84
  67. package/src/services/browser-service/internal/SessionManager.js +184 -184
  68. package/src/services/browser-service/internal/SessionManager.test.js +39 -39
  69. package/src/services/browser-service/internal/browser-session/cookies.js +144 -144
  70. package/src/services/browser-service/internal/browser-session/input-ops.js +222 -222
  71. package/src/services/browser-service/internal/browser-session/input-pipeline.js +144 -144
  72. package/src/services/browser-service/internal/browser-session/logging.js +46 -46
  73. package/src/services/browser-service/internal/browser-session/navigation.js +38 -38
  74. package/src/services/browser-service/internal/browser-session/page-hooks.js +442 -442
  75. package/src/services/browser-service/internal/browser-session/page-management.js +302 -302
  76. package/src/services/browser-service/internal/browser-session/page-management.test.js +148 -148
  77. package/src/services/browser-service/internal/browser-session/recording.js +198 -198
  78. package/src/services/browser-service/internal/browser-session/runtime-events.js +61 -61
  79. package/src/services/browser-service/internal/browser-session/session-core.js +84 -84
  80. package/src/services/browser-service/internal/browser-session/session-state.js +38 -38
  81. package/src/services/browser-service/internal/browser-session/types.js +14 -14
  82. package/src/services/browser-service/internal/browser-session/utils.js +95 -95
  83. package/src/services/browser-service/internal/browser-session/viewport-manager.js +46 -46
  84. package/src/services/browser-service/internal/browser-session/viewport.js +215 -215
  85. package/src/services/browser-service/internal/container-matcher.js +851 -851
  86. package/src/services/browser-service/internal/container-registry.js +182 -182
  87. package/src/services/browser-service/internal/engine-manager.js +259 -259
  88. package/src/services/browser-service/internal/fingerprint.js +203 -203
  89. package/src/services/browser-service/internal/heartbeat.js +137 -137
  90. package/src/services/browser-service/internal/logging.js +46 -46
  91. package/src/services/browser-service/internal/page-runtime/runtime.js +1317 -1317
  92. package/src/services/browser-service/internal/pageRuntime.js +28 -28
  93. package/src/services/browser-service/internal/runtimeInjector.js +31 -31
  94. package/src/services/browser-service/internal/service-process-logger.js +140 -140
  95. package/src/services/browser-service/internal/state-bus.js +45 -45
  96. package/src/services/browser-service/internal/storage-paths.js +42 -42
  97. package/src/services/browser-service/internal/ws-server.js +1194 -1194
  98. package/src/services/browser-service/internal/ws-server.test.js +58 -58
  99. package/src/services/browser-service/server.mjs +6 -6
  100. package/src/services/controller/cli-bridge.js +93 -93
  101. package/src/services/controller/container-index.js +50 -50
  102. package/src/services/controller/container-storage.js +36 -36
  103. package/src/services/controller/controller-actions.js +207 -207
  104. package/src/services/controller/controller.js +1138 -1138
  105. package/src/services/controller/selectors.js +54 -54
  106. package/src/services/controller/transport.js +125 -125
  107. package/src/utils/args.mjs +26 -26
  108. package/src/utils/browser-service.mjs +544 -544
  109. package/src/utils/command-log.mjs +64 -64
  110. package/src/utils/config.mjs +214 -214
  111. package/src/utils/fingerprint.mjs +181 -181
  112. package/src/utils/help.mjs +216 -216
  113. package/src/utils/js-policy.mjs +13 -13
  114. package/src/utils/ws-client.mjs +30 -30
@@ -1,190 +1,190 @@
1
- import { buildSelectorCheck } from './utils.mjs';
2
-
3
- function normalizeQuery(raw) {
4
- const text = String(raw || '').trim();
5
- if (!text) return { query: '', queryLower: '' };
6
- return { query: text, queryLower: text.toLowerCase() };
7
- }
8
-
9
- function normalizeDirection(raw) {
10
- const text = String(raw || 'down').trim().toLowerCase();
11
- if (text === 'up' || text === 'down' || text === 'both') return text;
12
- return 'down';
13
- }
14
-
15
- function normalizeLimit(raw) {
16
- const num = Number(raw);
17
- if (!Number.isFinite(num) || num <= 0) return 1;
18
- return Math.max(1, Math.floor(num));
19
- }
20
-
21
- function normalizeRect(node) {
22
- const rect = node?.rect && typeof node.rect === 'object' ? node.rect : null;
23
- if (!rect) return null;
24
- const left = Number(rect.left ?? rect.x ?? 0);
25
- const top = Number(rect.top ?? rect.y ?? 0);
26
- const width = Number(rect.width ?? 0);
27
- const height = Number(rect.height ?? 0);
28
- if (!Number.isFinite(left) || !Number.isFinite(top) || !Number.isFinite(width) || !Number.isFinite(height)) return null;
29
- if (width <= 0 || height <= 0) return null;
30
- return { left, top, width, height, right: left + width, bottom: top + height };
31
- }
32
-
33
- function computeCenter(rect) {
34
- if (!rect) return null;
35
- return {
36
- x: Math.round(rect.left + rect.width / 2),
37
- y: Math.round(rect.top + rect.height / 2),
38
- };
39
- }
40
-
41
- function buildSearchText(node) {
42
- if (!node || typeof node !== 'object') return '';
43
- const parts = [];
44
- const snippet = typeof node.textSnippet === 'string' ? node.textSnippet : '';
45
- if (snippet) parts.push(snippet);
46
- const attrs = node.attrs && typeof node.attrs === 'object' ? node.attrs : null;
47
- if (attrs) {
48
- const candidates = [
49
- attrs['aria-label'],
50
- attrs['aria-label'.toLowerCase()],
51
- attrs.title,
52
- attrs.alt,
53
- attrs.placeholder,
54
- ];
55
- for (const item of candidates) {
56
- const text = typeof item === 'string' ? item.trim() : '';
57
- if (text) parts.push(text);
58
- }
59
- }
60
- return parts.join(' ').replace(/\s+/g, ' ').trim();
61
- }
62
-
63
- function isPathWithin(path, parentPath) {
64
- const child = String(path || '').trim();
65
- const parent = String(parentPath || '').trim();
66
- if (!child || !parent) return false;
67
- return child === parent || child.startsWith(`${parent}/`);
68
- }
69
-
70
- function collectMatches(node, options, path = 'root', out = []) {
71
- if (!node) return out;
72
- const { queryLower, visibleOnly } = options;
73
- const visible = node.visible === true;
74
- if (visibleOnly && !visible) {
75
- return out;
76
- }
77
- {
78
- const searchText = buildSearchText(node);
79
- if (searchText && searchText.toLowerCase().includes(queryLower)) {
80
- out.push({ node, path, searchText });
81
- }
82
- }
83
- if (Array.isArray(node.children)) {
84
- for (let i = 0; i < node.children.length; i += 1) {
85
- collectMatches(node.children[i], options, `${path}/${i}`, out);
86
- }
87
- }
88
- return out;
89
- }
90
-
91
- function sortMatches(matches, direction) {
92
- const sorted = [...matches].sort((a, b) => {
93
- const ra = normalizeRect(a.targetNode);
94
- const rb = normalizeRect(b.targetNode);
95
- const ta = ra ? ra.top : Number.POSITIVE_INFINITY;
96
- const tb = rb ? rb.top : Number.POSITIVE_INFINITY;
97
- if (ta !== tb) return ta - tb;
98
- const la = ra ? ra.left : Number.POSITIVE_INFINITY;
99
- const lb = rb ? rb.left : Number.POSITIVE_INFINITY;
100
- return la - lb;
101
- });
102
- if (direction === 'up') return sorted.reverse();
103
- return sorted;
104
- }
105
-
106
- function applyStartAfter(matches, startAfterPath) {
107
- if (!startAfterPath) return matches;
108
- const idx = matches.findIndex((item) => item.targetPath === startAfterPath || item.matchPath === startAfterPath);
109
- if (idx < 0) return matches;
110
- return matches.slice(idx + 1);
111
- }
112
-
113
- export function searchSnapshot(snapshot, rawOptions = {}) {
114
- const { query, queryLower } = normalizeQuery(rawOptions.query || rawOptions.keyword || rawOptions.text);
115
- if (!query) {
116
- return { ok: false, code: 'QUERY_REQUIRED', message: 'search requires query keyword', data: { query } };
117
- }
118
- const direction = normalizeDirection(rawOptions.direction || 'down');
119
- const limit = normalizeLimit(rawOptions.limit ?? rawOptions.maxResults ?? 1);
120
- const visibleOnly = rawOptions.visibleOnly !== false;
121
- const containerSelector = String(rawOptions.containerSelector || rawOptions.selector || '').trim() || null;
122
- const startAfterPath = String(rawOptions.startAfterPath || rawOptions.afterPath || '').trim() || null;
123
-
124
- const containerNodes = containerSelector
125
- ? buildSelectorCheck(snapshot, { css: containerSelector, visible: visibleOnly })
126
- : [];
127
- const containerPaths = containerNodes.map((node) => node.path).filter(Boolean);
128
-
129
- const matches = collectMatches(snapshot, { queryLower, visibleOnly }, 'root', []);
130
- const enriched = matches.map((match) => {
131
- let containerNode = null;
132
- let containerPath = null;
133
- if (containerPaths.length > 0) {
134
- for (const path of containerPaths) {
135
- if (isPathWithin(match.path, path)) {
136
- containerPath = path;
137
- break;
138
- }
139
- }
140
- if (containerPath) {
141
- containerNode = containerNodes.find((node) => node.path === containerPath) || null;
142
- }
143
- }
144
- const targetNode = containerNode || match.node;
145
- const rect = normalizeRect(targetNode);
146
- const center = computeCenter(rect);
147
- return {
148
- matchPath: match.path,
149
- targetPath: containerPath || match.path,
150
- targetNode,
151
- matchNode: match.node,
152
- containerPath,
153
- rect,
154
- center,
155
- searchText: match.searchText,
156
- };
157
- });
158
-
159
- const filtered = containerSelector
160
- ? enriched.filter((item) => item.containerPath)
161
- : enriched;
162
- const ordered = sortMatches(filtered, direction);
163
- const sliced = applyStartAfter(ordered, startAfterPath).slice(0, limit);
164
- const results = sliced.map((item) => ({
165
- matchPath: item.matchPath,
166
- targetPath: item.targetPath,
167
- containerPath: item.containerPath,
168
- rect: item.rect,
169
- center: item.center,
170
- text: item.searchText,
171
- }));
172
- const nextCursor = results.length > 0 ? results[results.length - 1].targetPath : startAfterPath;
173
-
174
- return {
175
- ok: true,
176
- code: 'SEARCH_OK',
177
- message: 'search done',
178
- data: {
179
- query,
180
- direction,
181
- limit,
182
- visibleOnly,
183
- containerSelector,
184
- totalMatches: filtered.length,
185
- returned: results.length,
186
- nextCursor,
187
- results,
188
- },
189
- };
190
- }
1
+ import { buildSelectorCheck } from './utils.mjs';
2
+
3
+ function normalizeQuery(raw) {
4
+ const text = String(raw || '').trim();
5
+ if (!text) return { query: '', queryLower: '' };
6
+ return { query: text, queryLower: text.toLowerCase() };
7
+ }
8
+
9
+ function normalizeDirection(raw) {
10
+ const text = String(raw || 'down').trim().toLowerCase();
11
+ if (text === 'up' || text === 'down' || text === 'both') return text;
12
+ return 'down';
13
+ }
14
+
15
+ function normalizeLimit(raw) {
16
+ const num = Number(raw);
17
+ if (!Number.isFinite(num) || num <= 0) return 1;
18
+ return Math.max(1, Math.floor(num));
19
+ }
20
+
21
+ function normalizeRect(node) {
22
+ const rect = node?.rect && typeof node.rect === 'object' ? node.rect : null;
23
+ if (!rect) return null;
24
+ const left = Number(rect.left ?? rect.x ?? 0);
25
+ const top = Number(rect.top ?? rect.y ?? 0);
26
+ const width = Number(rect.width ?? 0);
27
+ const height = Number(rect.height ?? 0);
28
+ if (!Number.isFinite(left) || !Number.isFinite(top) || !Number.isFinite(width) || !Number.isFinite(height)) return null;
29
+ if (width <= 0 || height <= 0) return null;
30
+ return { left, top, width, height, right: left + width, bottom: top + height };
31
+ }
32
+
33
+ function computeCenter(rect) {
34
+ if (!rect) return null;
35
+ return {
36
+ x: Math.round(rect.left + rect.width / 2),
37
+ y: Math.round(rect.top + rect.height / 2),
38
+ };
39
+ }
40
+
41
+ function buildSearchText(node) {
42
+ if (!node || typeof node !== 'object') return '';
43
+ const parts = [];
44
+ const snippet = typeof node.textSnippet === 'string' ? node.textSnippet : '';
45
+ if (snippet) parts.push(snippet);
46
+ const attrs = node.attrs && typeof node.attrs === 'object' ? node.attrs : null;
47
+ if (attrs) {
48
+ const candidates = [
49
+ attrs['aria-label'],
50
+ attrs['aria-label'.toLowerCase()],
51
+ attrs.title,
52
+ attrs.alt,
53
+ attrs.placeholder,
54
+ ];
55
+ for (const item of candidates) {
56
+ const text = typeof item === 'string' ? item.trim() : '';
57
+ if (text) parts.push(text);
58
+ }
59
+ }
60
+ return parts.join(' ').replace(/\s+/g, ' ').trim();
61
+ }
62
+
63
+ function isPathWithin(path, parentPath) {
64
+ const child = String(path || '').trim();
65
+ const parent = String(parentPath || '').trim();
66
+ if (!child || !parent) return false;
67
+ return child === parent || child.startsWith(`${parent}/`);
68
+ }
69
+
70
+ function collectMatches(node, options, path = 'root', out = []) {
71
+ if (!node) return out;
72
+ const { queryLower, visibleOnly } = options;
73
+ const visible = node.visible === true;
74
+ if (visibleOnly && !visible) {
75
+ return out;
76
+ }
77
+ {
78
+ const searchText = buildSearchText(node);
79
+ if (searchText && searchText.toLowerCase().includes(queryLower)) {
80
+ out.push({ node, path, searchText });
81
+ }
82
+ }
83
+ if (Array.isArray(node.children)) {
84
+ for (let i = 0; i < node.children.length; i += 1) {
85
+ collectMatches(node.children[i], options, `${path}/${i}`, out);
86
+ }
87
+ }
88
+ return out;
89
+ }
90
+
91
+ function sortMatches(matches, direction) {
92
+ const sorted = [...matches].sort((a, b) => {
93
+ const ra = normalizeRect(a.targetNode);
94
+ const rb = normalizeRect(b.targetNode);
95
+ const ta = ra ? ra.top : Number.POSITIVE_INFINITY;
96
+ const tb = rb ? rb.top : Number.POSITIVE_INFINITY;
97
+ if (ta !== tb) return ta - tb;
98
+ const la = ra ? ra.left : Number.POSITIVE_INFINITY;
99
+ const lb = rb ? rb.left : Number.POSITIVE_INFINITY;
100
+ return la - lb;
101
+ });
102
+ if (direction === 'up') return sorted.reverse();
103
+ return sorted;
104
+ }
105
+
106
+ function applyStartAfter(matches, startAfterPath) {
107
+ if (!startAfterPath) return matches;
108
+ const idx = matches.findIndex((item) => item.targetPath === startAfterPath || item.matchPath === startAfterPath);
109
+ if (idx < 0) return matches;
110
+ return matches.slice(idx + 1);
111
+ }
112
+
113
+ export function searchSnapshot(snapshot, rawOptions = {}) {
114
+ const { query, queryLower } = normalizeQuery(rawOptions.query || rawOptions.keyword || rawOptions.text);
115
+ if (!query) {
116
+ return { ok: false, code: 'QUERY_REQUIRED', message: 'search requires query keyword', data: { query } };
117
+ }
118
+ const direction = normalizeDirection(rawOptions.direction || 'down');
119
+ const limit = normalizeLimit(rawOptions.limit ?? rawOptions.maxResults ?? 1);
120
+ const visibleOnly = rawOptions.visibleOnly !== false;
121
+ const containerSelector = String(rawOptions.containerSelector || rawOptions.selector || '').trim() || null;
122
+ const startAfterPath = String(rawOptions.startAfterPath || rawOptions.afterPath || '').trim() || null;
123
+
124
+ const containerNodes = containerSelector
125
+ ? buildSelectorCheck(snapshot, { css: containerSelector, visible: visibleOnly })
126
+ : [];
127
+ const containerPaths = containerNodes.map((node) => node.path).filter(Boolean);
128
+
129
+ const matches = collectMatches(snapshot, { queryLower, visibleOnly }, 'root', []);
130
+ const enriched = matches.map((match) => {
131
+ let containerNode = null;
132
+ let containerPath = null;
133
+ if (containerPaths.length > 0) {
134
+ for (const path of containerPaths) {
135
+ if (isPathWithin(match.path, path)) {
136
+ containerPath = path;
137
+ break;
138
+ }
139
+ }
140
+ if (containerPath) {
141
+ containerNode = containerNodes.find((node) => node.path === containerPath) || null;
142
+ }
143
+ }
144
+ const targetNode = containerNode || match.node;
145
+ const rect = normalizeRect(targetNode);
146
+ const center = computeCenter(rect);
147
+ return {
148
+ matchPath: match.path,
149
+ targetPath: containerPath || match.path,
150
+ targetNode,
151
+ matchNode: match.node,
152
+ containerPath,
153
+ rect,
154
+ center,
155
+ searchText: match.searchText,
156
+ };
157
+ });
158
+
159
+ const filtered = containerSelector
160
+ ? enriched.filter((item) => item.containerPath)
161
+ : enriched;
162
+ const ordered = sortMatches(filtered, direction);
163
+ const sliced = applyStartAfter(ordered, startAfterPath).slice(0, limit);
164
+ const results = sliced.map((item) => ({
165
+ matchPath: item.matchPath,
166
+ targetPath: item.targetPath,
167
+ containerPath: item.containerPath,
168
+ rect: item.rect,
169
+ center: item.center,
170
+ text: item.searchText,
171
+ }));
172
+ const nextCursor = results.length > 0 ? results[results.length - 1].targetPath : startAfterPath;
173
+
174
+ return {
175
+ ok: true,
176
+ code: 'SEARCH_OK',
177
+ message: 'search done',
178
+ data: {
179
+ query,
180
+ direction,
181
+ limit,
182
+ visibleOnly,
183
+ containerSelector,
184
+ totalMatches: filtered.length,
185
+ returned: results.length,
186
+ nextCursor,
187
+ results,
188
+ },
189
+ };
190
+ }