2 Commits

Author SHA1 Message Date
DeepSeek Harness Agent 41c6bb133e native-fixes: guard attach against a browser this process already drives (Firefox single BiDi session); report the existing connection instead of stranding it 2026-11-08 21:28:20 +03:30
DeepSeek Harness Agent e072aadcb8 native-fixes: Firefox BiDi + shared browser defects
Fixes verified live on Edge 157, Chrome for Testing 157 and Firefox 159.0.1
through the installed DSH plugin (Edge Kit Browser v3.6.1 base).

Firefox / WebDriver BiDi:
- type: BiDi has no {type:'text'} key action and input.insertText is unknown;
  type by one keyDown/keyUp pair per code point.
- Enter/Delete/PageUp/PageDown/Escape: named keys now win over their text form
  (Enter was sent as a '\r' character) and the WebDriver key table is fixed
  (Escape was NUMPAD1); pressKey always sends the matching keyUp.
- newTab: browsingContext.create ignores an inline URL; create then navigate.
- waitForLoad: poll document.readyState for BiDi so a missed load event no
  longer stalls newTab ~15s; also report loadEvent source.
- close/detach: end the Firefox BiDi session explicitly (a bare WebSocket
  close does not release it -> "Maximum number of active sessions").
- restart/dispose: close the browser through the protocol before dropping the
  socket (the spawn handle is only the Windows launcher, so killing it orphaned
  the browser); re-validate attach-only sessions and never leave a half session.
