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
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { S } from './state.js'
|
|
2
|
+
|
|
3
|
+
export function waitPhase(wait) {
|
|
4
|
+
if (wait === true) return 'load'
|
|
5
|
+
if (wait === false) return 'none'
|
|
6
|
+
if (!['none', 'dom', 'load', 'idle'].includes(wait)) throw new Error('Invalid lifecycle wait')
|
|
7
|
+
return wait
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Subscribe before navigating. CDP may deliver events before Page.navigate's reply.
|
|
11
|
+
export function watchLifecycle(id, phase, deadline) {
|
|
12
|
+
const entries = S.loadWaiters.get(id) || new Set()
|
|
13
|
+
const buffered = []
|
|
14
|
+
const priorLoader = S.mainDocuments.get(id)?.loaderId || null
|
|
15
|
+
let bound, latestRebind, done, resolve, timer, stable, idlePoll, dom = false, loaded = false, loadAt = 0, postLoadIdle = false
|
|
16
|
+
const promise = new Promise(r => { resolve = r })
|
|
17
|
+
function finish(value) {
|
|
18
|
+
if (done) return
|
|
19
|
+
done = true
|
|
20
|
+
clearTimeout(timer)
|
|
21
|
+
clearTimeout(stable)
|
|
22
|
+
clearInterval(idlePoll)
|
|
23
|
+
entries.delete(entry)
|
|
24
|
+
if (!entries.size) S.loadWaiters.delete(id)
|
|
25
|
+
resolve(value)
|
|
26
|
+
}
|
|
27
|
+
function hasPendingNetwork() {
|
|
28
|
+
return [...S.netPending.values()].some(r => r.tabId === id && !['EventSource', 'WebSocket'].includes(r.type))
|
|
29
|
+
}
|
|
30
|
+
function isNetworkQuiet() {
|
|
31
|
+
return !hasPendingNetwork() && Date.now() - Math.max(S.netChanged.get(id) || 0, loadAt) >= 500
|
|
32
|
+
}
|
|
33
|
+
function observe(name, frameId, loaderId) {
|
|
34
|
+
if (done) return
|
|
35
|
+
if (!bound) {
|
|
36
|
+
if (buffered.length < 256) buffered.push([name, frameId, loaderId])
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
if ((bound.frameId && frameId !== bound.frameId) || (bound.loaderId && loaderId !== bound.loaderId)) return
|
|
40
|
+
if (name === 'networkIdle' && loaded) postLoadIdle = true
|
|
41
|
+
if (name === 'DOMContentLoaded') dom = true
|
|
42
|
+
if (name === 'load') { dom = true; if (!loaded) { loaded = true; loadAt = Date.now(); postLoadIdle = false } }
|
|
43
|
+
if (phase === 'load') { if (loaded) finish(true); return }
|
|
44
|
+
if (phase === 'idle') {
|
|
45
|
+
if (!loaded) return
|
|
46
|
+
if (!hasPendingNetwork() && (postLoadIdle || isNetworkQuiet())) { finish(true); return }
|
|
47
|
+
if (!idlePoll) {
|
|
48
|
+
idlePoll = setInterval(() => {
|
|
49
|
+
if (!hasPendingNetwork() && (postLoadIdle || isNetworkQuiet())) finish(true)
|
|
50
|
+
}, 50)
|
|
51
|
+
}
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
if (!dom) return
|
|
55
|
+
if (!stable) stable = setTimeout(() => finish(true), Math.min(150, Math.max(0, deadline - Date.now())))
|
|
56
|
+
}
|
|
57
|
+
function rebind(frameId, loaderId) {
|
|
58
|
+
if (done || !frameId || !loaderId) return
|
|
59
|
+
if (priorLoader && loaderId === priorLoader) return
|
|
60
|
+
if (!bound) { latestRebind = { frameId, loaderId }; return }
|
|
61
|
+
if (frameId !== bound.frameId || loaderId === bound.loaderId) return
|
|
62
|
+
bound = { frameId, loaderId }
|
|
63
|
+
dom = false
|
|
64
|
+
loaded = false
|
|
65
|
+
loadAt = 0
|
|
66
|
+
postLoadIdle = false
|
|
67
|
+
clearTimeout(stable)
|
|
68
|
+
stable = null
|
|
69
|
+
clearInterval(idlePoll)
|
|
70
|
+
idlePoll = null
|
|
71
|
+
}
|
|
72
|
+
const entry = { finish, observe, rebind }
|
|
73
|
+
entries.add(entry)
|
|
74
|
+
S.loadWaiters.set(id, entries)
|
|
75
|
+
timer = setTimeout(() => finish(phase === 'dom' && dom), Math.max(0, deadline - Date.now()))
|
|
76
|
+
return { finish, promise, bind(frame) {
|
|
77
|
+
bound = latestRebind && latestRebind.frameId === frame.frameId ? latestRebind : frame
|
|
78
|
+
latestRebind = null
|
|
79
|
+
for (const args of buffered) observe(...args)
|
|
80
|
+
buffered.length = 0
|
|
81
|
+
} }
|
|
82
|
+
}
|