dsh-chrome-bridge 1.18.0 → 1.20.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 +2 -0
- package/README.md +2 -0
- package/devtools.js +22 -11
- package/download.js +19 -12
- package/drag.js +30 -10
- package/i18n/en.js +157 -4
- package/i18n/index.js +17 -0
- package/i18n/ru.js +157 -4
- package/i18n/zh.js +155 -2
- package/index.js +201 -66
- package/nav.js +13 -5
- package/package.json +1 -1
- package/panel.js +4 -3
- package/refs.js +22 -14
- package/setup.js +34 -28
- package/vendor/extension/background.js +306 -18
- package/vendor/extension/manifest.json +1 -1
- package/vendor/extension/popup.css +2 -0
- package/vendor/extension/popup.html +6 -0
- package/vendor/extension/popup.js +17 -0
package/README.en.md
CHANGED
|
@@ -13,6 +13,8 @@ Lets DSH work in the Chrome you already use: real clicks and typing, a cursor yo
|
|
|
13
13
|
|
|
14
14
|
Once both are in, the plugin shows "Connected" on the Plugins page.
|
|
15
15
|
|
|
16
|
+
To let DSH upload files into web pages: open the extension's **Details** in Chrome and turn on **Allow access to file URLs** (Chrome keeps it off by default). The DSH Bridge popup also shows a "File uploads · Open" row.
|
|
17
|
+
|
|
16
18
|
## Update
|
|
17
19
|
|
|
18
20
|
Open it on the Plugins page and click "Update to …". A new version can be installed about a day after it is released.
|
package/README.md
CHANGED
package/devtools.js
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* 所以看 console 前先 attach 一下就能拿到「打开页面以来」的输出。网络请求没有补发,要 reload。
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { tt } from './i18n/index.js'
|
|
10
|
+
|
|
9
11
|
const time = (ms) => new Date(ms).toTimeString().slice(0, 8)
|
|
10
12
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
|
|
11
13
|
const LEVELS = {
|
|
@@ -31,13 +33,15 @@ export async function consoleLog(call, tabId, { level = 'all', filter, limit = 4
|
|
|
31
33
|
}
|
|
32
34
|
const total = items.length
|
|
33
35
|
items = items.slice(-limit)
|
|
34
|
-
if (!items.length) return level === 'all' && !filter ? '
|
|
36
|
+
if (!items.length) return level === 'all' && !filter ? tt('res.devtools.consoleEmpty') : tt('res.devtools.consoleNoMatch')
|
|
35
37
|
const lines = items.map((c) => {
|
|
36
|
-
const tag = c.kind === 'exception' ? '
|
|
38
|
+
const tag = c.kind === 'exception' ? tt('res.devtools.uncaught') : c.kind && c.kind !== 'console' ? `[${c.kind}] ` : ''
|
|
37
39
|
const where = c.where ? ` (${shortWhere(c.where)})` : ''
|
|
38
40
|
return `${time(c.at)} ${String(c.level).padEnd(7)} ${tag}${c.text}${where}`
|
|
39
41
|
})
|
|
40
|
-
const head = total > items.length
|
|
42
|
+
const head = total > items.length
|
|
43
|
+
? tt('res.devtools.consoleHead', { shown: items.length, total })
|
|
44
|
+
: tt('res.devtools.consoleCount', { n: items.length })
|
|
41
45
|
return `${head}\n${lines.join('\n')}`
|
|
42
46
|
}
|
|
43
47
|
|
|
@@ -51,7 +55,7 @@ export async function networkLog(call, tabId, { filter, reload = false, limit =
|
|
|
51
55
|
const total = items.length
|
|
52
56
|
items = items.slice(-limit)
|
|
53
57
|
if (!items.length) {
|
|
54
|
-
return filter ? '
|
|
58
|
+
return filter ? tt('res.devtools.netEmptyFiltered') : tt('res.devtools.netEmpty')
|
|
55
59
|
}
|
|
56
60
|
const hasId = items.some((n) => n.id)
|
|
57
61
|
const lines = items.map((n) => {
|
|
@@ -60,35 +64,42 @@ export async function networkLog(call, tabId, { filter, reload = false, limit =
|
|
|
60
64
|
const url = n.url.length > 150 ? n.url.slice(0, 149) + '…' : n.url
|
|
61
65
|
return `${hasId ? `#${n.id} ` : ''}${n.method} ${status} ${String(n.type || '').toLowerCase()} ${ms} ${url}`
|
|
62
66
|
})
|
|
63
|
-
const head =
|
|
64
|
-
(
|
|
67
|
+
const head =
|
|
68
|
+
(total > items.length
|
|
69
|
+
? tt('res.devtools.netHead', { shown: items.length, total })
|
|
70
|
+
: tt('res.devtools.netCount', { n: items.length })) +
|
|
71
|
+
(hasId ? tt('res.devtools.netHintResponse') : tt('res.devtools.netHintOldExt'))
|
|
65
72
|
return `${head}\n${lines.join('\n')}`
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
export async function responseBody(call, tabId, requestId, limit = 6000) {
|
|
69
|
-
if (!requestId) throw new Error('
|
|
76
|
+
if (!requestId) throw new Error(tt('err.devtools.requestNeeded'))
|
|
70
77
|
const id = String(requestId).replace(/^#/, '')
|
|
71
78
|
let r
|
|
72
79
|
try {
|
|
73
80
|
r = await call('cdp', { tabId, method: 'Network.getResponseBody', params: { requestId: id } })
|
|
74
81
|
} catch (e) {
|
|
75
82
|
if (/No resource|No data found|identifier/i.test(e.message)) {
|
|
76
|
-
throw new Error('
|
|
83
|
+
throw new Error(tt('err.devtools.noBody'))
|
|
77
84
|
}
|
|
78
85
|
throw e
|
|
79
86
|
}
|
|
80
87
|
const { body = '', base64Encoded } = r.result || {}
|
|
81
|
-
if (base64Encoded)
|
|
88
|
+
if (base64Encoded) {
|
|
89
|
+
return tt('res.devtools.binary', { size: `${Math.round((body.length * 3) / 4 / 1024)}KB` })
|
|
90
|
+
}
|
|
82
91
|
let text = body
|
|
83
92
|
const t = body.trim()
|
|
84
93
|
if (t.startsWith('{') || t.startsWith('[')) {
|
|
85
94
|
try { text = JSON.stringify(JSON.parse(t), null, 2) } catch {}
|
|
86
95
|
}
|
|
87
|
-
return text.length > limit
|
|
96
|
+
return text.length > limit
|
|
97
|
+
? text.slice(0, limit) + tt('res.devtools.truncated', { n: text.length })
|
|
98
|
+
: text || tt('res.devtools.empty')
|
|
88
99
|
}
|
|
89
100
|
|
|
90
101
|
export async function clearLogs(call, tabId) {
|
|
91
102
|
await call('console', { tabId, clear: true })
|
|
92
103
|
await call('network', { tabId, clear: true })
|
|
93
|
-
return '
|
|
104
|
+
return tt('res.devtools.cleared')
|
|
94
105
|
}
|
package/download.js
CHANGED
|
@@ -14,6 +14,7 @@ import os from 'node:os'
|
|
|
14
14
|
import path from 'node:path'
|
|
15
15
|
import crypto from 'node:crypto'
|
|
16
16
|
import { refElementJs } from './refs.js'
|
|
17
|
+
import { tt } from './i18n/index.js'
|
|
17
18
|
|
|
18
19
|
const CHUNK = 2 * 1024 * 1024 // 页面里每次读回 2MB(base64 后约 2.7MB)
|
|
19
20
|
const PAGE_MAX = 300 * 1024 * 1024 // 页面里最多暂存这么大,再大走插件直接下
|
|
@@ -70,7 +71,7 @@ export function uniquePath(dir, name) {
|
|
|
70
71
|
const p = path.join(dir, i ? `${base} (${i})${ext}` : name)
|
|
71
72
|
if (!fs.existsSync(p)) return p
|
|
72
73
|
}
|
|
73
|
-
throw new Error(
|
|
74
|
+
throw new Error(tt('err.dlTooManyNames', { dir, name }))
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
export function humanSize(n) {
|
|
@@ -128,14 +129,14 @@ const DROP_JS = (id) => `(() => { if (window.__dshDl) delete window.__dshDl[${JS
|
|
|
128
129
|
async function viaPage(call, tabId, url, file) {
|
|
129
130
|
const id = crypto.randomUUID()
|
|
130
131
|
const r = (await call('eval', { tabId, expression: FETCH_JS(id, url), awaitPromise: true, userGesture: false }, TIMEOUT_MS)).value || {}
|
|
131
|
-
if (r.status) throw new Error(
|
|
132
|
+
if (r.status) throw new Error(tt('err.dlHttp', { status: r.status }))
|
|
132
133
|
if (r.failed || r.tooBig) return null
|
|
133
134
|
try {
|
|
134
135
|
const fd = fs.openSync(file, 'w')
|
|
135
136
|
try {
|
|
136
137
|
for (let off = 0; off < r.size; off += CHUNK) {
|
|
137
138
|
const b64 = (await call('eval', { tabId, expression: CHUNK_JS(id, off), userGesture: false })).value
|
|
138
|
-
if (typeof b64 !== 'string') throw new Error('
|
|
139
|
+
if (typeof b64 !== 'string') throw new Error(tt('err.dlPageGone'))
|
|
139
140
|
fs.writeSync(fd, Buffer.from(b64, 'base64'))
|
|
140
141
|
}
|
|
141
142
|
} finally {
|
|
@@ -176,7 +177,7 @@ async function viaNode(call, tabId, target, file, fetchImpl = globalThis.fetch)
|
|
|
176
177
|
url = new URL(res.headers.get('location'), url).href
|
|
177
178
|
continue
|
|
178
179
|
}
|
|
179
|
-
if (!res.ok || !res.body) throw new Error(
|
|
180
|
+
if (!res.ok || !res.body) throw new Error(tt('err.dlHttp', { status: res.status }))
|
|
180
181
|
const out = fs.createWriteStream(file)
|
|
181
182
|
let size = 0
|
|
182
183
|
try {
|
|
@@ -189,7 +190,7 @@ async function viaNode(call, tabId, target, file, fetchImpl = globalThis.fetch)
|
|
|
189
190
|
}
|
|
190
191
|
return { size, type: res.headers.get('content-type') || '', disposition: res.headers.get('content-disposition') || '', finalUrl: url }
|
|
191
192
|
}
|
|
192
|
-
throw new Error('
|
|
193
|
+
throw new Error(tt('err.dlRedirects'))
|
|
193
194
|
} finally {
|
|
194
195
|
clearTimeout(timer)
|
|
195
196
|
}
|
|
@@ -200,14 +201,20 @@ async function viaNode(call, tabId, target, file, fetchImpl = globalThis.fetch)
|
|
|
200
201
|
* @param opts.dir 存到哪个文件夹(调用方已经定好)
|
|
201
202
|
*/
|
|
202
203
|
export async function download(call, tabId, { url, ref, selector, filename, dir }, deps = {}) {
|
|
203
|
-
if ((ref === undefined || ref === null) && !selector && !url) throw new Error('
|
|
204
|
+
if ((ref === undefined || ref === null) && !selector && !url) throw new Error(tt('err.dlNeedsTarget'))
|
|
204
205
|
const target = (await call('eval', { tabId, expression: TARGET_JS({ ref, selector, url }), userGesture: false })).value
|
|
205
|
-
if (!target) throw new Error('
|
|
206
|
-
if (target.error === 'gone')
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
if (!target) throw new Error(tt('err.dlNoAnswer'))
|
|
207
|
+
if (target.error === 'gone') {
|
|
208
|
+
throw new Error(
|
|
209
|
+
ref !== undefined && ref !== null
|
|
210
|
+
? tt('err.dlRefGone', { ref })
|
|
211
|
+
: tt('err.noElement', { sel: selector }),
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
if (target.error === 'nohref') throw new Error(tt('err.dlNoHref', { tag: target.tag }))
|
|
215
|
+
if (target.error === 'badurl') throw new Error(tt('err.dlBadUrl', { raw: target.raw }))
|
|
209
216
|
const proto = new URL(target.url).protocol
|
|
210
|
-
if (!['http:', 'https:', 'blob:', 'data:'].includes(proto)) throw new Error(
|
|
217
|
+
if (!['http:', 'https:', 'blob:', 'data:'].includes(proto)) throw new Error(tt('err.dlBadProto', { proto }))
|
|
211
218
|
|
|
212
219
|
fs.mkdirSync(dir, { recursive: true })
|
|
213
220
|
const part = path.join(dir, `.dsh-download-${crypto.randomUUID()}.part`)
|
|
@@ -215,7 +222,7 @@ export async function download(call, tabId, { url, ref, selector, filename, dir
|
|
|
215
222
|
let via = 'page'
|
|
216
223
|
let meta = await viaPage(call, tabId, target.url, part)
|
|
217
224
|
if (!meta) {
|
|
218
|
-
if (proto === 'blob:' || proto === 'data:') throw new Error('
|
|
225
|
+
if (proto === 'blob:' || proto === 'data:') throw new Error(tt('err.dlBlobDead'))
|
|
219
226
|
via = 'direct'
|
|
220
227
|
meta = await viaNode(call, tabId, target, part, deps.fetch)
|
|
221
228
|
}
|
package/drag.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { refElementJs } from './refs.js'
|
|
15
|
+
import { tt } from './i18n/index.js'
|
|
15
16
|
|
|
16
17
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
|
|
17
18
|
|
|
@@ -47,7 +48,9 @@ const elementJs = (end) =>
|
|
|
47
48
|
|
|
48
49
|
const isElementEnd = (end) => hasRef(end) || !!end.selector || !!end.text
|
|
49
50
|
const describe = (end) =>
|
|
50
|
-
hasRef(end)
|
|
51
|
+
hasRef(end)
|
|
52
|
+
? `[${end.ref}]`
|
|
53
|
+
: end.selector || (end.text ? tt('res.drag.quotedText', { text: end.text }) : `(${end.x}, ${end.y})`)
|
|
51
54
|
|
|
52
55
|
/** 一次 eval 算出两端的视口坐标,顺带判断是不是原生拖放。 */
|
|
53
56
|
const PLAN_JS = (from, to) => `(async () => {
|
|
@@ -96,30 +99,40 @@ const NATIVE_JS = (from, to, a, b) => `(() => {
|
|
|
96
99
|
*/
|
|
97
100
|
export async function drag(call, tabId, from, to, { steps = 12, cursor } = {}) {
|
|
98
101
|
const plan = (await call('eval', { tabId, expression: PLAN_JS(from, to), userGesture: false })).value
|
|
99
|
-
if (!plan) throw new Error('
|
|
102
|
+
if (!plan) throw new Error(tt('err.dragNoAnswer'))
|
|
100
103
|
if (plan.missing) {
|
|
101
104
|
const end = plan.missing === 'from' ? from : to
|
|
102
|
-
throw new Error(
|
|
103
|
-
(
|
|
105
|
+
throw new Error(
|
|
106
|
+
tt('err.dragNotFound', {
|
|
107
|
+
end: plan.missing === 'from' ? tt('which.start') : tt('which.end'),
|
|
108
|
+
desc: describe(end),
|
|
109
|
+
}) + (hasRef(end) ? tt('err.dragRefStale') : ''),
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
if (plan.same) {
|
|
113
|
+
throw new Error(tt('err.dragSame', { from: describe(from), to: describe(to) }))
|
|
104
114
|
}
|
|
105
|
-
if (plan.same) throw new Error(`起点 ${describe(from)} 和终点 ${describe(to)} 找到的是同一个元素——换个更具体的写法(ref 或 selector)`)
|
|
106
115
|
const { a, b } = plan
|
|
107
|
-
if (!plan.bIn) throw new Error(
|
|
116
|
+
if (!plan.bIn) throw new Error(tt('err.dragOffscreen', { to: describe(to) }))
|
|
108
117
|
|
|
109
118
|
const cur = async (fn) => {
|
|
110
119
|
if (!cursor) return 0
|
|
111
120
|
try { return Number(await fn(cursor)) || 0 } catch { return 0 }
|
|
112
121
|
}
|
|
113
122
|
// 光标先滑到起点亮名牌,到位了再按下
|
|
114
|
-
if (cursor) await sleep(Math.min(700, await cur((c) => c.move(a.x, a.y, { label:
|
|
123
|
+
if (cursor) await sleep(Math.min(700, await cur((c) => c.move(a.x, a.y, { label: tt('res.drag.label', { from: describe(from), to: describe(to) }) }))) + 60)
|
|
115
124
|
|
|
116
125
|
if (plan.native) {
|
|
117
126
|
await cur((c) => c.down())
|
|
118
127
|
await sleep(await cur((c) => c.move(b.x, b.y, { duration: 420, straight: true })))
|
|
119
128
|
const r = (await call('eval', { tabId, expression: NATIVE_JS(from, to, a, b) })).value
|
|
120
129
|
await cur((c) => c.up())
|
|
121
|
-
if (r && r.error) throw new Error('
|
|
122
|
-
return
|
|
130
|
+
if (r && r.error) throw new Error(tt('err.dragNoTarget'))
|
|
131
|
+
return tt('res.drag.doneHtml5', {
|
|
132
|
+
from: describe(from),
|
|
133
|
+
to: describe(to),
|
|
134
|
+
verdict: r && r.accepted ? tt('res.drag.accepted') : tt('res.drag.notAccepted'),
|
|
135
|
+
})
|
|
123
136
|
}
|
|
124
137
|
|
|
125
138
|
const mouse = (type, p, extra) => call('cdp', {
|
|
@@ -139,5 +152,12 @@ export async function drag(call, tabId, from, to, { steps = 12, cursor } = {}) {
|
|
|
139
152
|
}
|
|
140
153
|
await mouse('mouseReleased', b, { button: 'left', buttons: 0, clickCount: 1 })
|
|
141
154
|
await cur((c) => c.up())
|
|
142
|
-
return
|
|
155
|
+
return tt('res.drag.doneCoords', {
|
|
156
|
+
from: describe(from),
|
|
157
|
+
to: describe(to),
|
|
158
|
+
x1: Math.round(a.x),
|
|
159
|
+
y1: Math.round(a.y),
|
|
160
|
+
x2: Math.round(b.x),
|
|
161
|
+
y2: Math.round(b.y),
|
|
162
|
+
})
|
|
143
163
|
}
|
package/i18n/en.js
CHANGED
|
@@ -38,10 +38,10 @@ export default {
|
|
|
38
38
|
'tool.input.action': 'Input action to perform',
|
|
39
39
|
'tool.input.text': 'Text to enter when action=type',
|
|
40
40
|
'tool.input.ref': '%ref; can replace selector',
|
|
41
|
-
'tool.input.selector': 'CSS selector (for type it is clicked first to focus; select/
|
|
41
|
+
'tool.input.selector': 'CSS selector (for type it is clicked first to focus; select/focus/hover need it or ref; upload needs it too, unless the reply to your last click explicitly said the page is asking for a file)',
|
|
42
42
|
'tool.input.key': 'Key for action=key, e.g. Enter / Escape / "meta+a" / "ctrl+shift+k"',
|
|
43
43
|
'tool.input.value': 'Value or option label to pick when action=select',
|
|
44
|
-
'tool.input.files': 'Absolute local file paths for action=upload (only regular, non-hidden files under the session working directory or the system temp directory)',
|
|
44
|
+
'tool.input.files': 'Absolute local file paths for action=upload (only regular, non-hidden files under the session working directory or the system temp directory). Only when the reply to your last click explicitly said the page is asking for a file may upload omit ref / selector',
|
|
45
45
|
'tool.input.dy': 'Vertical scroll amount for action=scroll; default 600 (positive scrolls down)',
|
|
46
46
|
'tool.input.dx': 'Horizontal scroll amount for action=scroll; default 0',
|
|
47
47
|
'tool.input.x': 'Viewport X for action=hover when no selector is given',
|
|
@@ -135,6 +135,15 @@ export default {
|
|
|
135
135
|
'err.selectNeedsValue': 'action=select needs value',
|
|
136
136
|
'err.uploadNeedsTarget': 'action=upload needs ref or selector',
|
|
137
137
|
'err.uploadNeedsFiles': 'action=upload needs files',
|
|
138
|
+
'err.uploadNoChooser': "The page is not waiting for a file: click the page's upload button first (the reply will say so), or point at the file input with ref / selector",
|
|
139
|
+
'err.uploadUserPicked': 'Someone used this file input after it was intercepted (most likely the user picked a file themselves), so nothing was replaced. If you really need to swap in your files, ask the user first, then click the upload button again.',
|
|
140
|
+
'err.uploadFolder': 'This is a folder picker, and DSH cannot pick folders yet: ask the user to click the matching button on the page and pick the folder themselves (their own clicks are not intercepted).',
|
|
141
|
+
'err.uploadSingle': 'This file input takes only one file; pass a single path in files',
|
|
142
|
+
'err.fileAccessOff': 'Cannot upload: by default Chrome does not let extensions read files on the computer. Ask the user to open %url (the DSH Bridge details page) in Chrome and turn on "Allow access to file URLs". The extension then reloads by itself; wait a few seconds and upload again (if the page had opened a file picker, click its upload button again).',
|
|
143
|
+
'note.fileChooser': '📎 The page is asking for a file%multi: the system file picker was intercepted (it will not open). Hand the files to it with browser_input action=upload files=[…]; no ref / selector needed. If the user wants to pick in the system dialog themselves, ask them to click this button (their own clicks are not intercepted).',
|
|
144
|
+
'note.fileChooserMulti': ' (multiple allowed)',
|
|
145
|
+
'note.fileChooserUnsupported': '⚠️ The page opened a different kind of system file dialog (not a file input in the page). DSH cannot fill it, and this one was cancelled. Clicking again shows the normal system dialog; the user has to pick the file there.',
|
|
146
|
+
'note.fileChooserFolder': '⚠️ This button asks for a whole folder, and DSH cannot pick folders yet, so this system dialog will not open. Ask the user to click this button and pick the folder themselves (their own clicks are not intercepted).',
|
|
138
147
|
'err.focusNeedsTarget': 'action=focus needs ref or selector',
|
|
139
148
|
'err.hoverNeedsTarget': 'action=hover needs ref or selector, or x/y coordinates',
|
|
140
149
|
'err.navNeedsUrl': 'action=go needs a url',
|
|
@@ -143,8 +152,8 @@ export default {
|
|
|
143
152
|
'err.waitNeedsOne': 'Give exactly one of selector / text / url',
|
|
144
153
|
'err.dragNeedsEnd': '%which needs one of %ref, %sel, %txt or %xy',
|
|
145
154
|
'err.noWorkdir': 'Cannot determine the session working directory; drop to=workdir to save into the "Downloads" folder',
|
|
146
|
-
'which.start': '
|
|
147
|
-
'which.end': '
|
|
155
|
+
'which.start': 'start point',
|
|
156
|
+
'which.end': 'end point',
|
|
148
157
|
|
|
149
158
|
// ── setup hints appended to errors ─────────────────────────────────────
|
|
150
159
|
'hint.extOpened': 'I opened chrome://extensions for you (background tab)%store',
|
|
@@ -154,4 +163,148 @@ export default {
|
|
|
154
163
|
'hint.copiedWin': 'paste it into the file picker\'s address bar and press Enter',
|
|
155
164
|
'hint.notes': '\n(%notes)',
|
|
156
165
|
'hint.notesSep': '; ',
|
|
166
|
+
'err.navFirstPage': 'This is already the first page; cannot go back',
|
|
167
|
+
'err.navLastPage': 'This is already the last page; cannot go forward',
|
|
168
|
+
'res.wait.whatText': 'text "%text"',
|
|
169
|
+
'res.wait.whatUrl': 'a URL containing "%url"',
|
|
170
|
+
'res.wait.found': 'Found',
|
|
171
|
+
'res.wait.goneState': 'No longer present:',
|
|
172
|
+
'res.wait.ok': '%state %what after %ms',
|
|
173
|
+
'res.wait.still': 'is still there',
|
|
174
|
+
'res.wait.notYet': 'has not appeared yet',
|
|
175
|
+
'err.waitTimeout': 'Waited %ms: %what %state',
|
|
176
|
+
'err.panelTooLarge': 'Request is too large',
|
|
177
|
+
'err.panelNotJson': 'Not JSON',
|
|
178
|
+
'res.devtools.consoleEmpty': '(the console has no output)',
|
|
179
|
+
'res.devtools.consoleNoMatch': '(no matching entries)',
|
|
180
|
+
'res.devtools.uncaught': '[uncaught] ',
|
|
181
|
+
'res.devtools.consoleHead': 'last %shown of %total entries',
|
|
182
|
+
'res.devtools.consoleCount': '%n entries',
|
|
183
|
+
'res.devtools.netEmptyFiltered': '(no matching requests)',
|
|
184
|
+
'res.devtools.netEmpty': '(no requests recorded yet — only those made after the debugger attached; pass reload=true to refresh once and capture everything the page loads)',
|
|
185
|
+
'res.devtools.netHead': 'last %shown of %total requests',
|
|
186
|
+
'res.devtools.netCount': '%n requests',
|
|
187
|
+
'res.devtools.netHintResponse': '; to see a response body: action=response with the # number from the list as request',
|
|
188
|
+
'res.devtools.netHintOldExt': '; the extension is outdated and response bodies are unavailable — reload the extension',
|
|
189
|
+
'err.devtools.requestNeeded': 'action=response needs request (the # number listed by action=network)',
|
|
190
|
+
'err.devtools.noBody': 'cannot fetch this request\'s response body (evicted too early, the request is not finished, or the debugger was detached) — rerun action=network reload=true',
|
|
191
|
+
'res.devtools.binary': '(binary content, about %size — not text)',
|
|
192
|
+
'res.devtools.truncated': '\n…(truncated, %n characters in total)',
|
|
193
|
+
'res.devtools.empty': '(empty)',
|
|
194
|
+
'res.devtools.cleared': 'Console and network records cleared',
|
|
195
|
+
'err.dlTooManyNames': 'too many files with the same name in %dir: %name',
|
|
196
|
+
'err.dlHttp': 'download failed: the server returned HTTP %status',
|
|
197
|
+
'err.dlPageGone': 'the page navigated away; the download was aborted',
|
|
198
|
+
'err.dlRedirects': 'download failed: too many redirects',
|
|
199
|
+
'err.dlNeedsTarget': 'give one of url, ref or selector',
|
|
200
|
+
'err.dlNoAnswer': 'the page did not answer (it may have just navigated; try again)',
|
|
201
|
+
'err.dlRefGone': 'ref %ref is no longer valid — run browser_read what=snapshot again',
|
|
202
|
+
'err.noElement': 'element not found: %sel',
|
|
203
|
+
'err.dlNoHref': 'this %tag element has no link (href / src). If it is a button, browser_click it first and see whether that opens a download link',
|
|
204
|
+
'err.dlBadUrl': 'bad URL: %raw',
|
|
205
|
+
'err.dlBadProto': 'unsupported URL scheme: %proto',
|
|
206
|
+
'err.dlBlobDead': 'cannot read this file from the page (the blob link may have expired: click the button that generates it again and retry)',
|
|
207
|
+
'res.drag.label': 'dragging %from → %to',
|
|
208
|
+
'res.drag.quotedText': '"%text"',
|
|
209
|
+
'err.dragNoAnswer': 'the page did not answer (it may have just navigated; try again)',
|
|
210
|
+
'err.dragNotFound': 'could not find the %end: %desc',
|
|
211
|
+
'err.dragRefStale': ' (the ref may be stale; take a fresh snapshot)',
|
|
212
|
+
'err.dragSame': 'start %from and end %to resolve to the same element — be more specific (ref or selector)',
|
|
213
|
+
'err.dragOffscreen': 'end %to is off screen — scroll so that both start and end are visible',
|
|
214
|
+
'err.dragNoTarget': 'there is no element at the end point',
|
|
215
|
+
'res.drag.doneHtml5': 'dragged %from → %to (HTML5 drag and drop%verdict)',
|
|
216
|
+
'res.drag.accepted': '; the target accepted it',
|
|
217
|
+
'res.drag.notAccepted': ', but the target did not report acceptance — check whether the result is right',
|
|
218
|
+
'res.drag.doneCoords': 'dragged %from → %to: (%x1, %y1) → (%x2, %y2)',
|
|
219
|
+
'err.refGone': 'ref %ref is no longer valid (the page changed or navigated) — run browser_read what=snapshot to get new refs',
|
|
220
|
+
'err.snapshotFailed': 'the page did not return a snapshot (it may have just navigated; try again)',
|
|
221
|
+
'res.snap.head': '%count interactive elements ([N] is the ref: pass ref=N to browser_click / browser_input)',
|
|
222
|
+
'res.snap.nothing': '(no interactive elements found)',
|
|
223
|
+
'res.snap.more': '\n…%more more elements are not listed — pass selector to look at part of the page',
|
|
224
|
+
'res.snap.truncated': '\n…(truncated, %n characters in total — pass selector to narrow it down, or raise limit)',
|
|
225
|
+
'err.refNotInt': 'the ref must be a positive integer; got %ref',
|
|
226
|
+
'err.refFocus': 'could not focus ref %n (the element may not be focusable)',
|
|
227
|
+
'err.selectNotSelect': 'not a <select> element',
|
|
228
|
+
'err.selectNoOption': 'no such option',
|
|
229
|
+
'err.selectFailed': 'selection failed: %why%options',
|
|
230
|
+
'err.selectOptions': ' (allowed values: %options)',
|
|
231
|
+
'res.hint.quoted': '"%text"',
|
|
232
|
+
'res.hint.typing': 'typing %n chars',
|
|
233
|
+
'res.hint.key': 'key %key',
|
|
234
|
+
'res.hint.element': 'element %el',
|
|
235
|
+
'res.hint.waitGone': 'wait for gone ',
|
|
236
|
+
'res.hint.url': 'URL %url',
|
|
237
|
+
'res.tabs.agentWindow': ' (DSH work window)',
|
|
238
|
+
'res.tabs.empty': '(no tabs)',
|
|
239
|
+
'res.tabs.footnote': '(* = the page the user is looking at)',
|
|
240
|
+
'res.tabs.noMatch': '(no matching tabs)',
|
|
241
|
+
'res.tabs.agentHint': ' (in a separate DSH work window, opened in the background without disturbing the page the user is looking at)',
|
|
242
|
+
'res.tabs.background': ' (background tab)',
|
|
243
|
+
'res.tabs.opened': 'opened tab %id%where: %url',
|
|
244
|
+
'res.tabs.closed': 'closed tab %id',
|
|
245
|
+
'res.tabs.activated': 'switched to tab %id',
|
|
246
|
+
'res.read.iframeCross': '\n\n[iframe] %src (cross-site frame; its text cannot be read — use browser_screenshot)',
|
|
247
|
+
'res.read.noText': '(the page has no visible text)',
|
|
248
|
+
'res.read.noAttr': '(no such attribute)',
|
|
249
|
+
'res.read.viewport': ' | viewport %w×%h, scrolled %scrollYpx',
|
|
250
|
+
'res.read.dialog': '\n⚠️ a %type dialog is in the way: "%message" — call browser_dialog first to let it through',
|
|
251
|
+
'res.click.atRef': 'clicked [%ref] %tag "%text" @ (%x, %y)',
|
|
252
|
+
'res.click.atRefCount': 'clicked [%ref] %tag "%text" @ (%x, %y) ×%count',
|
|
253
|
+
'res.click.byTag': 'clicked %tag "%text" @ (%x, %y)',
|
|
254
|
+
'res.click.atCoords': 'clicked (%x, %y)',
|
|
255
|
+
'res.input.typedAfterClick': 'typed %n characters (clicked %target first)',
|
|
256
|
+
'res.input.typed': 'typed %n characters',
|
|
257
|
+
'res.input.typedAfterFocus': ' (focused %target first)',
|
|
258
|
+
'res.input.pressedKey': 'pressed key %key',
|
|
259
|
+
'res.input.selected': 'selected "%label" (%value)',
|
|
260
|
+
'res.input.uploaded': 'put %n files into %target',
|
|
261
|
+
'res.input.uploadedChooser': 'handed %n files to the file picker the page just opened',
|
|
262
|
+
'res.input.focused': 'focused %target',
|
|
263
|
+
'res.input.hovered': 'hovered @ (%x, %y)',
|
|
264
|
+
'res.input.hoveredEl': ' %tag "%text"',
|
|
265
|
+
'res.input.scrolled': 'scrolled %dy, scrollY=%scrollY / page height %pageHeight',
|
|
266
|
+
'res.nav.late': ' (the page has not finished loading; use browser_wait to wait if needed)',
|
|
267
|
+
'res.nav.subtitle': ' — %title',
|
|
268
|
+
'res.nav.go': 'reached %url%title%late',
|
|
269
|
+
'res.nav.history': '%verb %url%title%late',
|
|
270
|
+
'res.nav.back': 'went back to',
|
|
271
|
+
'res.nav.forward': 'went forward to',
|
|
272
|
+
'res.nav.reload': 'reloaded',
|
|
273
|
+
'res.shot.note': 'screenshot (%mode, %size) — %where',
|
|
274
|
+
'res.shot.saved': '\n(attachments are unavailable; saved to %file — use read_image to view it)',
|
|
275
|
+
'res.wait.selector': 'waited for %sel @ (%x, %y) "%text", took %ms',
|
|
276
|
+
'res.dialog.accepted': 'dialog accepted',
|
|
277
|
+
'res.dialog.dismissed': 'dialog dismissed',
|
|
278
|
+
'res.dl.warnHtml': '\n⚠️ what was downloaded is a web page (text/html) — most likely a login page or a "download is about to start" interstitial, not the file itself: open it, or use a direct file link',
|
|
279
|
+
'res.dl.done': 'downloaded: %file (%size%type)%warn',
|
|
280
|
+
'res.dl.typePart': ', %type',
|
|
281
|
+
'setup.noVendor': 'the plugin package has no bundled host: reinstall the plugin from the release tarball (README, Install section).',
|
|
282
|
+
'setup.unsupportedPlatform': 'the browser bridge does not support %platform yet (only macOS, Windows and Linux).',
|
|
283
|
+
'setup.regHead': 'the host or the native messaging registration was not written (usually a permissions problem):',
|
|
284
|
+
'setup.regHostDir': 'host directory %dir%mark',
|
|
285
|
+
'setup.regNm': 'registration%kind %file%mark',
|
|
286
|
+
'setup.nmKindWin': ' (registry + file)',
|
|
287
|
+
'setup.nmKindFile': ' file',
|
|
288
|
+
'setup.regTail': 'restart DSH once and it will retry; if that does not help, open an issue on GitHub.',
|
|
289
|
+
'setup.launchFailed': 'Chrome failed to launch the host: %err\nAfter restarting DSH, quit Chrome completely and open it again.',
|
|
290
|
+
'setup.storeHead': 'the extension is installed from the Chrome Web Store (DSH Bridge %version), but the host is not connected:',
|
|
291
|
+
'setup.storeStep1': '1. make sure Chrome is running',
|
|
292
|
+
'setup.storeStep2': '2. DSH Bridge is enabled on chrome://extensions',
|
|
293
|
+
'setup.storeStep3': '3. if that does not help, quit Chrome completely and open it again',
|
|
294
|
+
'setup.storeTail': 'no need to "Load unpacked" — the host and the native registration are already installed automatically.',
|
|
295
|
+
'setup.manualHead': 'one last step for the browser bridge (once), pick one of two ways:',
|
|
296
|
+
'setup.manualStore': '· simplest: install DSH Bridge from the Chrome Web Store (no developer mode):',
|
|
297
|
+
'setup.storeUrl': ' %url',
|
|
298
|
+
'setup.manualUnpacked': '· or load the unpacked extension:',
|
|
299
|
+
'setup.manualStep1': ' 1. open chrome://extensions in Chrome',
|
|
300
|
+
'setup.manualStep2': ' 2. turn on "Developer mode" in the top right corner',
|
|
301
|
+
'setup.manualStep3': ' 3. click "Load unpacked", %paste, and pick this folder:',
|
|
302
|
+
'setup.manualDir': ' %dir',
|
|
303
|
+
'setup.manualTail': 'when it is installed, come back and retry; the host and the native registration are already installed automatically, no script to run.',
|
|
304
|
+
'setup.pasteDarwin': 'press ⌘⇧G in the file picker, paste and hit Enter',
|
|
305
|
+
'setup.pasteWin': 'paste the path into the address bar at the top of the file picker and hit Enter',
|
|
306
|
+
'setup.pasteLinux': 'press Ctrl+L in the file picker, paste and hit Enter',
|
|
307
|
+
'res.read.truncated': '\n…(truncated, %n characters in total)',
|
|
308
|
+
'err.setupProcList': 'the process listing did not finish',
|
|
309
|
+
'err.chromeNotFound': 'Chrome not found',
|
|
157
310
|
}
|
package/i18n/index.js
CHANGED
|
@@ -62,3 +62,20 @@ export function createT(locale, dicts = DICTS) {
|
|
|
62
62
|
return text
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 当前在用的 t():插件启动时由 apply() 按 config.locale 设一次;
|
|
68
|
+
* 其他模块(refs / nav / download / drag / devtools / panel / setup)用 tt() 取文案。
|
|
69
|
+
*/
|
|
70
|
+
let active = createT(DEFAULT_LOCALE)
|
|
71
|
+
|
|
72
|
+
/** 切到指定语言,并把新的 t() 返回出去(apply() 自己还要用)。 */
|
|
73
|
+
export function setLocale(locale) {
|
|
74
|
+
active = createT(locale)
|
|
75
|
+
return active
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 按当前语言取一条文案(模块内部用)。 */
|
|
79
|
+
export function tt(key, vars) {
|
|
80
|
+
return active(key, vars)
|
|
81
|
+
}
|