dsh-chrome-use 0.4.0 → 0.4.1
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/extension/controller.js +30 -7
- package/extension/manifest.json +1 -1
- package/package.json +1 -1
- package/src/client.js +1 -1
package/extension/controller.js
CHANGED
|
@@ -115,6 +115,8 @@ export class BrowserController {
|
|
|
115
115
|
const state = this.attached.get(tabId);
|
|
116
116
|
if (!state) return;
|
|
117
117
|
if (method.startsWith('Network.')) state.lastNetworkActivity = Date.now();
|
|
118
|
+
if (method === 'Network.requestWillBeSent') { state.networkRequests.set(params.requestId, params.request?.url ?? ''); state.networkInFlight = state.networkRequests.size; }
|
|
119
|
+
if (method === 'Network.loadingFinished' || method === 'Network.loadingFailed') { state.networkRequests.delete(params.requestId); state.networkInFlight = state.networkRequests.size; }
|
|
118
120
|
if (method === 'Page.loadEventFired' && state.loadResolve) { const resolve = state.loadResolve; state.loadResolve = null; resolve(true); }
|
|
119
121
|
if (method === 'Page.javascriptDialogOpening') state.dialog = { type: params.type, message: clip(params.message, 2000), defaultPrompt: clip(params.defaultPrompt, 1000) };
|
|
120
122
|
if (method === 'Page.javascriptDialogClosed') state.dialog = null;
|
|
@@ -152,7 +154,7 @@ export class BrowserController {
|
|
|
152
154
|
attachment.then(() => { if (abandoned || signal.aborted) this.api.debugger.detach({ tabId }).catch(() => {}); }, () => {});
|
|
153
155
|
try { await bounded(attachment, signal, 'attach'); }
|
|
154
156
|
catch (error) { abandoned = true; throw error; }
|
|
155
|
-
this.attached.set(tabId, { refs: new Map(), revision: 0, logs: [], dialog: null, loadResolve: null, lastNetworkActivity: Date.now() });
|
|
157
|
+
this.attached.set(tabId, { refs: new Map(), revision: 0, logs: [], dialog: null, loadResolve: null, lastNetworkActivity: Date.now(), networkInFlight: 0, networkRequests: new Map() });
|
|
156
158
|
try {
|
|
157
159
|
for (const domain of ['Page', 'DOM', 'Accessibility', 'Runtime', 'Network']) await this.command(tabId, `${domain}.enable`, {}, signal);
|
|
158
160
|
} catch (error) {
|
|
@@ -388,11 +390,15 @@ export class BrowserController {
|
|
|
388
390
|
if (action === 'snapshot') {
|
|
389
391
|
const state = this.attached.get(tabId);
|
|
390
392
|
state.refs.clear();
|
|
393
|
+
if (state.dialog) {
|
|
394
|
+
const tab = await bounded(this.api.tabs.get(tabId), signal, 'tabs.get');
|
|
395
|
+
return { tabId, url: clip(tab.url, 4096), title: clip(tab.title, 300), dialog: state.dialog, elements: [], truncated: false };
|
|
396
|
+
}
|
|
391
397
|
const revision = state.revision;
|
|
392
398
|
const { nodes } = await cdp('Accessibility.getFullAXTree');
|
|
393
399
|
if (state.revision !== revision) throw new Error('PAGE_CHANGED: take a fresh snapshot');
|
|
394
400
|
const prefix = crypto.randomUUID().slice(0, 8);
|
|
395
|
-
const visible = nodes.filter(node => !node.ignored && !['none', 'generic', 'InlineTextBox'].includes(node.role?.value));
|
|
401
|
+
const visible = nodes.filter(node => !node.ignored && !['none', 'generic', 'InlineTextBox', 'StaticText'].includes(node.role?.value));
|
|
396
402
|
const entries = visible.slice(0, 500).map((node, index) => {
|
|
397
403
|
const entry = { role: clip(node.role?.value, 80), name: clip(node.name?.value, 1000) };
|
|
398
404
|
if (node.backendDOMNodeId) {
|
|
@@ -442,9 +448,26 @@ export class BrowserController {
|
|
|
442
448
|
const button = action === 'fill' ? 'left' : (args.button ?? 'left');
|
|
443
449
|
const count = action === 'fill' ? 1 : (args.count ?? 1);
|
|
444
450
|
const buttons = button === 'left' ? 1 : button === 'right' ? 2 : 4;
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
451
|
+
const state = this.attached.get(tabId);
|
|
452
|
+
const dispatched = Promise.all([
|
|
453
|
+
cdp('Input.dispatchMouseEvent', { type: 'mouseMoved', x: position.x, y: position.y, buttons: 0 }),
|
|
454
|
+
cdp('Input.dispatchMouseEvent', { type: 'mousePressed', x: position.x, y: position.y, button, buttons, clickCount: count }),
|
|
455
|
+
cdp('Input.dispatchMouseEvent', { type: 'mouseReleased', x: position.x, y: position.y, button, buttons: 0, clickCount: count }),
|
|
456
|
+
]);
|
|
457
|
+
// A click that opens alert/confirm/prompt blocks the renderer, so the
|
|
458
|
+
// mouse command may never acknowledge. The dialog event still arrives;
|
|
459
|
+
// return control to the caller so chrome_dialog can dismiss it.
|
|
460
|
+
dispatched.catch(() => {});
|
|
461
|
+
const opened = (async () => {
|
|
462
|
+
const end = Date.now() + 2500;
|
|
463
|
+
while (Date.now() < end) {
|
|
464
|
+
if (state.dialog) return true;
|
|
465
|
+
await sleep(25);
|
|
466
|
+
}
|
|
467
|
+
return false;
|
|
468
|
+
})();
|
|
469
|
+
if (await Promise.race([dispatched.then(() => false), opened])) return { tabId, action, button, count, completed: true, dialog: state.dialog ?? null };
|
|
470
|
+
await dispatched;
|
|
448
471
|
if (action === 'fill') {
|
|
449
472
|
const selected = await cdp('Runtime.callFunctionOn', { objectId, returnByValue: true, functionDeclaration: 'function() { if (!this.isConnected) throw new Error("STALE_ELEMENT"); this.focus(); this.select(); return true; }' });
|
|
450
473
|
if (selected.exceptionDetails) throw new Error('INPUT_SELECTION_FAILED');
|
|
@@ -576,7 +599,7 @@ export class BrowserController {
|
|
|
576
599
|
matched = Boolean(result.result?.value);
|
|
577
600
|
} else if (args.networkIdle) {
|
|
578
601
|
const state = this.attached.get(tabId);
|
|
579
|
-
matched = Date.now() - (state?.lastNetworkActivity ?? 0) >= 500;
|
|
602
|
+
matched = (state?.networkInFlight ?? 0) === 0 && Date.now() - (state?.lastNetworkActivity ?? 0) >= 500;
|
|
580
603
|
} else {
|
|
581
604
|
const result = await cdp('Runtime.callFunctionOn', { objectId, returnByValue: true, functionDeclaration: VISIBLE_FN });
|
|
582
605
|
if (result.exceptionDetails) {
|
|
@@ -585,7 +608,7 @@ export class BrowserController {
|
|
|
585
608
|
} else matched = Boolean(result.result.value);
|
|
586
609
|
}
|
|
587
610
|
if (matched !== gone) return { tabId, waitedMs: Date.now() - started, gone };
|
|
588
|
-
if (Date.now() >= deadline) throw new Error(`WAIT_TIMEOUT: ${timeout}ms`);
|
|
611
|
+
if (Date.now() >= deadline) { const st = this.attached.get(tabId); throw new Error(`WAIT_TIMEOUT: ${timeout}ms (inFlight=${st?.networkInFlight}, quiet=${Date.now() - (st?.lastNetworkActivity ?? 0)}, urls=${[...(st?.networkRequests?.values() ?? [])].join(',')})`); }
|
|
589
612
|
await sleep(Math.min(250, deadline - Date.now()), signal);
|
|
590
613
|
}
|
|
591
614
|
} finally {
|
package/extension/manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "dsh-chrome-use",
|
|
4
4
|
"description": "Let DeepSeek Harness read, control and debug your Google Chrome tabs after pairing.",
|
|
5
|
-
"version": "0.4.
|
|
5
|
+
"version": "0.4.1",
|
|
6
6
|
"minimum_chrome_version": "120",
|
|
7
7
|
"permissions": [
|
|
8
8
|
"debugger",
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -58,7 +58,7 @@ async function checkRelease(current, fetcher = fetch) {
|
|
|
58
58
|
} finally { clearTimeout(timer); }
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
const packageVersion = "0.4.
|
|
61
|
+
const packageVersion = "0.4.1";
|
|
62
62
|
// Wrapped by scripts/build-client.mjs for the Harness browser module loader.
|
|
63
63
|
const React = require('react');
|
|
64
64
|
const { createElement: h, useState, useEffect, useRef } = React;
|