dsh-chrome-bridge 1.19.0 → 2.0.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 +6 -2
- package/README.md +6 -2
- package/client.js +110 -29
- package/core/ext.js +119 -0
- package/core/hosts.js +277 -0
- package/core/locale.js +8 -0
- package/core/receipt.js +56 -0
- package/core/session.js +157 -0
- package/core/shots.js +56 -0
- package/core/tooldef.js +142 -0
- package/core/transport.js +212 -0
- package/core/upload.js +59 -0
- package/devtools.js +37 -16
- package/download.js +895 -69
- package/drag.js +68 -30
- package/features/frames.js +58 -0
- package/features/gif.js +203 -0
- package/features/index.js +1 -0
- package/features/mock-har.js +85 -0
- package/features/record.js +225 -0
- package/i18n/en.js +312 -16
- package/i18n/index.js +17 -0
- package/i18n/ru.js +312 -16
- package/i18n/zh.js +310 -14
- package/image-guard.js +13 -6
- package/index.js +21 -1073
- package/locale/ru.json +7 -0
- package/nav.js +56 -10
- package/package.json +8 -1
- package/panel.js +14 -4
- package/refs.js +293 -240
- package/setup.js +248 -74
- package/tools/click.js +58 -0
- package/tools/devtools.js +61 -0
- package/tools/dialog.js +22 -0
- package/tools/download.js +50 -0
- package/tools/drag.js +61 -0
- package/tools/eval.js +22 -0
- package/tools/fill.js +77 -0
- package/tools/handoff.js +40 -0
- package/tools/index.js +38 -0
- package/tools/input.js +147 -0
- package/tools/nav.js +57 -0
- package/tools/read.js +87 -0
- package/tools/record.js +120 -0
- package/tools/screenshot.js +223 -0
- package/tools/tabs.js +131 -0
- package/tools/wait.js +56 -0
- package/vendor/cb +616 -35
- package/vendor/extension/_locales/en/messages.json +3 -0
- package/vendor/extension/_locales/ru/messages.json +3 -0
- package/vendor/extension/_locales/zh_CN/messages.json +3 -0
- package/vendor/extension/_locales/zh_TW/messages.json +3 -0
- package/vendor/extension/background.js +2 -1969
- package/vendor/extension/confirm.css +148 -0
- package/vendor/extension/confirm.html +49 -0
- package/vendor/extension/confirm.js +188 -0
- package/vendor/extension/in-page-cursor.js +599 -0
- package/vendor/extension/manifest.json +11 -2
- package/vendor/extension/popup.css +99 -5
- package/vendor/extension/popup.html +28 -2
- package/vendor/extension/popup.js +430 -45
- package/vendor/extension/sw/boot.js +111 -0
- package/vendor/extension/sw/cdp.js +411 -0
- package/vendor/extension/sw/chooser.js +192 -0
- package/vendor/extension/sw/confirm.js +608 -0
- package/vendor/extension/sw/cursor.js +241 -0
- package/vendor/extension/sw/dispatch.js +129 -0
- package/vendor/extension/sw/download.js +279 -0
- package/vendor/extension/sw/fetch-hub.js +224 -0
- package/vendor/extension/sw/frames.js +651 -0
- package/vendor/extension/sw/imaging.js +361 -0
- package/vendor/extension/sw/native.js +111 -0
- package/vendor/extension/sw/net-tools.js +525 -0
- package/vendor/extension/sw/ops.js +829 -0
- package/vendor/extension/sw/popup-api.js +303 -0
- package/vendor/extension/sw/profile.js +166 -0
- package/vendor/extension/sw/record.js +494 -0
- package/vendor/extension/sw/state.js +161 -0
- package/vendor/extension/sw/tabui.js +219 -0
- package/vendor/extension/sw/util.js +166 -0
- package/vendor/extension/sw/welcome.js +26 -0
- package/vendor/extension/sw/windows.js +94 -0
- package/vendor/extension/welcome.css +189 -0
- package/vendor/extension/welcome.html +70 -0
- package/vendor/extension/welcome.js +157 -0
- package/vendor/host/host.js +476 -71
- package/vendor/in-page-cursor.js +309 -37
- package/vendor/skill/SKILL.md +34 -16
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process'
|
|
2
|
+
import crypto from 'node:crypto'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { shotRefs } from '../core/shots.js'
|
|
6
|
+
import { safeName, uniquePath } from '../download.js'
|
|
7
|
+
import { tt } from '../i18n/index.js'
|
|
8
|
+
import { encodeGif } from './gif.js'
|
|
9
|
+
|
|
10
|
+
const { O_WRONLY, O_CREAT, O_EXCL, O_NOFOLLOW } = fs.constants
|
|
11
|
+
const NOFOLLOW = O_NOFOLLOW || 0
|
|
12
|
+
|
|
13
|
+
function stamp(date = new Date()) {
|
|
14
|
+
const p = (n) => String(n).padStart(2, '0')
|
|
15
|
+
return `${date.getFullYear()}${p(date.getMonth() + 1)}${p(date.getDate())}-${p(date.getHours())}${p(date.getMinutes())}${p(date.getSeconds())}`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function mediaName(filename, format) {
|
|
19
|
+
const ext = `.${format}`
|
|
20
|
+
let name = safeName(filename) || `browser-recording-${stamp()}`
|
|
21
|
+
if (name.toLowerCase().endsWith(ext)) return name
|
|
22
|
+
if (/\.(?:gif|mp4|webm)$/i.test(name)) name = name.replace(/\.(?:gif|mp4|webm)$/i, '')
|
|
23
|
+
else if (!/\.[a-z0-9]{1,12}$/i.test(name)) return `${name}${ext}`
|
|
24
|
+
return `${name}${ext}`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function writeExclusive(dir, name, data) {
|
|
28
|
+
for (let i = 0; i < 1000; i++) {
|
|
29
|
+
const candidate = uniquePath(dir, name)
|
|
30
|
+
let fd
|
|
31
|
+
try {
|
|
32
|
+
fd = fs.openSync(candidate, O_WRONLY | O_CREAT | O_EXCL | NOFOLLOW, 0o600)
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (error && error.code === 'EEXIST') continue
|
|
35
|
+
throw error
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
fs.writeFileSync(fd, data)
|
|
39
|
+
return candidate
|
|
40
|
+
} catch (error) {
|
|
41
|
+
try { fs.unlinkSync(candidate) } catch {}
|
|
42
|
+
throw error
|
|
43
|
+
} finally {
|
|
44
|
+
try { fs.closeSync(fd) } catch {}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
throw new Error(tt('err.recordName'))
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function frameDelays(frames, fps = 3, durationMs = 0) {
|
|
51
|
+
const list = Array.isArray(frames) ? frames : []
|
|
52
|
+
const nominal = 1000 / Math.max(1, Number(fps) || 3)
|
|
53
|
+
return list.map((frame, index) => {
|
|
54
|
+
const at = Number(frame.atMs) || 0
|
|
55
|
+
let ms
|
|
56
|
+
if (index + 1 < list.length) ms = (Number(list[index + 1].atMs) || 0) - at
|
|
57
|
+
else ms = Math.max(Number(durationMs) - at, nominal)
|
|
58
|
+
if (!Number.isFinite(ms) || ms <= 0) ms = nominal
|
|
59
|
+
return Math.max(2, Math.min(65535, Math.round(ms / 10)))
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function encodeRecordingGif(result, fps = 3) {
|
|
64
|
+
const width = Math.round(Number(result && result.width))
|
|
65
|
+
const height = Math.round(Number(result && result.height))
|
|
66
|
+
const frames = Array.isArray(result && result.frames) ? result.frames : []
|
|
67
|
+
if (!frames.length) throw new Error(tt('err.recordEmpty'))
|
|
68
|
+
if (!width || !height) throw new Error(tt('err.recordPixels'))
|
|
69
|
+
const delays = frameDelays(frames, fps, result.durationMs)
|
|
70
|
+
const gifFrames = frames.map((frame, index) => {
|
|
71
|
+
if (!frame.rgb && !frame.rgba) throw new Error(tt('err.recordPixels'))
|
|
72
|
+
return { ...(frame.rgb ? { rgb: frame.rgb } : { rgba: frame.rgba }), delayCs: delays[index] }
|
|
73
|
+
})
|
|
74
|
+
return encodeGif({ width, height, frames: gifFrames, loop: 0 })
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function ffmpegAvailable(run = execFileSync) {
|
|
78
|
+
try {
|
|
79
|
+
run('ffmpeg', ['-version'], { stdio: 'ignore', timeout: 5000, windowsHide: true })
|
|
80
|
+
return true
|
|
81
|
+
} catch {
|
|
82
|
+
return false
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function inputRate(result, fps) {
|
|
87
|
+
const frames = Array.isArray(result.frames) ? result.frames.length : 0
|
|
88
|
+
const seconds = Number(result.durationMs) / 1000
|
|
89
|
+
if (!frames || !Number.isFinite(seconds) || seconds <= 0) return Math.max(1, Number(fps) || 3)
|
|
90
|
+
return Math.max(1, Math.min(30, frames / seconds))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function copyExclusive(source, dest) {
|
|
94
|
+
const out = fs.openSync(dest, O_WRONLY | O_CREAT | O_EXCL | NOFOLLOW, 0o600)
|
|
95
|
+
let input
|
|
96
|
+
try {
|
|
97
|
+
input = fs.openSync(source, fs.constants.O_RDONLY)
|
|
98
|
+
const buf = Buffer.allocUnsafe(1024 * 1024)
|
|
99
|
+
for (;;) {
|
|
100
|
+
const n = fs.readSync(input, buf, 0, buf.length, null)
|
|
101
|
+
if (!n) break
|
|
102
|
+
let off = 0
|
|
103
|
+
while (off < n) off += fs.writeSync(out, buf, off, n - off)
|
|
104
|
+
}
|
|
105
|
+
return dest
|
|
106
|
+
} catch (error) {
|
|
107
|
+
try { fs.unlinkSync(dest) } catch {}
|
|
108
|
+
throw error
|
|
109
|
+
} finally {
|
|
110
|
+
try { if (input !== undefined) fs.closeSync(input) } catch {}
|
|
111
|
+
try { fs.closeSync(out) } catch {}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function publishExclusive(temp, dir, name) {
|
|
116
|
+
const ext = path.extname(name)
|
|
117
|
+
const base = name.slice(0, name.length - ext.length)
|
|
118
|
+
for (let i = 0; i < 1000; i++) {
|
|
119
|
+
const file = path.join(dir, i ? `${base} (${i})${ext}` : name)
|
|
120
|
+
try {
|
|
121
|
+
fs.linkSync(temp, file)
|
|
122
|
+
return file
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (!error || error.code === 'EEXIST') continue
|
|
125
|
+
if (!['EXDEV', 'ENOTSUP', 'EPERM'].includes(error.code)) throw error
|
|
126
|
+
try {
|
|
127
|
+
copyExclusive(temp, file)
|
|
128
|
+
return file
|
|
129
|
+
} catch (copyError) {
|
|
130
|
+
if (!copyError || copyError.code !== 'EEXIST') throw copyError
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
throw new Error(tt('err.recordName'))
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function encodeVideo(result, { dir, filename, format, fps, run }) {
|
|
138
|
+
const frames = Array.isArray(result.frames) ? result.frames : []
|
|
139
|
+
if (!frames.length) throw new Error(tt('err.recordEmpty'))
|
|
140
|
+
const input = Buffer.concat(frames.map(frame => Buffer.from(frame.jpeg || '', 'base64')))
|
|
141
|
+
if (!input.length) throw new Error(tt('err.recordEmpty'))
|
|
142
|
+
const name = mediaName(filename, format)
|
|
143
|
+
const temp = path.join(dir, `.dsh-record-${crypto.randomUUID()}.${format}`)
|
|
144
|
+
const rate = inputRate(result, fps).toFixed(3).replace(/\.0+$/, '').replace(/(\.\d*?)0+$/, '$1')
|
|
145
|
+
const video = format === 'mp4'
|
|
146
|
+
? ['-c:v', 'libx264', '-pix_fmt', 'yuv420p', '-vf', 'scale=trunc(iw/2)*2:trunc(ih/2)*2', '-movflags', '+faststart']
|
|
147
|
+
: ['-c:v', 'libvpx-vp9', '-pix_fmt', 'yuv420p', '-deadline', 'realtime', '-cpu-used', '5', '-b:v', '0', '-crf', '34']
|
|
148
|
+
const args = [
|
|
149
|
+
'-hide_banner', '-loglevel', 'error', '-y',
|
|
150
|
+
'-f', 'image2pipe', '-c:v', 'mjpeg', '-framerate', rate, '-i', 'pipe:0',
|
|
151
|
+
'-frames:v', String(frames.length), '-an', ...video, temp,
|
|
152
|
+
]
|
|
153
|
+
try {
|
|
154
|
+
run('ffmpeg', args, { input, stdio: ['pipe', 'ignore', 'pipe'], timeout: 120000, windowsHide: true, maxBuffer: 1024 * 1024 })
|
|
155
|
+
fs.chmodSync(temp, 0o600)
|
|
156
|
+
return publishExclusive(temp, dir, name)
|
|
157
|
+
} finally {
|
|
158
|
+
try { fs.unlinkSync(temp) } catch {}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function saveGif(result, { dir, filename, fps }) {
|
|
163
|
+
const gif = encodeRecordingGif(result, fps)
|
|
164
|
+
return writeExclusive(dir, mediaName(filename, 'gif'), gif)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export async function saveRecording(result, {
|
|
168
|
+
format = 'gif',
|
|
169
|
+
fps = 3,
|
|
170
|
+
dir,
|
|
171
|
+
filename,
|
|
172
|
+
run = execFileSync,
|
|
173
|
+
} = {}) {
|
|
174
|
+
if (!dir || !path.isAbsolute(dir)) throw new Error(tt('err.recordDir'))
|
|
175
|
+
const requested = format === 'mp4' || format === 'webm' ? format : 'gif'
|
|
176
|
+
let file
|
|
177
|
+
let actual = requested
|
|
178
|
+
let fallback = ''
|
|
179
|
+
if (requested === 'gif') {
|
|
180
|
+
file = saveGif(result, { dir, filename, fps })
|
|
181
|
+
} else if (!ffmpegAvailable(run)) {
|
|
182
|
+
fallback = 'missing'
|
|
183
|
+
actual = 'gif'
|
|
184
|
+
file = saveGif(result, { dir, filename, fps })
|
|
185
|
+
} else {
|
|
186
|
+
try {
|
|
187
|
+
file = encodeVideo(result, { dir, filename, format: requested, fps, run })
|
|
188
|
+
} catch {
|
|
189
|
+
fallback = 'failed'
|
|
190
|
+
actual = 'gif'
|
|
191
|
+
file = saveGif(result, { dir, filename, fps })
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const size = fs.statSync(file).size
|
|
195
|
+
return {
|
|
196
|
+
file,
|
|
197
|
+
size,
|
|
198
|
+
format: actual,
|
|
199
|
+
requestedFormat: requested,
|
|
200
|
+
fallback,
|
|
201
|
+
count: Math.round(Number(result.count) || (result.frames || []).length || 0),
|
|
202
|
+
durationMs: Math.round(Number(result.durationMs) || 0),
|
|
203
|
+
width: Math.round(Number(result.width) || 0),
|
|
204
|
+
height: Math.round(Number(result.height) || 0),
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export async function saveContactPreview(contactSheet, getAttachments) {
|
|
209
|
+
if (!contactSheet || !contactSheet.data || typeof getAttachments !== 'function') return ''
|
|
210
|
+
const attachments = getAttachments()
|
|
211
|
+
if (!attachments || typeof attachments.saveImages !== 'function') return ''
|
|
212
|
+
try {
|
|
213
|
+
const [ref] = await attachments.saveImages([{
|
|
214
|
+
data: Buffer.from(contactSheet.data, 'base64'),
|
|
215
|
+
mediaType: 'image/jpeg',
|
|
216
|
+
name: `recording-contact-${Date.now()}.jpg`,
|
|
217
|
+
}])
|
|
218
|
+
const token = crypto.randomUUID()
|
|
219
|
+
shotRefs.set(token, ref)
|
|
220
|
+
if (shotRefs.size > 20) shotRefs.delete(shotRefs.keys().next().value)
|
|
221
|
+
return token
|
|
222
|
+
} catch {
|
|
223
|
+
return ''
|
|
224
|
+
}
|
|
225
|
+
}
|