@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.
- package/LICENSE +21 -21
- package/README.md +586 -586
- package/bin/browser-service.mjs +11 -11
- package/bin/camo.mjs +22 -22
- package/package.json +48 -48
- package/scripts/build.mjs +19 -19
- package/scripts/bump-version.mjs +34 -34
- package/scripts/check-file-size.mjs +80 -80
- package/scripts/file-size-policy.json +12 -2
- package/scripts/install.mjs +76 -76
- package/scripts/release.sh +54 -54
- package/src/autoscript/action-providers/index.mjs +6 -6
- package/src/autoscript/impact-engine.mjs +78 -78
- package/src/autoscript/runtime.mjs +1017 -1017
- package/src/autoscript/schema.mjs +376 -376
- package/src/cli.mjs +405 -405
- package/src/commands/attach.mjs +141 -141
- package/src/commands/autoscript.mjs +1011 -1011
- package/src/commands/browser.mjs +1255 -1255
- package/src/commands/container.mjs +401 -401
- package/src/commands/cookies.mjs +69 -69
- package/src/commands/create.mjs +98 -98
- package/src/commands/devtools.mjs +349 -349
- package/src/commands/events.mjs +152 -152
- package/src/commands/highlight-mode.mjs +24 -24
- package/src/commands/init.mjs +68 -68
- package/src/commands/lifecycle.mjs +275 -275
- package/src/commands/mouse.mjs +45 -45
- package/src/commands/profile.mjs +46 -46
- package/src/commands/record.mjs +115 -115
- package/src/commands/system.mjs +14 -14
- package/src/commands/window.mjs +123 -123
- package/src/container/change-notifier.mjs +362 -362
- package/src/container/element-filter.mjs +143 -143
- package/src/container/index.mjs +3 -3
- package/src/container/runtime-core/checkpoint.mjs +209 -209
- package/src/container/runtime-core/index.mjs +21 -21
- package/src/container/runtime-core/operations/index.mjs +774 -774
- package/src/container/runtime-core/operations/selector-scripts.mjs +277 -277
- package/src/container/runtime-core/operations/tab-pool.mjs +746 -746
- package/src/container/runtime-core/operations/viewport.mjs +189 -189
- package/src/container/runtime-core/search.mjs +190 -190
- package/src/container/runtime-core/subscription.mjs +224 -224
- package/src/container/runtime-core/utils.mjs +94 -94
- package/src/container/runtime-core/validation.mjs +127 -127
- package/src/container/runtime-core.mjs +1 -1
- package/src/container/subscription-registry.mjs +459 -459
- package/src/core/actions.mjs +561 -561
- package/src/core/browser.mjs +266 -266
- package/src/core/index.mjs +52 -52
- package/src/core/utils.mjs +91 -91
- package/src/events/daemon-entry.mjs +33 -33
- package/src/events/daemon.mjs +80 -80
- package/src/events/progress-log.mjs +109 -109
- package/src/events/ws-server.mjs +239 -239
- package/src/lib/client.mjs +200 -200
- package/src/lifecycle/cleanup.mjs +83 -83
- package/src/lifecycle/lock.mjs +126 -126
- package/src/lifecycle/session-registry.mjs +279 -279
- package/src/lifecycle/session-view.mjs +76 -76
- package/src/lifecycle/session-watchdog.mjs +281 -281
- package/src/services/browser-service/index.js +671 -671
- package/src/services/browser-service/internal/BrowserSession.input.test.js +389 -389
- package/src/services/browser-service/internal/BrowserSession.js +325 -304
- package/src/services/browser-service/internal/ElementRegistry.js +60 -60
- package/src/services/browser-service/internal/ProfileLock.js +84 -84
- package/src/services/browser-service/internal/SessionManager.js +184 -184
- package/src/services/browser-service/internal/SessionManager.test.js +39 -39
- package/src/services/browser-service/internal/browser-session/cookies.js +144 -144
- package/src/services/browser-service/internal/browser-session/input-ops.js +222 -222
- package/src/services/browser-service/internal/browser-session/input-pipeline.js +144 -144
- package/src/services/browser-service/internal/browser-session/logging.js +46 -46
- package/src/services/browser-service/internal/browser-session/navigation.js +38 -38
- package/src/services/browser-service/internal/browser-session/page-hooks.js +442 -442
- package/src/services/browser-service/internal/browser-session/page-management.js +302 -302
- package/src/services/browser-service/internal/browser-session/page-management.test.js +148 -148
- package/src/services/browser-service/internal/browser-session/recording.js +198 -198
- package/src/services/browser-service/internal/browser-session/runtime-events.js +61 -61
- package/src/services/browser-service/internal/browser-session/session-core.js +84 -84
- package/src/services/browser-service/internal/browser-session/session-state.js +38 -38
- package/src/services/browser-service/internal/browser-session/types.js +14 -14
- package/src/services/browser-service/internal/browser-session/utils.js +95 -95
- package/src/services/browser-service/internal/browser-session/viewport-manager.js +46 -46
- package/src/services/browser-service/internal/browser-session/viewport.js +215 -215
- package/src/services/browser-service/internal/container-matcher.js +851 -851
- package/src/services/browser-service/internal/container-registry.js +182 -182
- package/src/services/browser-service/internal/engine-manager.js +259 -259
- package/src/services/browser-service/internal/fingerprint.js +203 -203
- package/src/services/browser-service/internal/heartbeat.js +137 -137
- package/src/services/browser-service/internal/logging.js +46 -46
- package/src/services/browser-service/internal/page-runtime/runtime.js +1317 -1317
- package/src/services/browser-service/internal/pageRuntime.js +28 -28
- package/src/services/browser-service/internal/runtimeInjector.js +31 -31
- package/src/services/browser-service/internal/service-process-logger.js +140 -140
- package/src/services/browser-service/internal/state-bus.js +45 -45
- package/src/services/browser-service/internal/storage-paths.js +42 -42
- package/src/services/browser-service/internal/ws-server.js +1194 -1194
- package/src/services/browser-service/internal/ws-server.test.js +58 -58
- package/src/services/browser-service/server.mjs +6 -6
- package/src/services/controller/cli-bridge.js +93 -93
- package/src/services/controller/container-index.js +50 -50
- package/src/services/controller/container-storage.js +36 -36
- package/src/services/controller/controller-actions.js +207 -207
- package/src/services/controller/controller.js +1138 -1138
- package/src/services/controller/selectors.js +54 -54
- package/src/services/controller/transport.js +125 -125
- package/src/utils/args.mjs +26 -26
- package/src/utils/browser-service.mjs +544 -544
- package/src/utils/command-log.mjs +64 -64
- package/src/utils/config.mjs +214 -214
- package/src/utils/fingerprint.mjs +181 -181
- package/src/utils/help.mjs +216 -216
- package/src/utils/js-policy.mjs +13 -13
- package/src/utils/ws-client.mjs +30 -30
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
import { getDomSnapshotByProfile } from '../../utils/browser-service.mjs';
|
|
2
|
-
import { detectCheckpoint } from './checkpoint.mjs';
|
|
3
|
-
import {
|
|
4
|
-
asErrorPayload,
|
|
5
|
-
buildSelectorCheck,
|
|
6
|
-
ensureActiveSession,
|
|
7
|
-
getCurrentUrl,
|
|
8
|
-
maybeSelector,
|
|
9
|
-
normalizeArray,
|
|
10
|
-
} from './utils.mjs';
|
|
11
|
-
|
|
12
|
-
async function validatePage(profileId, spec = {}, platform = 'generic') {
|
|
13
|
-
const url = await getCurrentUrl(profileId);
|
|
14
|
-
const includes = normalizeArray(spec.urlIncludes || []);
|
|
15
|
-
const excludes = normalizeArray(spec.urlExcludes || []);
|
|
16
|
-
const hostIncludes = normalizeArray(spec.hostIncludes || []);
|
|
17
|
-
const errors = [];
|
|
18
|
-
|
|
19
|
-
for (const token of includes) {
|
|
20
|
-
if (!url.includes(String(token))) errors.push(`url missing token: ${token}`);
|
|
21
|
-
}
|
|
22
|
-
for (const token of excludes) {
|
|
23
|
-
if (url.includes(String(token))) errors.push(`url contains forbidden token: ${token}`);
|
|
24
|
-
}
|
|
25
|
-
if (hostIncludes.length > 0 && !hostIncludes.some((token) => url.includes(String(token)))) {
|
|
26
|
-
errors.push(`url host mismatch, expected one of: ${hostIncludes.join(',')}`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const checkpoints = normalizeArray(spec.checkpointIn || []);
|
|
30
|
-
let checkpoint = null;
|
|
31
|
-
if (checkpoints.length > 0) {
|
|
32
|
-
const detected = await detectCheckpoint({ profileId, platform });
|
|
33
|
-
checkpoint = detected?.data?.checkpoint || null;
|
|
34
|
-
if (!checkpoints.includes(checkpoint)) {
|
|
35
|
-
errors.push(`checkpoint mismatch: got ${checkpoint}, expect one of ${checkpoints.join(',')}`);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
ok: errors.length === 0,
|
|
41
|
-
url,
|
|
42
|
-
checkpoint,
|
|
43
|
-
errors,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async function validateContainer(profileId, spec = {}) {
|
|
48
|
-
const snapshot = await getDomSnapshotByProfile(profileId);
|
|
49
|
-
const selector = maybeSelector({
|
|
50
|
-
profileId,
|
|
51
|
-
containerId: spec.containerId || null,
|
|
52
|
-
selector: spec.selector || null,
|
|
53
|
-
});
|
|
54
|
-
if (!selector) {
|
|
55
|
-
return { ok: false, selector: null, count: 0, errors: ['container selector not resolved'] };
|
|
56
|
-
}
|
|
57
|
-
const matched = buildSelectorCheck(snapshot, selector);
|
|
58
|
-
const count = matched.length;
|
|
59
|
-
const mustExist = spec.mustExist !== false;
|
|
60
|
-
const minCount = Number.isFinite(Number(spec.minCount)) ? Number(spec.minCount) : (mustExist ? 1 : 0);
|
|
61
|
-
const maxCount = Number.isFinite(Number(spec.maxCount)) ? Number(spec.maxCount) : null;
|
|
62
|
-
const errors = [];
|
|
63
|
-
|
|
64
|
-
if (count < minCount) errors.push(`container count too small: ${count} < ${minCount}`);
|
|
65
|
-
if (maxCount !== null && count > maxCount) errors.push(`container count too large: ${count} > ${maxCount}`);
|
|
66
|
-
if (!mustExist && minCount === 0) {
|
|
67
|
-
return { ok: true, selector, count, errors: [] };
|
|
68
|
-
}
|
|
69
|
-
return { ok: errors.length === 0, selector, count, errors };
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export async function validateOperation({
|
|
73
|
-
profileId,
|
|
74
|
-
validationSpec = {},
|
|
75
|
-
phase = 'pre',
|
|
76
|
-
context = {},
|
|
77
|
-
platform = 'generic',
|
|
78
|
-
}) {
|
|
79
|
-
try {
|
|
80
|
-
const mode = String(validationSpec.mode || 'none').toLowerCase();
|
|
81
|
-
if (mode === 'none') {
|
|
82
|
-
return { ok: true, code: 'VALIDATION_SKIPPED', message: 'Validation skipped', data: { phase, mode } };
|
|
83
|
-
}
|
|
84
|
-
if (phase === 'pre' && mode === 'post') {
|
|
85
|
-
return { ok: true, code: 'VALIDATION_SKIPPED', message: 'Pre validation skipped by mode=post', data: { phase, mode } };
|
|
86
|
-
}
|
|
87
|
-
if (phase === 'post' && mode === 'pre') {
|
|
88
|
-
return { ok: true, code: 'VALIDATION_SKIPPED', message: 'Post validation skipped by mode=pre', data: { phase, mode } };
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const effective = validationSpec[phase] || {};
|
|
92
|
-
const resolvedProfile = (await ensureActiveSession(profileId)).profileId || profileId;
|
|
93
|
-
const pageResult = effective.page
|
|
94
|
-
? await validatePage(resolvedProfile, effective.page, platform)
|
|
95
|
-
: { ok: true, errors: [] };
|
|
96
|
-
const containerResult = effective.container
|
|
97
|
-
? await validateContainer(resolvedProfile, effective.container)
|
|
98
|
-
: { ok: true, errors: [] };
|
|
99
|
-
const allErrors = [...normalizeArray(pageResult.errors), ...normalizeArray(containerResult.errors)];
|
|
100
|
-
|
|
101
|
-
if (allErrors.length > 0) {
|
|
102
|
-
return asErrorPayload('VALIDATION_FAILED', `Validation failed at phase=${phase}`, {
|
|
103
|
-
phase,
|
|
104
|
-
mode,
|
|
105
|
-
errors: allErrors,
|
|
106
|
-
page: pageResult,
|
|
107
|
-
container: containerResult,
|
|
108
|
-
context,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
ok: true,
|
|
114
|
-
code: 'VALIDATION_PASSED',
|
|
115
|
-
message: `Validation passed at phase=${phase}`,
|
|
116
|
-
data: {
|
|
117
|
-
phase,
|
|
118
|
-
mode,
|
|
119
|
-
page: pageResult,
|
|
120
|
-
container: containerResult,
|
|
121
|
-
context,
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
} catch (err) {
|
|
125
|
-
return asErrorPayload('VALIDATION_FAILED', err?.message || String(err), { phase, context });
|
|
126
|
-
}
|
|
127
|
-
}
|
|
1
|
+
import { getDomSnapshotByProfile } from '../../utils/browser-service.mjs';
|
|
2
|
+
import { detectCheckpoint } from './checkpoint.mjs';
|
|
3
|
+
import {
|
|
4
|
+
asErrorPayload,
|
|
5
|
+
buildSelectorCheck,
|
|
6
|
+
ensureActiveSession,
|
|
7
|
+
getCurrentUrl,
|
|
8
|
+
maybeSelector,
|
|
9
|
+
normalizeArray,
|
|
10
|
+
} from './utils.mjs';
|
|
11
|
+
|
|
12
|
+
async function validatePage(profileId, spec = {}, platform = 'generic') {
|
|
13
|
+
const url = await getCurrentUrl(profileId);
|
|
14
|
+
const includes = normalizeArray(spec.urlIncludes || []);
|
|
15
|
+
const excludes = normalizeArray(spec.urlExcludes || []);
|
|
16
|
+
const hostIncludes = normalizeArray(spec.hostIncludes || []);
|
|
17
|
+
const errors = [];
|
|
18
|
+
|
|
19
|
+
for (const token of includes) {
|
|
20
|
+
if (!url.includes(String(token))) errors.push(`url missing token: ${token}`);
|
|
21
|
+
}
|
|
22
|
+
for (const token of excludes) {
|
|
23
|
+
if (url.includes(String(token))) errors.push(`url contains forbidden token: ${token}`);
|
|
24
|
+
}
|
|
25
|
+
if (hostIncludes.length > 0 && !hostIncludes.some((token) => url.includes(String(token)))) {
|
|
26
|
+
errors.push(`url host mismatch, expected one of: ${hostIncludes.join(',')}`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const checkpoints = normalizeArray(spec.checkpointIn || []);
|
|
30
|
+
let checkpoint = null;
|
|
31
|
+
if (checkpoints.length > 0) {
|
|
32
|
+
const detected = await detectCheckpoint({ profileId, platform });
|
|
33
|
+
checkpoint = detected?.data?.checkpoint || null;
|
|
34
|
+
if (!checkpoints.includes(checkpoint)) {
|
|
35
|
+
errors.push(`checkpoint mismatch: got ${checkpoint}, expect one of ${checkpoints.join(',')}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
ok: errors.length === 0,
|
|
41
|
+
url,
|
|
42
|
+
checkpoint,
|
|
43
|
+
errors,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function validateContainer(profileId, spec = {}) {
|
|
48
|
+
const snapshot = await getDomSnapshotByProfile(profileId);
|
|
49
|
+
const selector = maybeSelector({
|
|
50
|
+
profileId,
|
|
51
|
+
containerId: spec.containerId || null,
|
|
52
|
+
selector: spec.selector || null,
|
|
53
|
+
});
|
|
54
|
+
if (!selector) {
|
|
55
|
+
return { ok: false, selector: null, count: 0, errors: ['container selector not resolved'] };
|
|
56
|
+
}
|
|
57
|
+
const matched = buildSelectorCheck(snapshot, selector);
|
|
58
|
+
const count = matched.length;
|
|
59
|
+
const mustExist = spec.mustExist !== false;
|
|
60
|
+
const minCount = Number.isFinite(Number(spec.minCount)) ? Number(spec.minCount) : (mustExist ? 1 : 0);
|
|
61
|
+
const maxCount = Number.isFinite(Number(spec.maxCount)) ? Number(spec.maxCount) : null;
|
|
62
|
+
const errors = [];
|
|
63
|
+
|
|
64
|
+
if (count < minCount) errors.push(`container count too small: ${count} < ${minCount}`);
|
|
65
|
+
if (maxCount !== null && count > maxCount) errors.push(`container count too large: ${count} > ${maxCount}`);
|
|
66
|
+
if (!mustExist && minCount === 0) {
|
|
67
|
+
return { ok: true, selector, count, errors: [] };
|
|
68
|
+
}
|
|
69
|
+
return { ok: errors.length === 0, selector, count, errors };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function validateOperation({
|
|
73
|
+
profileId,
|
|
74
|
+
validationSpec = {},
|
|
75
|
+
phase = 'pre',
|
|
76
|
+
context = {},
|
|
77
|
+
platform = 'generic',
|
|
78
|
+
}) {
|
|
79
|
+
try {
|
|
80
|
+
const mode = String(validationSpec.mode || 'none').toLowerCase();
|
|
81
|
+
if (mode === 'none') {
|
|
82
|
+
return { ok: true, code: 'VALIDATION_SKIPPED', message: 'Validation skipped', data: { phase, mode } };
|
|
83
|
+
}
|
|
84
|
+
if (phase === 'pre' && mode === 'post') {
|
|
85
|
+
return { ok: true, code: 'VALIDATION_SKIPPED', message: 'Pre validation skipped by mode=post', data: { phase, mode } };
|
|
86
|
+
}
|
|
87
|
+
if (phase === 'post' && mode === 'pre') {
|
|
88
|
+
return { ok: true, code: 'VALIDATION_SKIPPED', message: 'Post validation skipped by mode=pre', data: { phase, mode } };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const effective = validationSpec[phase] || {};
|
|
92
|
+
const resolvedProfile = (await ensureActiveSession(profileId)).profileId || profileId;
|
|
93
|
+
const pageResult = effective.page
|
|
94
|
+
? await validatePage(resolvedProfile, effective.page, platform)
|
|
95
|
+
: { ok: true, errors: [] };
|
|
96
|
+
const containerResult = effective.container
|
|
97
|
+
? await validateContainer(resolvedProfile, effective.container)
|
|
98
|
+
: { ok: true, errors: [] };
|
|
99
|
+
const allErrors = [...normalizeArray(pageResult.errors), ...normalizeArray(containerResult.errors)];
|
|
100
|
+
|
|
101
|
+
if (allErrors.length > 0) {
|
|
102
|
+
return asErrorPayload('VALIDATION_FAILED', `Validation failed at phase=${phase}`, {
|
|
103
|
+
phase,
|
|
104
|
+
mode,
|
|
105
|
+
errors: allErrors,
|
|
106
|
+
page: pageResult,
|
|
107
|
+
container: containerResult,
|
|
108
|
+
context,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
ok: true,
|
|
114
|
+
code: 'VALIDATION_PASSED',
|
|
115
|
+
message: `Validation passed at phase=${phase}`,
|
|
116
|
+
data: {
|
|
117
|
+
phase,
|
|
118
|
+
mode,
|
|
119
|
+
page: pageResult,
|
|
120
|
+
container: containerResult,
|
|
121
|
+
context,
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
} catch (err) {
|
|
125
|
+
return asErrorPayload('VALIDATION_FAILED', err?.message || String(err), { phase, context });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './runtime-core/index.mjs';
|
|
1
|
+
export * from './runtime-core/index.mjs';
|