dsh-site-bridge 0.6.1 → 0.6.3

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.
@@ -2,7 +2,7 @@
2
2
  "manifest_version": 3,
3
3
  "default_locale": "en",
4
4
  "name": "__MSG_appName__",
5
- "version": "0.6.1",
5
+ "version": "0.6.3",
6
6
  "description": "__MSG_appDesc__",
7
7
  "minimum_chrome_version": "116",
8
8
  "permissions": [
package/extension/sw.js CHANGED
@@ -294,6 +294,25 @@ async function claimTab(tabId) {
294
294
  return attach(id)
295
295
  }
296
296
 
297
+ chrome.tabs.onUpdated.addListener((tabId, info, tab) => {
298
+ const session = state.sessions.get(tabId)
299
+ if (!session) return
300
+ const next = { id: tab.id, url: tab.url, title: tab.title }
301
+ if (next.title === session.target.title && next.url === session.target.url) return
302
+ session.target = next
303
+ void evt('target', { tab: next, tabId })
304
+ })
305
+
306
+ chrome.tabs.onRemoved.addListener((tabId) => {
307
+ if (!state.sessions.has(tabId)) return
308
+ state.sessions.delete(tabId)
309
+ if (state.activeTabId === tabId) {
310
+ state.activeTabId = state.sessions.size > 0 ? [...state.sessions.keys()][0] : null
311
+ }
312
+ void evt('target', { tab: null, tabId })
313
+ void evt('active', { tabId: state.activeTabId })
314
+ })
315
+
297
316
  chrome.debugger.onDetach.addListener((source, reason) => {
298
317
  const session = state.sessions.get(source.tabId)
299
318
  if (!session) return
@@ -1502,10 +1521,31 @@ async function dispatch(op, args) {
1502
1521
  const active = activeSession()
1503
1522
  return { target: active?.target ?? null, attached: state.activeTabId, tabs: [...state.sessions.keys()] }
1504
1523
  }
1524
+ case 'tab.close': {
1525
+ const id = Number(args.tabId ?? state.activeTabId)
1526
+ if (!Number.isFinite(id)) throw new Error('нечего закрывать: передайте tabId')
1527
+ await detach(id).catch(() => {})
1528
+ await chrome.tabs.remove(id)
1529
+ return { closed: id }
1530
+ }
1505
1531
  case 'tab.open': {
1506
1532
  const tab = await chrome.tabs.create({ url: String(args.url ?? 'about:blank'), active: args.active !== false })
1507
1533
  await attach(tab.id)
1508
- return { target: state.sessions.get(tab.id)?.target ?? { id: tab.id, url: tab.url, title: tab.title } }
1534
+ // A fresh tab has no title yet: wait for the load so the caller gets a
1535
+ // target it can show, instead of an empty string.
1536
+ const deadline = Date.now() + Math.min(Number(args.waitMs ?? 10000), 30000)
1537
+ let info = tab
1538
+ while (Date.now() < deadline) {
1539
+ info = await chrome.tabs.get(tab.id).catch(() => info)
1540
+ if (info.status === 'complete' && info.title) break
1541
+ await sleep(150)
1542
+ }
1543
+ const session = state.sessions.get(tab.id)
1544
+ if (session) {
1545
+ session.target = { id: info.id, url: info.url, title: info.title }
1546
+ await evt('target', { tab: session.target, tabId: tab.id })
1547
+ }
1548
+ return { target: session?.target ?? { id: tab.id, url: tab.url, title: tab.title } }
1509
1549
  }
1510
1550
  case 'tab.focus': {
1511
1551
  const session = requireSession(args.tabId)
package/lib/index.js CHANGED
@@ -261,7 +261,7 @@ export function apply(ctx, config) {
261
261
  'claim добавляет ещё одну, use переключает активную, release отключает, open открывает новую и сразу ' +
262
262
  'подключает её, focus выводит вкладку на передний план. Вкладка должна быть http(s) или file://.',
263
263
  {
264
- action: { type: 'string', description: 'list | claim | use | release | open | focus' },
264
+ action: { type: 'string', description: 'list | claim | use | release | open | close | focus' },
265
265
  tabId: { type: 'number', description: 'id вкладки для claim / use / release / focus (из action=list)' },
266
266
  url: { type: 'string', description: 'адрес для action=open (по умолчанию about:blank)' }
267
267
  },
@@ -277,6 +277,12 @@ export function apply(ctx, config) {
277
277
  const target = result?.target ?? null
278
278
  return ok(`Открыта и подключена вкладка: ${target?.title || ''} — ${target?.url || ''}`, { target })
279
279
  }
280
+ if (action === 'close') {
281
+ const tabId = Number(args.tabId ?? instance.state().activeTabId)
282
+ if (!Number.isFinite(tabId)) throw new Error('нечего закрывать: передайте tabId')
283
+ await instance.enqueue('tab.close', { tabId }, { timeout: 20000 })
284
+ return ok(`Вкладка ${tabId} закрыта.`, { tabId })
285
+ }
280
286
  if (action === 'focus') {
281
287
  const tabId = Number(args.tabId ?? instance.state().activeTabId)
282
288
  if (!Number.isFinite(tabId)) throw new Error('нечего выводить на передний план: нет подключённой вкладки')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-site-bridge",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Chrome/Edge MV3 bridge for DeepSeek Harness: capture page markup (DOM, styles, selectors) and BFF traffic (xhr/fetch with headers and bodies) into a workspace snapshot bundle, drive the page with trusted CDP input, and verify injected scripts. Authorization never leaves the browser and is never written to disk.",
5
5
  "icon": "./icon.svg",
6
6
  "type": "module",