dsh-chrome-bridge 2.0.3 → 2.1.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.en.md +1 -1
- package/README.md +1 -1
- package/core/ext.js +8 -1
- package/core/hosts.js +3 -4
- package/core/receipt.js +228 -31
- package/core/session.js +11 -14
- package/core/tooldef.js +10 -1
- package/core/transport.js +67 -17
- package/drag.js +10 -10
- package/features/frames.js +5 -2
- package/i18n/en.js +34 -7
- package/i18n/ru.js +34 -7
- package/i18n/zh.js +34 -7
- package/nav.js +103 -32
- package/package.json +1 -1
- package/refs.js +309 -73
- package/tools/batch.js +311 -0
- package/tools/click.js +37 -11
- package/tools/dialog.js +19 -2
- package/tools/drag.js +31 -5
- package/tools/fill.js +71 -22
- package/tools/index.js +3 -1
- package/tools/input.js +97 -36
- package/tools/nav.js +46 -23
- package/tools/read.js +2 -0
- package/tools/tabs.js +16 -2
- package/tools/wait.js +14 -6
- package/vendor/extension/in-page-cursor.js +1 -1
- package/vendor/extension/manifest.json +1 -1
- package/vendor/extension/popup.css +1 -0
- package/vendor/extension/popup.html +6 -3
- package/vendor/extension/popup.js +19 -13
- package/vendor/extension/sw/actions.js +573 -0
- package/vendor/extension/sw/boot.js +2 -1
- package/vendor/extension/sw/cdp.js +139 -11
- package/vendor/extension/sw/conditions.js +176 -0
- package/vendor/extension/sw/confirm.js +39 -7
- package/vendor/extension/sw/cursor.js +176 -14
- package/vendor/extension/sw/dispatch.js +6 -1
- package/vendor/extension/sw/frames.js +543 -47
- package/vendor/extension/sw/lifecycle.js +82 -0
- package/vendor/extension/sw/ops.js +801 -139
- package/vendor/extension/sw/page-access.js +292 -0
- package/vendor/extension/sw/popup-api.js +28 -7
- package/vendor/extension/sw/snapshot.js +251 -0
- package/vendor/extension/sw/state.js +16 -5
- package/vendor/extension/sw/tabui.js +9 -2
- package/vendor/in-page-cursor.js +1 -1
- package/vendor/skill/SKILL.md +8 -7
package/tools/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { t } from '../core/locale.js'
|
|
2
|
+
import { buildBatch } from './batch.js'
|
|
2
3
|
import { buildTabs } from './tabs.js'
|
|
3
4
|
import { buildRead } from './read.js'
|
|
4
5
|
import { buildClick } from './click.js'
|
|
@@ -18,7 +19,7 @@ import { buildRecord } from './record.js'
|
|
|
18
19
|
export function buildTools(deps) {
|
|
19
20
|
// 好几处参数说明共用这两段,按当前语言取一次。
|
|
20
21
|
const toolDeps = { ...deps, TAB: t('param.tab'), REF: t('param.ref') }
|
|
21
|
-
|
|
22
|
+
const tools = [
|
|
22
23
|
buildTabs(toolDeps),
|
|
23
24
|
buildRead(toolDeps),
|
|
24
25
|
buildClick(toolDeps),
|
|
@@ -35,4 +36,5 @@ export function buildTools(deps) {
|
|
|
35
36
|
buildDevtools(toolDeps),
|
|
36
37
|
buildRecord(toolDeps),
|
|
37
38
|
]
|
|
39
|
+
return [...tools, buildBatch(toolDeps, tools)]
|
|
38
40
|
}
|
package/tools/input.js
CHANGED
|
@@ -2,10 +2,11 @@ import { t } from '../core/locale.js'
|
|
|
2
2
|
import { call } from '../core/transport.js'
|
|
3
3
|
import { defineTool, present, textOutput } from '../core/tooldef.js'
|
|
4
4
|
import { recordAction, chooserKey, pruneEntries, chooserIds, CHOOSER_TTL, sessionCwd } from '../core/session.js'
|
|
5
|
-
import {
|
|
6
|
-
import { probeState,
|
|
5
|
+
import { hasCap, emulateFocus, withCursor } from '../core/ext.js'
|
|
6
|
+
import { probeState, finishAction, observeParam, performAct, inBatch } from '../core/receipt.js'
|
|
7
7
|
import { chooserNote, uploadable, uploadError } from '../core/upload.js'
|
|
8
|
-
import {
|
|
8
|
+
import { isFrameRef } from '../features/frames.js'
|
|
9
|
+
import { expectedDocId, locate, focusShadow, selectInPage, setField, scrollElement, staleRefHint } from '../refs.js'
|
|
9
10
|
|
|
10
11
|
export function buildInput({ resolveTab, TAB, REF }) {
|
|
11
12
|
return defineTool({
|
|
@@ -16,6 +17,9 @@ export function buildInput({ resolveTab, TAB, REF }) {
|
|
|
16
17
|
type: 'string', required: true, enum: ['type', 'fill', 'check', 'key', 'select', 'upload', 'focus', 'hover', 'scroll'],
|
|
17
18
|
description: t('tool.input.action'),
|
|
18
19
|
},
|
|
20
|
+
observe: observeParam(),
|
|
21
|
+
clear: { type: 'boolean', description: t('tool.input.clear') },
|
|
22
|
+
submit: { type: 'boolean', description: t('tool.input.submit') },
|
|
19
23
|
tab: { type: 'string', description: TAB },
|
|
20
24
|
text: { type: 'string', description: t('tool.input.text') },
|
|
21
25
|
ref: { type: 'integer', description: t('tool.input.ref', { ref: REF }) },
|
|
@@ -34,10 +38,73 @@ export function buildInput({ resolveTab, TAB, REF }) {
|
|
|
34
38
|
async execute(args, exec) {
|
|
35
39
|
const tabId = await resolveTab(args.tab)
|
|
36
40
|
recordAction(tabId)
|
|
37
|
-
|
|
38
|
-
if (args.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
const { action, ref, observe } = args
|
|
42
|
+
if (action === 'type' && typeof args.text !== 'string') throw new Error(t('err.typeNeedsText'))
|
|
43
|
+
if (action === 'key' && !args.key) throw new Error(t('err.keyNeedsKey'))
|
|
44
|
+
if (action === 'hover' && ref == null && !args.selector && (args.x === undefined || args.y === undefined)) {
|
|
45
|
+
throw new Error(t('err.hoverNeedsTarget'))
|
|
46
|
+
}
|
|
47
|
+
if (['type', 'hover', 'scroll'].includes(action) && ref != null && (!Number.isInteger(Number(ref)) || Number(ref) < 1)) {
|
|
48
|
+
throw new Error(t('err.refNotInt', { ref }))
|
|
49
|
+
}
|
|
50
|
+
const targetLabel = ref != null ? `[${ref}]` : args.selector
|
|
51
|
+
const typed = (r) => t('res.input.typed', { n: r.typed ?? args.text.length }) +
|
|
52
|
+
(targetLabel ? t('res.input.typedAfterFocus', { target: targetLabel }) : '') + chooserNote(r, tabId)
|
|
53
|
+
const hovered = (r) => t('res.input.hovered', { x: r.x, y: r.y }) +
|
|
54
|
+
(r.target ? t('res.input.hoveredEl', { tag: r.target.tag, text: r.target.text }) : '')
|
|
55
|
+
const scrolled = (r) => targetLabel ? t('res.input.scrolledEl', r)
|
|
56
|
+
: t('res.input.scrolled', { dy: `${r.deltaY}px`, scrollY: r.scrollY, pageHeight: r.pageHeight })
|
|
57
|
+
const pressed = (r) => t('res.input.pressedKey', { key: args.key }) + chooserNote(r, tabId)
|
|
58
|
+
if (['type', 'key', 'hover', 'scroll'].includes(action) && !isFrameRef(ref) && await hasCap('actV1')) {
|
|
59
|
+
const hasTarget = action !== 'key'
|
|
60
|
+
const r = await performAct(tabId, {
|
|
61
|
+
kind: action, ref: hasTarget ? ref : undefined, selector: hasTarget ? args.selector : undefined,
|
|
62
|
+
expectedDocId: hasTarget && ref != null ? expectedDocId(tabId) : undefined,
|
|
63
|
+
text: action === 'type' ? args.text : undefined, clear: args.clear, submit: args.submit, key: args.key,
|
|
64
|
+
chooser: action === 'key' || action === 'type' && args.submit === true,
|
|
65
|
+
x: args.x, y: args.y, deltaX: action === 'scroll' ? Number(args.dx || 0) : undefined,
|
|
66
|
+
deltaY: action === 'scroll' ? Number(args.dy ?? 600) : undefined,
|
|
67
|
+
})
|
|
68
|
+
const formats = { type: typed, key: pressed, hover: hovered, scroll: scrolled }
|
|
69
|
+
return finishAction(tabId, formats[action](r), { result: r, observe })
|
|
70
|
+
}
|
|
71
|
+
if (['fill', 'check', 'select'].includes(action) && !isFrameRef(ref) && (ref != null || args.selector || action !== 'select') && await hasCap('actV1')) {
|
|
72
|
+
if (ref != null && (!Number.isInteger(Number(ref)) || Number(ref) < 1)) throw new Error(t('err.refNotInt', { ref }))
|
|
73
|
+
const value = action === 'fill' ? (args.value ?? args.text) : args.value
|
|
74
|
+
if (action === 'fill' && value === undefined) throw new Error(t('err.typeNeedsText'))
|
|
75
|
+
if (action === 'check' && typeof args.checked !== 'boolean') throw new Error(t('err.checkedNeeded'))
|
|
76
|
+
if (action === 'select' && value === undefined) throw new Error(t('err.selectNeedsValue'))
|
|
77
|
+
const field = {
|
|
78
|
+
...(ref != null ? { ref: Number(ref) } : args.selector ? { selector: args.selector } : { activeElement: true }),
|
|
79
|
+
action,
|
|
80
|
+
...(action === 'check' ? { checked: args.checked } : { value: String(value) }),
|
|
81
|
+
}
|
|
82
|
+
const r = await performAct(tabId, {
|
|
83
|
+
kind: 'fillFields', fields: [field], expectedDocId: ref != null ? expectedDocId(tabId) : undefined,
|
|
84
|
+
})
|
|
85
|
+
if (r.failedRef !== undefined) {
|
|
86
|
+
if (r.status === 'gone') {
|
|
87
|
+
const hint = inBatch() ? '' : await staleRefHint(call, tabId, Number(ref)).catch(() => '')
|
|
88
|
+
throw new Error(t('err.refGone', { ref: Number(ref) }) + hint)
|
|
89
|
+
}
|
|
90
|
+
if (r.status === 'missing') throw new Error(t('err.noElement', { sel: args.selector || t('res.input.active') }))
|
|
91
|
+
if (r.status === 'disabled') throw new Error(t('err.fieldDisabled'))
|
|
92
|
+
if (action === 'select') {
|
|
93
|
+
const why = r.status === 'noOption' ? t('err.selectNoOption') : t('err.selectNotSelect')
|
|
94
|
+
const options = r.options ? t('err.selectOptions', { options: r.options.join(', ') }) : ''
|
|
95
|
+
throw new Error(t('err.selectFailed', { why, options }))
|
|
96
|
+
}
|
|
97
|
+
if (r.status === 'wrong') throw new Error(t('err.fieldWrong'))
|
|
98
|
+
throw new Error(t('err.fieldRejected'))
|
|
99
|
+
}
|
|
100
|
+
const text = action === 'select'
|
|
101
|
+
? t('res.input.selected', { label: r.selected?.label ?? '', value: r.selected?.value ?? String(value) })
|
|
102
|
+
: t('res.input.fieldDone', { target: targetLabel || t('res.input.active') })
|
|
103
|
+
return finishAction(tabId, text, { result: r, observe })
|
|
104
|
+
}
|
|
105
|
+
if (action !== 'scroll') await emulateFocus(tabId)
|
|
106
|
+
const before = action === 'upload' && !args.files?.length ? undefined : await probeState(tabId)
|
|
107
|
+
const done = (text, result) => finishAction(tabId, text, { before, result, observe })
|
|
41
108
|
// 有编号就先把它换成选择器;shadow DOM / iframe 里的元素换不成,下面各自按坐标/页内处理
|
|
42
109
|
const hasRef = args.ref !== undefined && args.ref !== null &&
|
|
43
110
|
['type', 'select', 'upload', 'focus', 'hover'].includes(args.action)
|
|
@@ -49,15 +116,22 @@ export function buildInput({ resolveTab, TAB, REF }) {
|
|
|
49
116
|
}
|
|
50
117
|
switch (args.action) {
|
|
51
118
|
case 'type': {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
119
|
+
const epoch = Number.isInteger(before?.controlEpoch) ? { controlEpoch: before.controlEpoch } : {}
|
|
120
|
+
let clicked
|
|
121
|
+
if (el?.shadow) clicked = await call('click', { tabId, x: el.x, y: el.y, ...withCursor(), ...epoch })
|
|
122
|
+
else if (args.clear && selector) clicked = await call('clickEl', { tabId, selector, ...withCursor(), ...epoch })
|
|
123
|
+
if (args.clear) {
|
|
124
|
+
await call('key', { tabId, key: process.platform === 'darwin' ? 'Meta+a' : 'Ctrl+a', ...epoch })
|
|
125
|
+
await call('key', { tabId, key: 'Backspace', ...epoch })
|
|
57
126
|
}
|
|
58
|
-
const r = await call('type', {
|
|
59
|
-
|
|
60
|
-
|
|
127
|
+
const r = await call('type', {
|
|
128
|
+
tabId, text: args.text, selector: !clicked ? selector || undefined : undefined, ...withCursor(),
|
|
129
|
+
...(args.clear || args.submit ? epoch : {}),
|
|
130
|
+
})
|
|
131
|
+
const submitted = args.submit ? await call('key', { tabId, key: 'Enter', chooser: true, ...epoch }) : null
|
|
132
|
+
const result = { ...clicked, ...r, ...submitted }
|
|
133
|
+
const text = el?.shadow ? t('res.input.typedAfterClick', { n: r.typed, target }) + chooserNote(result, tabId) : typed(result)
|
|
134
|
+
return done(text, result)
|
|
61
135
|
}
|
|
62
136
|
case 'fill':
|
|
63
137
|
case 'check': {
|
|
@@ -71,7 +145,7 @@ export function buildInput({ resolveTab, TAB, REF }) {
|
|
|
71
145
|
case 'key': {
|
|
72
146
|
if (!args.key) throw new Error(t('err.keyNeedsKey'))
|
|
73
147
|
const r = await call('key', { tabId, key: args.key, chooser: true })
|
|
74
|
-
return done(
|
|
148
|
+
return done(pressed(r), r)
|
|
75
149
|
}
|
|
76
150
|
case 'select': {
|
|
77
151
|
if (!selector && !el) throw new Error(t('err.selectNeedsTarget'))
|
|
@@ -95,17 +169,17 @@ export function buildInput({ resolveTab, TAB, REF }) {
|
|
|
95
169
|
if (!r || !r.chooser) throw new Error(t('err.uploadNeedsTarget'))
|
|
96
170
|
// 等回包时这个会话可能又点开了新框(存了新 id):只删这次用掉的
|
|
97
171
|
if (chooserIds.get(key) === used) chooserIds.delete(key)
|
|
98
|
-
return
|
|
172
|
+
return done(t('res.input.uploadedChooser', { n: r.files.length }), r)
|
|
99
173
|
}
|
|
100
174
|
let r
|
|
101
175
|
try { r = await call('upload', { tabId, selector, files }) } catch (e) { throw uploadError(e) }
|
|
102
|
-
return
|
|
176
|
+
return done(t('res.input.uploaded', { n: r.files.length, target }), r)
|
|
103
177
|
}
|
|
104
178
|
case 'focus': {
|
|
105
179
|
if (!selector && !el) throw new Error(t('err.focusNeedsTarget'))
|
|
106
180
|
if (el && el.shadow) await focusShadow(call, tabId, args.ref)
|
|
107
181
|
else await call('focus', { tabId, selector })
|
|
108
|
-
return
|
|
182
|
+
return done(t('res.input.focused', { target }))
|
|
109
183
|
}
|
|
110
184
|
case 'hover': {
|
|
111
185
|
const byPoint = el && el.shadow
|
|
@@ -119,25 +193,12 @@ export function buildInput({ resolveTab, TAB, REF }) {
|
|
|
119
193
|
selector: byPoint ? undefined : selector || undefined,
|
|
120
194
|
...withCursor(),
|
|
121
195
|
})
|
|
122
|
-
return
|
|
123
|
-
text:
|
|
124
|
-
t('res.input.hovered', { x: r.x, y: r.y }) +
|
|
125
|
-
(r.target ? t('res.input.hoveredEl', { tag: r.target.tag, text: r.target.text }) : ''),
|
|
126
|
-
}
|
|
196
|
+
return done(hovered(r), r)
|
|
127
197
|
}
|
|
128
198
|
case 'scroll': {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
const r = await call('scroll', { tabId, deltaY: Number(args.dy ?? 600), deltaX: Number(args.dx || 0) })
|
|
134
|
-
return {
|
|
135
|
-
text: t('res.input.scrolled', {
|
|
136
|
-
dy: `${r.deltaY}px`,
|
|
137
|
-
scrollY: r.scrollY,
|
|
138
|
-
pageHeight: r.pageHeight,
|
|
139
|
-
}),
|
|
140
|
-
}
|
|
199
|
+
const r = targetLabel ? await scrollElement(call, tabId, args)
|
|
200
|
+
: await call('scroll', { tabId, deltaY: Number(args.dy ?? 600), deltaX: Number(args.dx || 0) })
|
|
201
|
+
return done(scrolled(r), r)
|
|
141
202
|
}
|
|
142
203
|
default:
|
|
143
204
|
throw new Error(t('err.unknownAction', { action: args.action }))
|
package/tools/nav.js
CHANGED
|
@@ -2,7 +2,8 @@ import { t } from '../core/locale.js'
|
|
|
2
2
|
import { call } from '../core/transport.js'
|
|
3
3
|
import { defineTool, present, textOutput } from '../core/tooldef.js'
|
|
4
4
|
import { recordAction } from '../core/session.js'
|
|
5
|
-
import {
|
|
5
|
+
import { hasCap } from '../core/ext.js'
|
|
6
|
+
import { probeState, finishAction, navWaitParam, observeParam, expectParam, validateNavWait, validateExpect, originOf } from '../core/receipt.js'
|
|
6
7
|
import { historyNav } from '../nav.js'
|
|
7
8
|
|
|
8
9
|
export function buildNav({ resolveTab, TAB }) {
|
|
@@ -15,43 +16,65 @@ export function buildNav({ resolveTab, TAB }) {
|
|
|
15
16
|
description: t('tool.nav.action'),
|
|
16
17
|
},
|
|
17
18
|
url: { type: 'string', description: t('tool.nav.url') },
|
|
19
|
+
observe: observeParam(),
|
|
20
|
+
expect: expectParam(),
|
|
21
|
+
wait: navWaitParam(),
|
|
18
22
|
tab: { type: 'string', description: TAB },
|
|
19
23
|
},
|
|
20
24
|
output: textOutput,
|
|
21
25
|
presentCall: present('nav', 'browser_nav'),
|
|
22
26
|
async execute(args) {
|
|
27
|
+
const action = args.action || 'go'
|
|
28
|
+
const { expect, observe } = args
|
|
29
|
+
const wait = validateNavWait(args.wait)
|
|
30
|
+
validateExpect(expect)
|
|
31
|
+
if (!['go', 'back', 'forward', 'reload'].includes(action)) throw new Error(t('err.unknownAction', { action }))
|
|
32
|
+
if (action === 'go' && !args.url) throw new Error(t('err.navNeedsUrl'))
|
|
23
33
|
const tabId = await resolveTab(args.tab)
|
|
24
34
|
recordAction(tabId)
|
|
25
|
-
const action = args.action || 'go'
|
|
26
|
-
const before = await probeState(tabId)
|
|
27
35
|
if (action === 'go') {
|
|
28
|
-
|
|
29
|
-
const r = await call('nav', { tabId, url: args.url, wait:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const modern = await hasCap('navLifecycle')
|
|
37
|
+
const r = await call('nav', { tabId, url: args.url, wait: modern ? wait : wait !== 'none',
|
|
38
|
+
...(modern ? { receipt: true } : {}) }, modern ? 95_000 : 60_000)
|
|
39
|
+
const late = wait !== 'none' && r.loaded === false ? t('res.nav.late') : ''
|
|
40
|
+
const url = r.receipt?.url || r.url || args.url
|
|
41
|
+
const originChanged = r.receipt?.originChanged ?? (Boolean(originOf(args.url)) && originOf(args.url) !== originOf(url))
|
|
42
|
+
const privateDestination = r.receipt?.protectedSite || r.protectedSite || originChanged
|
|
43
|
+
const text = t('res.nav.go', {
|
|
44
|
+
url: privateDestination ? originOf(url) || '—' : url,
|
|
45
|
+
title: !privateDestination && r.title ? t('res.nav.subtitle', { title: r.title }) : '',
|
|
46
|
+
late,
|
|
47
|
+
})
|
|
48
|
+
const result = r.receipt
|
|
49
|
+
? { ...r, receipt: { ...r.receipt, navigated: true } }
|
|
50
|
+
: { ...r, navigated: true }
|
|
51
|
+
return finishAction(tabId, text, { before: { url: args.url }, result, observe, expect, skipObservation: wait === 'none' || r.loaded === false })
|
|
38
52
|
}
|
|
39
|
-
const r = await historyNav(call, tabId, action)
|
|
40
53
|
const verb = {
|
|
41
54
|
back: t('res.nav.back'),
|
|
42
55
|
forward: t('res.nav.forward'),
|
|
43
56
|
reload: t('res.nav.reload'),
|
|
44
57
|
}[action]
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
text
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}) + await actionReceipt(tabId, before, r),
|
|
58
|
+
const atomicHistory = await hasCap('navLifecycle')
|
|
59
|
+
if (wait === 'none') {
|
|
60
|
+
const r = await historyNav(call, tabId, action, 20000, 'none', { atomic: atomicHistory, requireEpoch: !atomicHistory })
|
|
61
|
+
const text = t('res.nav.history', { verb, url: '—', title: '', late: '' })
|
|
62
|
+
return finishAction(tabId, text, {
|
|
63
|
+
result: { ...r, receipt: { beforeUrl: '', url: '', title: '', navigated: false, unverified: true } },
|
|
64
|
+
observe, expect, skipObservation: true,
|
|
65
|
+
})
|
|
54
66
|
}
|
|
67
|
+
const before = await probeState(tabId)
|
|
68
|
+
const r = await historyNav(call, tabId, action, 20000, wait, { controlEpoch: before?.controlEpoch, atomic: atomicHistory, requireEpoch: !atomicHistory })
|
|
69
|
+
const late = !r.done ? t('res.nav.late') : ''
|
|
70
|
+
const originChanged = before?.url && originOf(before.url) !== originOf(r.url)
|
|
71
|
+
const text = t('res.nav.history', {
|
|
72
|
+
verb,
|
|
73
|
+
url: originChanged ? originOf(r.url) || '—' : r.url,
|
|
74
|
+
title: !originChanged && r.title ? t('res.nav.subtitle', { title: r.title }) : '',
|
|
75
|
+
late,
|
|
76
|
+
})
|
|
77
|
+
return finishAction(tabId, text, { before, result: { ...r, navigated: r.done }, observe, expect, skipObservation: !r.done })
|
|
55
78
|
},
|
|
56
79
|
})
|
|
57
80
|
}
|
package/tools/read.js
CHANGED
|
@@ -14,6 +14,7 @@ export function buildRead({ resolveTab, TAB }) {
|
|
|
14
14
|
name: { type: 'string', description: t('tool.read.name') },
|
|
15
15
|
limit: { type: 'integer', minimum: 1, description: t('tool.read.limit') },
|
|
16
16
|
scope: { type: 'string', enum: ['all', 'viewport'], description: t('tool.read.scope') },
|
|
17
|
+
mode: { type: 'string', enum: ['interactive', 'page'], default: 'interactive', description: t('tool.read.mode') },
|
|
17
18
|
diff: { type: 'boolean', description: t('tool.read.diff') },
|
|
18
19
|
query: { type: 'string', description: t('tool.read.query') },
|
|
19
20
|
cursor: { type: 'integer', minimum: 0, description: t('tool.read.cursor') },
|
|
@@ -28,6 +29,7 @@ export function buildRead({ resolveTab, TAB }) {
|
|
|
28
29
|
const text = await snapshot(call, tabId, {
|
|
29
30
|
selector: args.selector || undefined,
|
|
30
31
|
scope: args.scope,
|
|
32
|
+
mode: args.mode,
|
|
31
33
|
diff: args.diff,
|
|
32
34
|
query: args.query,
|
|
33
35
|
cursor: Math.max(0, Number(args.cursor) || 0),
|
package/tools/tabs.js
CHANGED
|
@@ -2,6 +2,8 @@ import { t } from '../core/locale.js'
|
|
|
2
2
|
import { call } from '../core/transport.js'
|
|
3
3
|
import { formatTabId, isMultiHost, resolveHost, scanHosts } from '../core/hosts.js'
|
|
4
4
|
import { defineTool, present, textOutput } from '../core/tooldef.js'
|
|
5
|
+
import { hasCap } from '../core/ext.js'
|
|
6
|
+
import { finishAction, navWaitParam, observeParam, validateNavWait, originOf } from '../core/receipt.js'
|
|
5
7
|
import { bindCallHost, forgetTab, getSessionHost, getSessionTab, rememberHost, rememberTab } from '../core/session.js'
|
|
6
8
|
|
|
7
9
|
function pickTargetHost(profile) {
|
|
@@ -32,6 +34,8 @@ export function buildTabs({ resolveTab, userTab }) {
|
|
|
32
34
|
query: { type: 'string', description: t('tool.tabs.query') },
|
|
33
35
|
url: { type: 'string', description: t('tool.tabs.url') },
|
|
34
36
|
tab: { type: 'string', description: t('tool.tabs.tab') },
|
|
37
|
+
wait: navWaitParam(),
|
|
38
|
+
observe: observeParam(),
|
|
35
39
|
profile: { type: 'string', description: t('tool.tabs.profile') },
|
|
36
40
|
},
|
|
37
41
|
output: textOutput,
|
|
@@ -82,11 +86,21 @@ export function buildTabs({ resolveTab, userTab }) {
|
|
|
82
86
|
case 'open': {
|
|
83
87
|
if (!args.url) throw new Error(t('err.openNeedsUrl'))
|
|
84
88
|
const target = pickTargetHost(args.profile)
|
|
85
|
-
const
|
|
89
|
+
const wait = validateNavWait(args.wait)
|
|
90
|
+
const modern = await hasCap('navLifecycle')
|
|
91
|
+
const r = await call('open', { url: args.url, ...(modern ? { wait, receipt: true } : {}) },
|
|
92
|
+
modern ? 95_000 : 65_000, false, target.id ? { host: target.id } : {})
|
|
86
93
|
rememberTab(r.tabId, target.id)
|
|
87
94
|
const where = r.window === 'agent' ? t('res.tabs.agentHint') : t('res.tabs.background')
|
|
88
95
|
const displayId = formatTabId(r.tabId, target.id, isMultiHost())
|
|
89
|
-
|
|
96
|
+
const url = r.receipt?.url || r.url || args.url
|
|
97
|
+
const privateDestination = r.receipt?.protectedSite || r.protectedSite ||
|
|
98
|
+
(r.receipt?.originChanged ?? originOf(url) !== originOf(args.url))
|
|
99
|
+
const text = t('res.tabs.opened', { id: displayId, where, url: privateDestination ? originOf(url) || '—' : url })
|
|
100
|
+
return finishAction(r.tabId, text, {
|
|
101
|
+
before: { url: args.url }, result: r, observe: args.observe, opened: true,
|
|
102
|
+
skipObservation: wait === 'none' || r.loaded === false,
|
|
103
|
+
})
|
|
90
104
|
}
|
|
91
105
|
case 'close': {
|
|
92
106
|
const tabSpec = args.profile && args.tab && !String(args.tab).includes(':')
|
package/tools/wait.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { t } from '../core/locale.js'
|
|
2
|
-
import { call } from '../core/transport.js'
|
|
2
|
+
import { call, callInfo } from '../core/transport.js'
|
|
3
3
|
import { defineTool, present, textOutput, WAIT_MAX_MS } from '../core/tooldef.js'
|
|
4
4
|
import { lastActionAt } from '../core/session.js'
|
|
5
|
-
import {
|
|
5
|
+
import { hasCap } from '../core/ext.js'
|
|
6
|
+
import { waitForExtension, waitForCondition } from '../nav.js'
|
|
6
7
|
|
|
7
8
|
export function buildWait({ resolveTab, TAB }) {
|
|
8
9
|
return defineTool({
|
|
@@ -29,8 +30,15 @@ export function buildWait({ resolveTab, TAB }) {
|
|
|
29
30
|
const given = [args.selector, args.text, !args.newTab ? args.url : undefined, args.network, args.responseUrl].filter(has).length +
|
|
30
31
|
Number(args.newTab === true)
|
|
31
32
|
if (given !== 1 || (extensionWait && args.gone)) throw new Error(t('err.waitNeedsOne'))
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
const batch = callInfo.getStore()?.batch
|
|
34
|
+
const onReceipt = batch ? (rct) => { if (rct) batch.receipt = rct } : undefined
|
|
35
|
+
const modern = await hasCap('inPageWait')
|
|
36
|
+
if (extensionWait) {
|
|
37
|
+
return { text: await waitForExtension(call, tabId, {
|
|
38
|
+
...args, timeoutMs, since: lastActionAt.get(tabId), receipt: Boolean(batch && modern), onReceipt,
|
|
39
|
+
}) }
|
|
40
|
+
}
|
|
41
|
+
if (!modern && has(args.selector) && !args.gone) {
|
|
34
42
|
// 客户端超时 = 确认上限 60 秒 + 执行时限 + 传输余量
|
|
35
43
|
const r = await call('waitFor', { tabId, selector: args.selector, timeoutMs, visible: true }, timeoutMs + 65_000)
|
|
36
44
|
return {
|
|
@@ -43,13 +51,13 @@ export function buildWait({ resolveTab, TAB }) {
|
|
|
43
51
|
}),
|
|
44
52
|
}
|
|
45
53
|
}
|
|
46
|
-
const text = await
|
|
54
|
+
const text = await waitForCondition(call, tabId, {
|
|
47
55
|
selector: has(args.selector) ? args.selector : undefined,
|
|
48
56
|
text: has(args.text) ? args.text : undefined,
|
|
49
57
|
url: has(args.url) ? args.url : undefined,
|
|
50
58
|
gone: !!args.gone,
|
|
51
59
|
timeoutMs,
|
|
52
|
-
})
|
|
60
|
+
}, modern, { receipt: Boolean(batch), onReceipt })
|
|
53
61
|
return { text }
|
|
54
62
|
},
|
|
55
63
|
})
|
|
@@ -323,7 +323,7 @@
|
|
|
323
323
|
appear();
|
|
324
324
|
const dx = px - from.x, dy = py - from.y;
|
|
325
325
|
const dist = Math.hypot(dx, dy);
|
|
326
|
-
if (dist < 2 || reduce()) return 0;
|
|
326
|
+
if (dist < 2 || opts.duration === 0 || reduce()) return 0;
|
|
327
327
|
const duration = Math.round(opts.duration != null ? opts.duration : Math.min(260, 110 + dist * 0.18));
|
|
328
328
|
if (opts.straight) { // 拖拽:匀速直线,跟真实的拖动步子对齐
|
|
329
329
|
glide = cur.animate([{ transform: at(from.x, from.y) }, { transform: at(px, py) }], { duration, easing: 'linear' });
|
|
@@ -298,6 +298,7 @@ code { font: 500 12.5px var(--mono); letter-spacing: -0.2px; }
|
|
|
298
298
|
|
|
299
299
|
/* ── 系统开关 ── */
|
|
300
300
|
|
|
301
|
+
.cursor-pace { font: inherit; color: var(--label); background: var(--fill); border: 0; border-radius: 7px; padding: 5px; }
|
|
301
302
|
.toggle { cursor: pointer; user-select: none; }
|
|
302
303
|
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
|
|
303
304
|
.switch { position: relative; flex: none; width: 51px; height: 31px; border-radius: 16px; background: var(--track); transition: background 0.25s ease; }
|
|
@@ -60,9 +60,12 @@
|
|
|
60
60
|
</label>
|
|
61
61
|
<label class="row toggle">
|
|
62
62
|
<span class="tile blue" aria-hidden="true"><svg viewBox="0 0 24 24"><path fill="currentColor" d="M5 3.4v15.4c0 .75.9 1.12 1.42.58l3.6-3.76 2.9 5.94c.24.48.82.68 1.3.45l1.9-.92c.48-.23.68-.8.45-1.28l-2.88-5.9 5.2-.18c.77-.03 1.13-.97.56-1.5L6.64 2.7C6.08 2.18 5 2.6 5 3.4z"/></svg></span>
|
|
63
|
-
<span class="row-main"><span class="row-title" data-i18n="cursor">页面里显示 DSH 光标</span><span class="row-hint" data-i18n="cursorHint"
|
|
64
|
-
<
|
|
65
|
-
|
|
63
|
+
<span class="row-main"><span class="row-title" data-i18n="cursor">页面里显示 DSH 光标</span><span class="row-hint" data-i18n="cursorHint">流畅模式会等光标到位再点击</span></span>
|
|
64
|
+
<select data-act="cursor" class="cursor-pace">
|
|
65
|
+
<option value="fast" data-i18n="paceFast">极速</option>
|
|
66
|
+
<option value="smooth" data-i18n="paceSmooth">流畅</option>
|
|
67
|
+
<option value="off" data-i18n="paceOff">关闭</option>
|
|
68
|
+
</select>
|
|
66
69
|
</label>
|
|
67
70
|
<label class="row toggle">
|
|
68
71
|
<span class="tile orange" aria-hidden="true"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linejoin="round"><rect x="1.8" y="4.6" width="9.6" height="8.6" rx="1.6"/><path d="M4.6 4.6V3.4c0-.9.7-1.6 1.6-1.6h6.4c.9 0 1.6.7 1.6 1.6v5.6c0 .9-.7 1.6-1.6 1.6h-1.2"/></svg></span>
|
|
@@ -51,7 +51,8 @@ const I18N = {
|
|
|
51
51
|
pause: '允许 DSH 控制浏览器',
|
|
52
52
|
pauseHint: '关掉后,DSH 碰不了浏览器',
|
|
53
53
|
cursor: '页面里显示 DSH 光标',
|
|
54
|
-
|
|
54
|
+
paceFast: '极速', paceSmooth: '流畅', paceOff: '关闭',
|
|
55
|
+
cursorHint: '流畅模式会等光标到位再点击',
|
|
55
56
|
window: '新页开在单独窗口',
|
|
56
57
|
windowHint: '关掉就开在你当前窗口的后台',
|
|
57
58
|
files: '上传文件',
|
|
@@ -171,7 +172,7 @@ const I18N = {
|
|
|
171
172
|
tabs: '列标签页', open: '开标签页', close: '关标签页', activate: '切标签页', text: '读文字', html: '读网页源码',
|
|
172
173
|
attr: '读属性', info: '页面信息', eval: '运行脚本', click: '点击', clickEl: '点击', clickText: '点击',
|
|
173
174
|
type: '打字', key: '按键', select: '选下拉', upload: '传文件', focus: '聚焦', hover: '悬停', scroll: '滚动',
|
|
174
|
-
nav: '跳转', shot: '截图', waitFor: '等元素', dialog: '处理弹窗', console: '看控制台', network: '看网络请求',
|
|
175
|
+
nav: '跳转', historyNav: '后退/前进', shot: '截图', waitFor: '等元素', dialog: '处理弹窗', console: '看控制台', network: '看网络请求',
|
|
175
176
|
cursor: '光标', attach: '开始控制', detach: '放开', screencast: '录屏', userRelease: '你放开了',
|
|
176
177
|
'cdp:Input.dispatchMouseEvent': '鼠标', 'cdp:Page.captureScreenshot': '截图', 'cdp:Page.reload': '刷新',
|
|
177
178
|
'cdp:Page.navigateToHistoryEntry': '后退/前进', 'cdp:Network.getResponseBody': '看返回内容',
|
|
@@ -189,7 +190,8 @@ const I18N = {
|
|
|
189
190
|
pause: 'Let DSH control the browser',
|
|
190
191
|
pauseHint: 'Off: DSH can\'t touch the browser',
|
|
191
192
|
cursor: 'Show the DSH cursor',
|
|
192
|
-
|
|
193
|
+
paceFast: 'Fast', paceSmooth: 'Smooth', paceOff: 'Off',
|
|
194
|
+
cursorHint: 'Smooth waits for the cursor before clicking',
|
|
193
195
|
window: 'New pages in a separate window',
|
|
194
196
|
windowHint: 'Off: background tabs in your current window',
|
|
195
197
|
files: 'File uploads',
|
|
@@ -309,7 +311,7 @@ const I18N = {
|
|
|
309
311
|
tabs: 'List tabs', open: 'Open tab', close: 'Close tab', activate: 'Switch tab', text: 'Read text', html: 'Read HTML',
|
|
310
312
|
attr: 'Read attribute', info: 'Page info', eval: 'Run script', click: 'Click', clickEl: 'Click', clickText: 'Click',
|
|
311
313
|
type: 'Type', key: 'Key press', select: 'Select', upload: 'Upload', focus: 'Focus', hover: 'Hover', scroll: 'Scroll',
|
|
312
|
-
nav: 'Navigate', shot: 'Screenshot', waitFor: 'Wait for element', dialog: 'Handle dialog', console: 'Console', network: 'Network',
|
|
314
|
+
nav: 'Navigate', historyNav: 'Back/forward', shot: 'Screenshot', waitFor: 'Wait for element', dialog: 'Handle dialog', console: 'Console', network: 'Network',
|
|
313
315
|
cursor: 'Cursor', attach: 'Take control', detach: 'Release', screencast: 'Record', userRelease: 'You released it',
|
|
314
316
|
'cdp:Input.dispatchMouseEvent': 'Mouse', 'cdp:Page.captureScreenshot': 'Screenshot', 'cdp:Page.reload': 'Reload',
|
|
315
317
|
'cdp:Page.navigateToHistoryEntry': 'Back/forward', 'cdp:Network.getResponseBody': 'Response body',
|
|
@@ -327,7 +329,8 @@ const I18N = {
|
|
|
327
329
|
pause: 'Разрешить управлять браузером',
|
|
328
330
|
pauseHint: 'Выкл.: DSH не может трогать браузер',
|
|
329
331
|
cursor: 'Показывать курсор DSH',
|
|
330
|
-
|
|
332
|
+
paceFast: 'Быстро', paceSmooth: 'Плавно', paceOff: 'Выкл.',
|
|
333
|
+
cursorHint: 'В плавном режиме щелчок следует за курсором',
|
|
331
334
|
window: 'Новые страницы в отдельном окне',
|
|
332
335
|
windowHint: 'Выкл.: фоновые вкладки в текущем окне',
|
|
333
336
|
files: 'Загрузка файлов',
|
|
@@ -447,7 +450,7 @@ const I18N = {
|
|
|
447
450
|
tabs: 'Список вкладок', open: 'Открыть вкладку', close: 'Закрыть вкладку', activate: 'Переключить вкладку', text: 'Текст', html: 'HTML',
|
|
448
451
|
attr: 'Атрибут', info: 'Сведения', eval: 'Скрипт', click: 'Клик', clickEl: 'Клик', clickText: 'Клик',
|
|
449
452
|
type: 'Ввод', key: 'Клавиша', select: 'Выбор', upload: 'Файл', focus: 'Фокус', hover: 'Наведение', scroll: 'Прокрутка',
|
|
450
|
-
nav: 'Переход', shot: 'Скриншот', waitFor: 'Ожидание элемента', dialog: 'Диалог', console: 'Консоль', network: 'Сеть',
|
|
453
|
+
nav: 'Переход', historyNav: 'Назад/вперёд', shot: 'Скриншот', waitFor: 'Ожидание элемента', dialog: 'Диалог', console: 'Консоль', network: 'Сеть',
|
|
451
454
|
cursor: 'Курсор', attach: 'Начало управления', detach: 'Отпустить', screencast: 'Запись', userRelease: 'Вы отпустили',
|
|
452
455
|
'cdp:Input.dispatchMouseEvent': 'Мышь', 'cdp:Page.captureScreenshot': 'Скриншот', 'cdp:Page.reload': 'Обновить',
|
|
453
456
|
'cdp:Page.navigateToHistoryEntry': 'Назад/вперёд', 'cdp:Network.getResponseBody': 'Ответ сервера',
|
|
@@ -669,10 +672,9 @@ function renderStatus(st) {
|
|
|
669
672
|
|
|
670
673
|
function renderSettings(st) {
|
|
671
674
|
const pause = document.querySelector('input[data-act="pause"]')
|
|
672
|
-
const cursor = document.querySelector('
|
|
675
|
+
const cursor = document.querySelector('select[data-act="cursor"]')
|
|
673
676
|
if (pause.checked !== !st.paused) pause.checked = !st.paused
|
|
674
|
-
|
|
675
|
-
if (cursor.checked !== showCursor) cursor.checked = showCursor
|
|
677
|
+
if (!cursor.disabled) cursor.value = st.cursorPace || (st.showCursor === false ? 'off' : 'fast')
|
|
676
678
|
const win = document.querySelector('input[data-act="window"]')
|
|
677
679
|
const ownWindow = st.ownWindow !== false
|
|
678
680
|
if (win.checked !== ownWindow) win.checked = ownWindow
|
|
@@ -996,21 +998,25 @@ document.addEventListener('click', async (ev) => {
|
|
|
996
998
|
/** 开关的「后台确认过的」状态:从上一次拿到的 state 里读;还没拿到过就当是点之前的样子 */
|
|
997
999
|
const SWITCHES = {
|
|
998
1000
|
pause: { confirmed: (st) => !st.paused, msg: (on) => ({ on: !on }), ok: (on) => (on ? T('resumedToast') : T('pausedToast')) },
|
|
999
|
-
cursor: { confirmed: (st) => st.showCursor
|
|
1001
|
+
cursor: { confirmed: (st) => st.cursorPace || (st.showCursor === false ? 'off' : 'fast'), msg: (cursorPace) => ({ cursorPace }), ok: (pace) => (pace === 'off' ? T('cursorOff') : `${T('cursorOn')} · ${T(pace === 'smooth' ? 'paceSmooth' : 'paceFast')}`) },
|
|
1000
1002
|
window: { confirmed: (st) => st.ownWindow !== false, msg: (on) => ({ on }), ok: (on) => (on ? T('windowOn') : T('windowOff')) },
|
|
1001
1003
|
}
|
|
1002
1004
|
|
|
1003
1005
|
document.addEventListener('change', async (ev) => {
|
|
1004
|
-
const input = ev.target.closest('input[data-act]')
|
|
1006
|
+
const input = ev.target.closest('input[data-act],select[data-act]')
|
|
1005
1007
|
if (!input) return
|
|
1006
1008
|
const act = input.dataset.act
|
|
1007
1009
|
const sw = SWITCHES[act]
|
|
1008
1010
|
if (!sw) return
|
|
1009
|
-
const
|
|
1011
|
+
const pace = act === 'cursor'
|
|
1012
|
+
const on = pace ? input.value : input.checked
|
|
1013
|
+
input.disabled = true
|
|
1010
1014
|
const res = await ask(act, sw.msg(on))
|
|
1015
|
+
input.disabled = false
|
|
1011
1016
|
if (!res || res.error) {
|
|
1012
1017
|
// 没改成:开关退回后台确认过的状态,不报成功;也不拿这个错误去画「扩展没响应」
|
|
1013
|
-
input.
|
|
1018
|
+
if (pace) input.value = last ? sw.confirmed(last) : 'fast'
|
|
1019
|
+
else input.checked = last ? sw.confirmed(last) : !on
|
|
1014
1020
|
toast(T('settingFailed', { e: (res && res.error) || '?' }))
|
|
1015
1021
|
return
|
|
1016
1022
|
}
|