- proxy: Firefox -proxy-server takes host:port (strip the http:// scheme);
  v3.6.1 direct-traffic preferences are kept.
- relaunch: only the selected engine is taskkilled, and Firefox refuses
  relaunch instead of killing every Firefox window.

Shared (Edge/Chrome/Firefox):
- see: prioritize aria-label for accessible names.
- click {text}/type {into}: walk shadow roots of every element, not just the
  host shapes already matched (shadow-DOM buttons and inputs are found).
- click {index}: re-resolve the element captured by the last see and scroll it
  into view before clicking (a stale cached coordinate silently missed).
- press {key:'Space'}/named keys: case-normalized named keys and a real space
  character (CDP delivered event.key = "" for the named form).

Also includes the native-portability loader for schemastery (asar-aware),
the home-relative activation-probe path, and the close action that no longer
nulls its session before Browser.close (browser leak).
2026-11-08 21:12:09 +03:30
4 changed files with 9 additions and 53 deletions
+1 -2
View File
@@ -63,10 +63,9 @@ Browser discovery is cross-platform — Windows, Linux (apt **and** snap paths,
- **auto** — probes every candidate by fetching an IP echo **through** it (ladder: checkip.amazonaws.com → ifconfig.me → ipinfo.io, so a single rate-limited echo service can't fake a failure), picks the fastest working proxy, restarts the browser onto it, and reports the verified exit IP/country.
- **set** — installs a list verbatim. One hop is handed to the browser directly (`--proxy-server`); two or more are **chained** through an in-kit local CONNECT forwarder (browser → 127.0.0.1 → hop1 → hop2 → … → origin), verified end-to-end before the switch — a rejected chain falls back to the fastest single hop (or errors, in `set`).
- **status** — live re-probe of the current route; **clear** — direct traffic again. `chainTo` adds one chained hop behind the auto-pick. Switching routes force-closes any survivor browser process (Edge startup-boost / profile handoff) before relaunch, so the new proxy state can never be silently lost — logins survive, windows reopen.
- **status** — live re-probe of the current route; **clear** — direct traffic again. `chainTo` adds one chained hop behind the auto-pick.
- The `proxyChain` setting preloads a chain into every launch; the native web seam (`web_fetch` / `web_search`) rides the same route.
- **Fully built in** — no system/v2ray proxy anywhere in the path: probes use raw sockets, and launched browsers get explicit proxy state (`--proxy-server` when routing; `--no-proxy-server` / `network.proxy.type:0` when direct, with `HTTP(S)_PROXY`/`ALL_PROXY` stripped from the launch environment). A local v2ray can never silently capture the browser.
- A candidate whose echo comes back **with your own egress IP** is rejected as *transparent* — a route that doesn't change your exit is a no-op, not a proxy. `setup.mjs` also disables Edge's startup boost (registry policy) so background Edge processes can't re-grab the debug port with stale, proxy-less flags.
A proxy counts as *working* only when an echo comes back through it — no blind trust in proxy-list sites.
+6 -33
View File
@@ -669,23 +669,12 @@ async function echoLadder(hops) {
}
return null;
}
let directEgress;
async function directEgressOf() {
// node fetch never reads HTTP_PROXY/v2ray — this is the machine's true exit.
if (directEgress === undefined) {
directEgress = null;
try { const r = await fetch('http://checkip.amazonaws.com/', { signal: AbortSignal.timeout(7000) }); directEgress = (await r.text()).trim().split(/\s/)[0] || null; } catch { /* offline */ }
}
return directEgress;
}
async function probeCandidate(h) {
const t0 = Date.now();
const [e, own] = await Promise.all([echoLadder([h]), directEgressOf()]);
if (!e) return { ok: false, reason: 'no echo (dead or blocking)', ms: Date.now() - t0 };
if (own && (e.ip === own || e.ip.startsWith(own.split('.').slice(0, 2).join('.') + '.'))) {
return { ok: false, reason: `transparent (exit ${e.ip} is your own network — routing through it changes nothing)`, ms: Date.now() - t0 };
}
return { ok: true, ip: e.ip, country: e.country, as: e.org, ms: Date.now() - t0 };
const e = await echoLadder([h]);
return e
? { ok: true, ip: e.ip, country: e.country, as: e.org, ms: Date.now() - t0 }
: { ok: false, reason: 'no echo (dead or blocking)', ms: Date.now() - t0 };
}
const pipeBoth = (a, b) => {
@@ -774,7 +763,7 @@ async function egressVia(hops) {
async function restartSession() {
const la = session && session.launchArgs ? session.launchArgs : null;
if (!session || session.attached || !la) return false;
const { child, ws, engine, kind } = session;
const { child, ws, engine } = session;
// Close the browser itself before dropping the socket: for Firefox the spawn
// handle is only the Windows launcher, so killing it can orphan the browser
// and leave Firefox's single BiDi session registered (the next session.new
@@ -784,24 +773,8 @@ async function restartSession() {
session = null;
try { ws.close(); } catch { /* gone */ }
if (child && child.exitCode === null) child.kill();
const port = la.port || effectivePort(la);
const waitFree = async (ms) => {
const t0 = Date.now();
while (await probePort(port) && Date.now() - t0 < ms) await new Promise((r) => setTimeout(r, 400));
return !(await probePort(port));
};
if (!(await waitFree(6000))) {
// A survivor browser (Edge startup-boost, profile handoff, leftover window)
// retook the port without our new flags — a fresh spawn would merge into it
// and silently lose proxy routing. For Chromium, kill instances of this
// browser kind (same semantics as relaunch:true; logins survive, windows
// reopen). Firefox refuses: taskkill would close every Firefox window.
if (kind === 'firefox') return false;
const exe = kind === 'chrome' ? 'chrome' : 'msedge';
const killCmd = process.platform === 'win32' ? `taskkill /IM ${exe}.exe /F` : `pkill -9 -x ${exe}`;
await new Promise((r) => exec(killCmd, () => r()));
if (!(await waitFree(8000))) return false;
}
while (await probePort(la.port || effectivePort(la)) && Date.now() - t0 < 10000) await new Promise((r) => setTimeout(r, 500));
await doLaunch(la);
return true;
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@local/edge-kit-easy",
"version": "3.6.4",
"version": "3.6.1",
"private": true,
"type": "module",
"description": "Edge Kit Browser — human-style browsing for agents in Edge, Chrome, or Firefox: see, click, type, video understanding, gameplay; live-attach-first over CDP/BiDi with a native settings page and the native web seam",
-16
View File
@@ -10,7 +10,6 @@ import fs from 'node:fs/promises';
import os from 'node:os';
import net from 'node:net';
import path from 'node:path';
import { execSync } from 'node:child_process';
const P = process.platform;
const HOME = os.homedir();
@@ -77,21 +76,6 @@ for (const port of [9444, 9445, 9446]) {
else warn(`debug port ${port} busy — a browser already holds it; the kit will attach to it (relaunch:true takes over)`);
}
/* 4b. Edge startup-boost survivor background processes re-spawn with stale
* command lines and silently swallow the kit's proxy flag on relaunch.
* The enterprise policy kills them for good. */
if (P === 'win32') {
try {
execSync('reg query "HKCU\\Software\\Policies\\Microsoft\\Edge" /v StartupBoostEnabled', { stdio: 'pipe' });
ok('Edge startup-boost already governed by policy');
} catch {
try {
execSync('reg add "HKCU\\Software\\Policies\\Microsoft\\Edge" /v StartupBoostEnabled /t REG_DWORD /d 0 /f', { stdio: 'pipe' });
ok('disabled Edge startup boost (policy) — survivor processes can no longer drop proxy flags');
} catch { warn('could not write Edge StartupBoostEnabled policy — restarts may race a background Edge'); }
}
}
/* 5. Direct egress — proves there is an internet path WITHOUT any system/v2ray
* proxy (node fetch never reads HTTP_PROXY). Geo-restricted hosts (Iran)
* often have no open HTTP echo without VPN but can reach proxies directly