dsh-chrome-bridge 2.0.2 → 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 +44 -15
- 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 +118 -36
- package/features/frames.js +5 -2
- package/i18n/en.js +37 -7
- package/i18n/ru.js +37 -7
- package/i18n/zh.js +37 -7
- package/nav.js +103 -32
- package/package.json +1 -1
- package/refs.js +317 -77
- package/tools/batch.js +311 -0
- package/tools/click.js +37 -11
- package/tools/dialog.js +19 -2
- package/tools/drag.js +52 -9
- 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/screenshot.js +10 -1
- package/tools/tabs.js +16 -2
- package/tools/wait.js +14 -6
- package/vendor/cb +3 -2
- package/vendor/extension/in-page-cursor.js +49 -11
- 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 +7 -1
- package/vendor/extension/sw/cdp.js +219 -33
- package/vendor/extension/sw/conditions.js +176 -0
- package/vendor/extension/sw/confirm.js +39 -7
- package/vendor/extension/sw/cursor.js +534 -49
- package/vendor/extension/sw/dispatch.js +43 -8
- package/vendor/extension/sw/frames.js +643 -49
- package/vendor/extension/sw/imaging.js +35 -17
- package/vendor/extension/sw/lifecycle.js +82 -0
- package/vendor/extension/sw/ops.js +1028 -148
- package/vendor/extension/sw/page-access.js +292 -0
- package/vendor/extension/sw/popup-api.js +42 -10
- package/vendor/extension/sw/record.js +22 -5
- package/vendor/extension/sw/snapshot.js +251 -0
- package/vendor/extension/sw/state.js +24 -5
- package/vendor/extension/sw/tabui.js +10 -2
- package/vendor/in-page-cursor.js +49 -11
- package/vendor/skill/SKILL.md +8 -7
|
@@ -27,8 +27,9 @@ const NO_TAB = 0
|
|
|
27
27
|
*/
|
|
28
28
|
const GATED_OPS = new Set([
|
|
29
29
|
'click', 'clickEl', 'clickText', 'type', 'key', 'select', 'upload', 'focus', 'hover', 'scroll',
|
|
30
|
-
'nav', 'eval', 'cdp', 'clickAndDownload', 'dialog', 'open', 'info',
|
|
30
|
+
'nav', 'historyNav', 'eval', 'cdp', 'clickAndDownload', 'dialog', 'open', 'info',
|
|
31
31
|
'text', 'html', 'attr', 'shot', 'shotMarked', 'waitFor', 'network', 'networkIdle', 'console', 'screencast',
|
|
32
|
+
'act', 'dragGesture', 'waitCondition', 'snapshotScan',
|
|
32
33
|
'mockSet', 'harStart', 'harExport',
|
|
33
34
|
'frameSnapshot', 'frameTexts', 'frameLocate', 'frameSetField', 'frameSelect',
|
|
34
35
|
'recordStart', 'recordStop', 'recordClip',
|
|
@@ -46,6 +47,7 @@ function fresh() {
|
|
|
46
47
|
writes: Promise.resolve(),
|
|
47
48
|
/** tabId → Map(origin → 到期时刻) */
|
|
48
49
|
grants: new Map(),
|
|
50
|
+
frameCache: new Map(),
|
|
49
51
|
/** 确认 id → entry */
|
|
50
52
|
pending: new Map(),
|
|
51
53
|
/** `${tabId}|${origin}` → entry:同一处并发的请求共用一个确认窗 */
|
|
@@ -146,6 +148,7 @@ function restoreProtectedSites() {
|
|
|
146
148
|
C.sites = sanitizeList(v && v.protectedSites)
|
|
147
149
|
C.loaded = true
|
|
148
150
|
C.loadFailed = false
|
|
151
|
+
S.protectedListEpoch = (S.protectedListEpoch || 0) + 1
|
|
149
152
|
}, (e) => {
|
|
150
153
|
if (C.ready !== job) return
|
|
151
154
|
log('读受保护网站清单失败:', String((e && e.message) || e))
|
|
@@ -187,8 +190,9 @@ function serial(fn) {
|
|
|
187
190
|
async function save(next) {
|
|
188
191
|
const prev = C.sites
|
|
189
192
|
C.sites = next // 先改内存:存储的 onChanged 回调一比就知道是我们自己写的
|
|
193
|
+
S.protectedListEpoch = (S.protectedListEpoch || 0) + 1
|
|
190
194
|
try { await chrome.storage.local.set({ protectedSites: next }) }
|
|
191
|
-
catch (e) { C.sites = prev; throw e }
|
|
195
|
+
catch (e) { C.sites = prev; S.protectedListEpoch = (S.protectedListEpoch || 0) + 1; throw e }
|
|
192
196
|
}
|
|
193
197
|
|
|
194
198
|
async function addProtectedSite(input) {
|
|
@@ -361,6 +365,7 @@ const DENY_WHY = {
|
|
|
361
365
|
const deniedError = (r) => new Error(`USER_DENIED_SENSITIVE ${(DENY_WHY[r.reason] || DENY_WHY.denied).replace('%h', r.host || '')}`)
|
|
362
366
|
|
|
363
367
|
const CROSS_FRAME_OPS = new Set([
|
|
368
|
+
'act', 'dragGesture', 'waitCondition', 'snapshotScan',
|
|
364
369
|
'shot', 'shotMarked', 'screencast', 'recordStart', 'recordClip',
|
|
365
370
|
'frameSnapshot', 'frameTexts', 'frameLocate', 'frameSetField', 'frameSelect',
|
|
366
371
|
])
|
|
@@ -370,7 +375,7 @@ const isCrossFrameOp = (op, args = {}) =>
|
|
|
370
375
|
const addOrigin = (set, url) => { const o = url ? originOf(url) : ''; if (o) set.add(o) }
|
|
371
376
|
|
|
372
377
|
/** 标签页里所有子帧(含跨站 iframe)的网址;返回 { ok, urls },API 缺失 / 空结果 / 超时 / 报错一律 ok=false */
|
|
373
|
-
async function
|
|
378
|
+
async function probeFrameUrls(tabId) {
|
|
374
379
|
if (!chrome.scripting?.executeScript) return { ok: false, urls: [] }
|
|
375
380
|
let timer
|
|
376
381
|
try {
|
|
@@ -387,14 +392,31 @@ async function frameUrls(tabId) {
|
|
|
387
392
|
} finally { clearTimeout(timer) }
|
|
388
393
|
}
|
|
389
394
|
|
|
395
|
+
async function frameUrls(tabId, fresh = false, attempt = 0) {
|
|
396
|
+
// Detached tabs have no CDP invalidation stream. Never reuse their observations.
|
|
397
|
+
if (!S.attached.has(tabId)) return probeFrameUrls(tabId)
|
|
398
|
+
const prior = C.frameCache.get(tabId)
|
|
399
|
+
if (!fresh && prior && prior.expires > Date.now()) return prior.promise
|
|
400
|
+
const entry = { expires: Date.now() + 1000 }
|
|
401
|
+
C.frameCache.set(tabId, entry)
|
|
402
|
+
entry.promise = probeFrameUrls(tabId).then(result => {
|
|
403
|
+
if (C.frameCache.get(tabId) !== entry) {
|
|
404
|
+
return attempt < 1 ? frameUrls(tabId, true, attempt + 1) : { ok: false, urls: [] }
|
|
405
|
+
}
|
|
406
|
+
if (!result.ok) C.frameCache.delete(tabId)
|
|
407
|
+
return result
|
|
408
|
+
})
|
|
409
|
+
return entry.promise
|
|
410
|
+
}
|
|
411
|
+
|
|
390
412
|
/** 清单非空时检查该标签页全部框架(含跨进程 OOPIF)是否均允许访问;无法核实时 fail-closed 返回 false */
|
|
391
|
-
async function areAllFramesAllowed(tabId) {
|
|
413
|
+
async function areAllFramesAllowed(tabId, autoObserve = false, fresh = false) {
|
|
392
414
|
if (!hasProtectedSites()) return true
|
|
393
415
|
const id = Number(tabId)
|
|
394
416
|
if (!Number.isInteger(id)) return false
|
|
395
|
-
const probed = await frameUrls(id)
|
|
417
|
+
const probed = await frameUrls(id, fresh)
|
|
396
418
|
if (!probed.ok) return false
|
|
397
|
-
return probed.urls.every((u)
|
|
419
|
+
return probed.urls.every(u => autoObserve ? !matchesProtectedSite(u) && isUrlAllowed(id, u) : isUrlAllowed(id, u))
|
|
398
420
|
}
|
|
399
421
|
|
|
400
422
|
/** 这个操作会碰到哪些网址:标签页现在的(和正在去的)地址、它的所有子帧,加上 nav / cdp / 新操作参数里指着的地址 */
|
|
@@ -442,7 +464,7 @@ async function recheck(tabId, pageOrigins, host, strict = true, op = '', args =
|
|
|
442
464
|
throw deniedError({ reason: 'navigated', host })
|
|
443
465
|
}
|
|
444
466
|
if (strict && C.sites.length && isCrossFrameOp(op, args)) {
|
|
445
|
-
const probed = await frameUrls(tabId)
|
|
467
|
+
const probed = await frameUrls(tabId, true)
|
|
446
468
|
if (!probed.ok) throw new Error('USER_DENIED_SENSITIVE 放行后无法复核内嵌框架来源,本次操作已取消')
|
|
447
469
|
for (const u of probed.urls) {
|
|
448
470
|
if (matchesProtectedSite(u) && !hasGrant(tabId, originOf(u)))
|
|
@@ -460,6 +482,7 @@ async function gate({ op, args = {}, client } = {}) {
|
|
|
460
482
|
// 每个请求前先把清单读到(读到过就是现成的,不花时间):后面的操作里 hasProtectedSites / isUrlAllowed 才准
|
|
461
483
|
await loadProtectedSites()
|
|
462
484
|
if (!GATED_OPS.has(op)) return
|
|
485
|
+
if (op === 'snapshotScan' && args.autoObserve === true) return // silent read is checked before and after scanning
|
|
463
486
|
await ready()
|
|
464
487
|
if (!C.sites.length || S.paused) return // 暂停了交给后面的暂停检查直接拒,不弹窗
|
|
465
488
|
const tabId = args.tabId != null && args.tabId !== '' ? Number(args.tabId) : null
|
|
@@ -552,7 +575,10 @@ function resolveConfirmation({ id, nonce, allow } = {}, sender) {
|
|
|
552
575
|
|
|
553
576
|
function onTabUpdated(tabId, change) {
|
|
554
577
|
if (!change || !change.url) return
|
|
578
|
+
C.frameCache.delete(tabId)
|
|
555
579
|
const now = originOf(change.url)
|
|
580
|
+
const prevSecret = S.recentSecrets.get(tabId)
|
|
581
|
+
if (prevSecret && prevSecret.origin !== now) S.recentSecrets.delete(tabId)
|
|
556
582
|
const m = C.grants.get(tabId)
|
|
557
583
|
if (m) for (const o of [...m.keys()]) if (o !== now) m.delete(o) // 离开了那个 origin:放行作废
|
|
558
584
|
// 等确认期间换到了别的 origin:用户看到的那一页已经不在了,确认按拒绝收掉、关窗
|
|
@@ -562,6 +588,8 @@ function onTabUpdated(tabId, change) {
|
|
|
562
588
|
}
|
|
563
589
|
|
|
564
590
|
function onTabRemoved(tabId) {
|
|
591
|
+
C.frameCache.delete(tabId)
|
|
592
|
+
S.recentSecrets.delete(tabId)
|
|
565
593
|
revokeTabGrants(tabId, 'tabClosed')
|
|
566
594
|
}
|
|
567
595
|
|
|
@@ -571,6 +599,7 @@ function onWindowRemoved(windowId) {
|
|
|
571
599
|
|
|
572
600
|
/** 调试器断开:空闲自动断开(idle)不算解绑,放行留着;别的(主动解绑、用户点掉调试提示条、标签页没了……)一律作废 */
|
|
573
601
|
function onDebuggerDetached(tabId, reason) {
|
|
602
|
+
C.frameCache.delete(tabId)
|
|
574
603
|
if (reason === 'idle') return
|
|
575
604
|
revokeTabGrants(tabId, reason === 'target_closed' ? 'tabClosed' : 'detached')
|
|
576
605
|
}
|
|
@@ -585,6 +614,9 @@ function initConfirm() {
|
|
|
585
614
|
if (C.unhook) return
|
|
586
615
|
restoreProtectedSites()
|
|
587
616
|
C.unhook = subscribe(S.preHooks, gate)
|
|
617
|
+
C.listeners.push(subscribe(S.cdpEvents, (src, method) => {
|
|
618
|
+
if (['Page.frameAttached', 'Page.frameNavigated', 'Page.frameDetached', 'Page.navigatedWithinDocument'].includes(method)) C.frameCache.delete(src.tabId)
|
|
619
|
+
}))
|
|
588
620
|
C.listeners.push(subscribe(S.tabDetached, onDebuggerDetached))
|
|
589
621
|
listen(chrome.tabs && chrome.tabs.onUpdated, onTabUpdated)
|
|
590
622
|
listen(chrome.tabs && chrome.tabs.onRemoved, onTabRemoved)
|