@linxin666/dsh-client-ui-browser-view 0.4.18 → 0.4.20
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.i18n.yaml +2 -2
- package/README.md +4 -4
- package/README.zh.md +4 -4
- package/lib/client.js +18 -2
- package/lib/client.js.map +1 -1
- package/lib/index.js +325 -85
- package/lib/types/client/settings-form.d.ts +2 -0
- package/lib/types/core/chrome.d.ts +9 -2
- package/lib/types/host/auth.d.ts +25 -0
- package/lib/types/host/service.d.ts +27 -5
- package/lib/types/index.d.ts +16 -0
- package/package.json +16 -16
package/lib/index.js
CHANGED
|
@@ -127,11 +127,11 @@ var CdpClient = class CdpClient {
|
|
|
127
127
|
});
|
|
128
128
|
this.socket.send(JSON.stringify(payload), (error) => {
|
|
129
129
|
if (error === null || error === void 0) return;
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
130
|
+
const reason = `the DevTools socket write failed: ${error.message}`;
|
|
131
|
+
this.failAll(reason);
|
|
132
|
+
try {
|
|
133
|
+
this.socket.close();
|
|
134
|
+
} catch {}
|
|
135
135
|
});
|
|
136
136
|
});
|
|
137
137
|
}
|
|
@@ -491,6 +491,20 @@ var ChromeProcess = class ChromeProcess {
|
|
|
491
491
|
return this.disposed;
|
|
492
492
|
}
|
|
493
493
|
/**
|
|
494
|
+
* Subscribe to child-process exit so attached transports mark themselves
|
|
495
|
+
* closed without waiting for idle WebSocket teardown (#2051).
|
|
496
|
+
*/
|
|
497
|
+
onExit(listener) {
|
|
498
|
+
if (this.child.exitCode !== null || this.child.signalCode !== null) {
|
|
499
|
+
listener();
|
|
500
|
+
return () => void 0;
|
|
501
|
+
}
|
|
502
|
+
this.child.once("exit", listener);
|
|
503
|
+
return () => {
|
|
504
|
+
this.child.off("exit", listener);
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
494
508
|
* What the disposal achieved, once it ran. A caller that needs to know
|
|
495
509
|
* whether a browser survived the shutdown reads this instead of assuming.
|
|
496
510
|
* @returns the recorded outcome, or undefined before {@link dispose}.
|
|
@@ -549,6 +563,9 @@ function describeExitHint(port) {
|
|
|
549
563
|
}
|
|
550
564
|
/**
|
|
551
565
|
* Terminate one child process, escalating to SIGKILL after a grace period.
|
|
566
|
+
* On Windows, `child.kill()` stops only the parent PID while Chrome's GPU and
|
|
567
|
+
* Crashpad children linger and lock the temp profile; invoke `taskkill /T /F`
|
|
568
|
+
* beside it so the whole process tree shuts down cleanly (#2051).
|
|
552
569
|
* @param child - the process launched for this browser.
|
|
553
570
|
*/
|
|
554
571
|
async function terminate(child) {
|
|
@@ -557,6 +574,11 @@ async function terminate(child) {
|
|
|
557
574
|
child.once("exit", () => resolve());
|
|
558
575
|
child.once("error", () => resolve());
|
|
559
576
|
});
|
|
577
|
+
if (process.platform === "win32" && child.pid !== void 0) await killProcessTreeWin32(child.pid);
|
|
578
|
+
if (child.exitCode !== null || child.signalCode !== null) {
|
|
579
|
+
await exited;
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
560
582
|
try {
|
|
561
583
|
child.kill();
|
|
562
584
|
} catch {
|
|
@@ -574,9 +596,40 @@ async function terminate(child) {
|
|
|
574
596
|
setTimeout(resolve, CHROME_EXIT_TIMEOUT_MS);
|
|
575
597
|
})]);
|
|
576
598
|
}
|
|
599
|
+
/** Force-terminate a Windows process tree rooted at `pid`, ignoring already-gone errors. */
|
|
600
|
+
async function killProcessTreeWin32(pid) {
|
|
601
|
+
await new Promise((resolve) => {
|
|
602
|
+
let settled = false;
|
|
603
|
+
const finish = () => {
|
|
604
|
+
if (settled) return;
|
|
605
|
+
settled = true;
|
|
606
|
+
clearTimeout(timer);
|
|
607
|
+
resolve();
|
|
608
|
+
};
|
|
609
|
+
const timer = setTimeout(finish, CHROME_EXIT_TIMEOUT_MS);
|
|
610
|
+
const unref = timer.unref;
|
|
611
|
+
if (typeof unref === "function") unref.call(timer);
|
|
612
|
+
try {
|
|
613
|
+
const killer = spawn("taskkill", [
|
|
614
|
+
"/PID",
|
|
615
|
+
String(pid),
|
|
616
|
+
"/T",
|
|
617
|
+
"/F"
|
|
618
|
+
], {
|
|
619
|
+
stdio: "ignore",
|
|
620
|
+
windowsHide: true
|
|
621
|
+
});
|
|
622
|
+
killer.once("close", finish);
|
|
623
|
+
killer.once("error", finish);
|
|
624
|
+
} catch {
|
|
625
|
+
finish();
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
}
|
|
577
629
|
/**
|
|
578
630
|
* Delete the profile directory this launch created, without ever following a
|
|
579
|
-
* link out of it.
|
|
631
|
+
* link out of it. Retries briefly on transient file locks left behind while
|
|
632
|
+
* browser subprocesses release handles (#2051).
|
|
580
633
|
*
|
|
581
634
|
* `fs.rm({ recursive: true })` is banned repository-wide: recursion walks a
|
|
582
635
|
* junction or symlink happily and deletes whatever it points at, so a temp
|
|
@@ -586,12 +639,29 @@ async function terminate(child) {
|
|
|
586
639
|
* Failures are swallowed: a leftover file in the OS temp directory is a lesser
|
|
587
640
|
* problem than failing the dispose path that the caller is awaiting.
|
|
588
641
|
* @param dir - absolute path of the profile directory created by this launch.
|
|
642
|
+
* @param retryDelaysMs - backoff delays after locked removals.
|
|
589
643
|
*/
|
|
590
|
-
async function removeTempProfile(dir
|
|
644
|
+
async function removeTempProfile(dir, retryDelaysMs = [
|
|
645
|
+
50,
|
|
646
|
+
150,
|
|
647
|
+
350
|
|
648
|
+
]) {
|
|
591
649
|
const root = tmpdir();
|
|
592
650
|
if (!dir.startsWith(root) || dir === root) return;
|
|
593
|
-
|
|
594
|
-
|
|
651
|
+
for (let attempt = 0; attempt <= retryDelaysMs.length; attempt++) {
|
|
652
|
+
await emptyDirectory(dir);
|
|
653
|
+
try {
|
|
654
|
+
await rmdir(dir);
|
|
655
|
+
return;
|
|
656
|
+
} catch (error) {
|
|
657
|
+
if (error?.code === "ENOENT") return;
|
|
658
|
+
const delay = retryDelaysMs[attempt];
|
|
659
|
+
if (delay === void 0) return;
|
|
660
|
+
await new Promise((resolve) => {
|
|
661
|
+
setTimeout(resolve, delay);
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
}
|
|
595
665
|
}
|
|
596
666
|
/** Recursively empty one directory, refusing to descend through links. */
|
|
597
667
|
async function emptyDirectory(dir) {
|
|
@@ -1653,11 +1723,18 @@ function isLoopbackRequest(request) {
|
|
|
1653
1723
|
* @module @linxin666/dsh-client-ui-browser-view/host/auth
|
|
1654
1724
|
*/
|
|
1655
1725
|
/**
|
|
1656
|
-
* Body text of the page DSH serves
|
|
1657
|
-
* token nor a valid cookie.
|
|
1726
|
+
* Body text of the page DSH serves from its own token exchange when a request
|
|
1727
|
+
* carries neither the launch token nor a valid cookie.
|
|
1658
1728
|
*/
|
|
1659
1729
|
const AUTH_CHALLENGE_TEXT = /dsh web authentication required/i;
|
|
1660
1730
|
/**
|
|
1731
|
+
* Body of the bare refusal a post-#8266 Host answers when route admission
|
|
1732
|
+
* rejects a request before its resource runs. That cohort admits every route
|
|
1733
|
+
* as authenticated unless it declares otherwise, so a navigation to the site
|
|
1734
|
+
* root is refused here instead of reaching the friendly exchange page above.
|
|
1735
|
+
*/
|
|
1736
|
+
const ADMISSION_REJECTION_TEXT = /^\s*unauthorized\s*$/i;
|
|
1737
|
+
/**
|
|
1661
1738
|
* Script that reads the document's visible text. `document.body` is absent on
|
|
1662
1739
|
* a document that has no body yet, and `innerText` needs one.
|
|
1663
1740
|
*/
|
|
@@ -1671,6 +1748,53 @@ function isAuthChallengeText(text) {
|
|
|
1671
1748
|
return AUTH_CHALLENGE_TEXT.test(text);
|
|
1672
1749
|
}
|
|
1673
1750
|
/**
|
|
1751
|
+
* Whether a page's visible text is the bare refusal of route admission. The
|
|
1752
|
+
* body is generic — any local service can answer it — so a caller must also
|
|
1753
|
+
* know the page came from this host's own listener before trusting it.
|
|
1754
|
+
* @param text - `document.body.innerText` of the page that just loaded.
|
|
1755
|
+
* @returns true when the document is only the word `unauthorized`.
|
|
1756
|
+
*/
|
|
1757
|
+
function isAdmissionRejectionText(text) {
|
|
1758
|
+
return ADMISSION_REJECTION_TEXT.test(text);
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Whether a URL names the same loopback listener as an origin: both
|
|
1762
|
+
* authorities loopback, the same protocol, and the same port. A different
|
|
1763
|
+
* port is a different local service, and a non-loopback host is never ours.
|
|
1764
|
+
* @param url - the URL a navigation was asked to open.
|
|
1765
|
+
* @param origin - the host's own listener origin.
|
|
1766
|
+
* @returns true when the two name one loopback listener.
|
|
1767
|
+
*/
|
|
1768
|
+
function isSameLoopbackOrigin(url, origin) {
|
|
1769
|
+
let target;
|
|
1770
|
+
let own;
|
|
1771
|
+
try {
|
|
1772
|
+
target = new URL(url);
|
|
1773
|
+
own = new URL(origin);
|
|
1774
|
+
} catch {
|
|
1775
|
+
return false;
|
|
1776
|
+
}
|
|
1777
|
+
if (target.protocol !== "http:" && target.protocol !== "https:") return false;
|
|
1778
|
+
if (target.protocol !== own.protocol) return false;
|
|
1779
|
+
if (!isLoopbackHostname(target.hostname) || !isLoopbackHostname(own.hostname)) return false;
|
|
1780
|
+
if (target.port !== own.port) return false;
|
|
1781
|
+
return target.hostname === own.hostname || target.hostname === "localhost";
|
|
1782
|
+
}
|
|
1783
|
+
/**
|
|
1784
|
+
* Whether a URL names the site root. DSH's token exchange answers only
|
|
1785
|
+
* `GET /` with the cookie-setting redirect, so a bare refusal anywhere else
|
|
1786
|
+
* cannot be cleared by a ticketed retry.
|
|
1787
|
+
* @param url - the URL a navigation was asked to open.
|
|
1788
|
+
* @returns true when the URL has no path beyond the root.
|
|
1789
|
+
*/
|
|
1790
|
+
function isHostRootUrl(url) {
|
|
1791
|
+
try {
|
|
1792
|
+
return new URL(url).pathname === "/";
|
|
1793
|
+
} catch {
|
|
1794
|
+
return false;
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
/**
|
|
1674
1798
|
* Whether a navigation target is one this DSH process serves on loopback: a
|
|
1675
1799
|
* `localhost` name, 127/8, or `[::1]`. A remote site can render any text it
|
|
1676
1800
|
* likes, so only a loopback authority is worth a token retry.
|
|
@@ -2103,9 +2227,14 @@ async function scrollBy(scope, tabId, delta) {
|
|
|
2103
2227
|
async function openIsolatedSession(options) {
|
|
2104
2228
|
const chrome = await ChromeProcess.launch({ viewport: options.viewport });
|
|
2105
2229
|
let cdp;
|
|
2230
|
+
let unbindExit;
|
|
2106
2231
|
try {
|
|
2107
2232
|
cdp = await CdpClient.connect(chrome.info.webSocketDebuggerUrl);
|
|
2233
|
+
unbindExit = chrome.onExit(() => {
|
|
2234
|
+
cdp.close();
|
|
2235
|
+
});
|
|
2108
2236
|
} catch (error) {
|
|
2237
|
+
unbindExit?.();
|
|
2109
2238
|
await chrome.dispose();
|
|
2110
2239
|
throw error;
|
|
2111
2240
|
}
|
|
@@ -2122,6 +2251,7 @@ async function openIsolatedSession(options) {
|
|
|
2122
2251
|
tabs,
|
|
2123
2252
|
chrome,
|
|
2124
2253
|
async dispose() {
|
|
2254
|
+
unbindExit?.();
|
|
2125
2255
|
await tabs.dispose();
|
|
2126
2256
|
cdp.close();
|
|
2127
2257
|
await chrome.dispose();
|
|
@@ -2185,6 +2315,7 @@ var BrowserViewService = class {
|
|
|
2185
2315
|
openSession;
|
|
2186
2316
|
resolveConfig;
|
|
2187
2317
|
authenticatedUrl;
|
|
2318
|
+
hostOrigin;
|
|
2188
2319
|
idleCloseDays;
|
|
2189
2320
|
sweepIntervalMs;
|
|
2190
2321
|
idleTimer;
|
|
@@ -2228,6 +2359,7 @@ var BrowserViewService = class {
|
|
|
2228
2359
|
this.openSession = options.openSession ?? openConfiguredSession;
|
|
2229
2360
|
this.resolveConfig = options.resolveConfig ?? (() => ({ mode: "isolated" }));
|
|
2230
2361
|
this.authenticatedUrl = options.authenticatedUrl;
|
|
2362
|
+
this.hostOrigin = options.hostOrigin;
|
|
2231
2363
|
this.idleCloseDays = options.idleCloseDays ?? (() => 0);
|
|
2232
2364
|
this.sweepIntervalMs = options.sweepIntervalMs ?? 6e5;
|
|
2233
2365
|
if (this.sweepIntervalMs > 0) {
|
|
@@ -2239,17 +2371,18 @@ var BrowserViewService = class {
|
|
|
2239
2371
|
this.idleTimer = timer;
|
|
2240
2372
|
}
|
|
2241
2373
|
}
|
|
2242
|
-
/** Whether a browser is currently running. */
|
|
2374
|
+
/** Whether a browser is currently running with an open transport. */
|
|
2243
2375
|
get running() {
|
|
2244
|
-
return this.session !== void 0;
|
|
2376
|
+
return this.session !== void 0 && !this.session.transport.closed;
|
|
2245
2377
|
}
|
|
2246
2378
|
/** The current panel-facing state; safe to call before anything started. */
|
|
2247
2379
|
state() {
|
|
2248
2380
|
const config = this.resolveConfig();
|
|
2381
|
+
const live = this.session !== void 0 && !this.session.transport.closed ? this.session : void 0;
|
|
2249
2382
|
const state = {
|
|
2250
|
-
tabs:
|
|
2251
|
-
activeTabId:
|
|
2252
|
-
running:
|
|
2383
|
+
tabs: live?.tabs.list() ?? [],
|
|
2384
|
+
activeTabId: live === void 0 ? null : this.displayedOrDefault(),
|
|
2385
|
+
running: live !== void 0,
|
|
2253
2386
|
mode: config.mode
|
|
2254
2387
|
};
|
|
2255
2388
|
if (config.mode === "cdp" && config.cdpEndpoint !== void 0) try {
|
|
@@ -2430,6 +2563,9 @@ var BrowserViewService = class {
|
|
|
2430
2563
|
* @returns the tab view.
|
|
2431
2564
|
*/
|
|
2432
2565
|
async tabFor(sessionId, tabId) {
|
|
2566
|
+
return await this.runWithSession(async () => await this.doTabFor(sessionId, tabId));
|
|
2567
|
+
}
|
|
2568
|
+
async doTabFor(sessionId, tabId) {
|
|
2433
2569
|
const tabs = await this.requireTabs();
|
|
2434
2570
|
const tab = await this.resolveTabFor(tabs, sessionId, tabId);
|
|
2435
2571
|
tabs.touch(tab.id);
|
|
@@ -2488,6 +2624,9 @@ var BrowserViewService = class {
|
|
|
2488
2624
|
* @returns the tab view.
|
|
2489
2625
|
*/
|
|
2490
2626
|
async ensureTab(sessionId) {
|
|
2627
|
+
return await this.runWithSession(async () => await this.doEnsureTab(sessionId));
|
|
2628
|
+
}
|
|
2629
|
+
async doEnsureTab(sessionId) {
|
|
2491
2630
|
const tabs = await this.requireTabs();
|
|
2492
2631
|
if (sessionId !== void 0) {
|
|
2493
2632
|
const bound = this.bindings.get(sessionId);
|
|
@@ -2543,17 +2682,19 @@ var BrowserViewService = class {
|
|
|
2543
2682
|
* @returns the action outcome plus the resulting tab view.
|
|
2544
2683
|
*/
|
|
2545
2684
|
async navigate(sessionId, url, tabId, options = {}) {
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2685
|
+
return await this.runWithSession(async () => {
|
|
2686
|
+
const tab = options.newTab === true ? await this.openTab(sessionId) : await this.doTabFor(sessionId, tabId);
|
|
2687
|
+
try {
|
|
2688
|
+
const outcome = await navigateTo(this.scope(), tab.id, url);
|
|
2689
|
+
await this.topUpAuthTicket(tab.id, url);
|
|
2690
|
+
return {
|
|
2691
|
+
outcome: this.trace("navigate", outcome),
|
|
2692
|
+
tab: this.refreshTab(tab.id)
|
|
2693
|
+
};
|
|
2694
|
+
} finally {
|
|
2695
|
+
this.authTopUpSpent.delete(tab.id);
|
|
2696
|
+
}
|
|
2697
|
+
});
|
|
2557
2698
|
}
|
|
2558
2699
|
/**
|
|
2559
2700
|
* Give a loopback navigation that landed on DSH's own authentication page
|
|
@@ -2587,7 +2728,7 @@ var BrowserViewService = class {
|
|
|
2587
2728
|
const mint = this.authenticatedUrl;
|
|
2588
2729
|
if (mint === void 0) return void 0;
|
|
2589
2730
|
if (!isLoopbackTarget(url)) return void 0;
|
|
2590
|
-
if (!await this.documentShowsAuthChallenge(tabId)) return void 0;
|
|
2731
|
+
if (!await this.documentShowsAuthChallenge(tabId, url)) return void 0;
|
|
2591
2732
|
try {
|
|
2592
2733
|
const ticket = mint(url);
|
|
2593
2734
|
return typeof ticket === "string" && ticket !== "" ? ticket : void 0;
|
|
@@ -2596,20 +2737,28 @@ var BrowserViewService = class {
|
|
|
2596
2737
|
}
|
|
2597
2738
|
}
|
|
2598
2739
|
/**
|
|
2599
|
-
* Whether the tab's current document is DSH's authentication page.
|
|
2600
|
-
*
|
|
2601
|
-
*
|
|
2740
|
+
* Whether the tab's current document is DSH's authentication page. Two
|
|
2741
|
+
* pages count: the token exchange's own sentence, and the bare
|
|
2742
|
+
* `unauthorized` a post-#8266 Host answers when route admission refuses the
|
|
2743
|
+
* site root before that exchange runs. The bare refusal is generic to every
|
|
2744
|
+
* local service, so it only counts when the requested URL names this host's
|
|
2745
|
+
* own listener.
|
|
2602
2746
|
* @param tabId - tab to read.
|
|
2747
|
+
* @param url - the URL the caller asked to open.
|
|
2603
2748
|
* @returns true when the page body is the challenge.
|
|
2604
2749
|
*/
|
|
2605
|
-
async documentShowsAuthChallenge(tabId) {
|
|
2750
|
+
async documentShowsAuthChallenge(tabId, url) {
|
|
2606
2751
|
try {
|
|
2607
2752
|
const scope = this.scope();
|
|
2608
2753
|
const text = (await scope.transport.send("Runtime.evaluate", {
|
|
2609
2754
|
expression: DOCUMENT_TEXT_EXPRESSION,
|
|
2610
2755
|
returnByValue: true
|
|
2611
2756
|
}, scope.tabs.sessionOf(tabId))).result?.value;
|
|
2612
|
-
|
|
2757
|
+
if (typeof text !== "string") return false;
|
|
2758
|
+
if (isAuthChallengeText(text)) return true;
|
|
2759
|
+
if (!isAdmissionRejectionText(text)) return false;
|
|
2760
|
+
const origin = this.hostOrigin?.();
|
|
2761
|
+
return origin !== void 0 && isSameLoopbackOrigin(url, origin) && isHostRootUrl(url);
|
|
2613
2762
|
} catch {
|
|
2614
2763
|
return false;
|
|
2615
2764
|
}
|
|
@@ -2622,9 +2771,11 @@ var BrowserViewService = class {
|
|
|
2622
2771
|
* @returns the recorded outcome.
|
|
2623
2772
|
*/
|
|
2624
2773
|
async click(sessionId, target, tabId) {
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2774
|
+
return await this.runWithSession(async () => {
|
|
2775
|
+
const tab = await this.doTabFor(sessionId, tabId);
|
|
2776
|
+
const outcome = await clickElement(this.scope(), tab.id, target);
|
|
2777
|
+
return this.trace("click", outcome);
|
|
2778
|
+
});
|
|
2628
2779
|
}
|
|
2629
2780
|
/**
|
|
2630
2781
|
* Type into a tab and trace the action.
|
|
@@ -2635,9 +2786,11 @@ var BrowserViewService = class {
|
|
|
2635
2786
|
* @returns the recorded outcome.
|
|
2636
2787
|
*/
|
|
2637
2788
|
async type(sessionId, text, target = {}, tabId) {
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2789
|
+
return await this.runWithSession(async () => {
|
|
2790
|
+
const tab = await this.doTabFor(sessionId, tabId);
|
|
2791
|
+
const outcome = await typeText(this.scope(), tab.id, text, target);
|
|
2792
|
+
return this.trace("type", outcome);
|
|
2793
|
+
});
|
|
2641
2794
|
}
|
|
2642
2795
|
/**
|
|
2643
2796
|
* Press one key and trace the action.
|
|
@@ -2647,9 +2800,11 @@ var BrowserViewService = class {
|
|
|
2647
2800
|
* @returns the recorded outcome.
|
|
2648
2801
|
*/
|
|
2649
2802
|
async press(sessionId, key, tabId) {
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2803
|
+
return await this.runWithSession(async () => {
|
|
2804
|
+
const tab = await this.doTabFor(sessionId, tabId);
|
|
2805
|
+
const outcome = await pressKey(this.scope(), tab.id, key);
|
|
2806
|
+
return this.trace("press", outcome);
|
|
2807
|
+
});
|
|
2653
2808
|
}
|
|
2654
2809
|
/**
|
|
2655
2810
|
* Scroll a tab and trace the action.
|
|
@@ -2659,9 +2814,11 @@ var BrowserViewService = class {
|
|
|
2659
2814
|
* @returns the recorded outcome.
|
|
2660
2815
|
*/
|
|
2661
2816
|
async scroll(sessionId, delta, tabId) {
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2817
|
+
return await this.runWithSession(async () => {
|
|
2818
|
+
const tab = await this.doTabFor(sessionId, tabId);
|
|
2819
|
+
const outcome = await scrollBy(this.scope(), tab.id, delta);
|
|
2820
|
+
return this.trace("scroll", outcome);
|
|
2821
|
+
});
|
|
2665
2822
|
}
|
|
2666
2823
|
/**
|
|
2667
2824
|
* Walk the tab's DOM and remember the ref map for later clicks.
|
|
@@ -2670,14 +2827,16 @@ var BrowserViewService = class {
|
|
|
2670
2827
|
* @returns the snapshot the model sees.
|
|
2671
2828
|
*/
|
|
2672
2829
|
async snapshot(sessionId, tabId) {
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2830
|
+
return await this.runWithSession(async () => {
|
|
2831
|
+
const tab = await this.doTabFor(sessionId, tabId);
|
|
2832
|
+
const tabs = this.scope().tabs;
|
|
2833
|
+
const result = await buildSnapshot(this.transport(), tab.id, tabs.sessionOf(tab.id), {
|
|
2834
|
+
url: tab.url,
|
|
2835
|
+
title: tab.title
|
|
2836
|
+
});
|
|
2837
|
+
tabs.setSnapshotRefs(tab.id, result.refs);
|
|
2838
|
+
return result.snapshot;
|
|
2678
2839
|
});
|
|
2679
|
-
tabs.setSnapshotRefs(tab.id, result.refs);
|
|
2680
|
-
return result.snapshot;
|
|
2681
2840
|
}
|
|
2682
2841
|
/**
|
|
2683
2842
|
* Capture one image of the tab.
|
|
@@ -2697,20 +2856,22 @@ var BrowserViewService = class {
|
|
|
2697
2856
|
* @throws when the request cannot be honoured by this viewport or the size limits.
|
|
2698
2857
|
*/
|
|
2699
2858
|
async screenshot(sessionId, tabId, request = {}) {
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2859
|
+
return await this.runWithSession(async () => {
|
|
2860
|
+
const tab = await this.doTabFor(sessionId, tabId);
|
|
2861
|
+
const tabs = this.scope().tabs;
|
|
2862
|
+
const plan = planScreenshot(await tabs.viewportOf(tab.id), request, this.jpegQuality);
|
|
2863
|
+
const data = await tabs.captureScreenshot(tab.id, plan.params);
|
|
2864
|
+
const current = tabs.list().find((candidate) => candidate.id === tab.id) ?? tab;
|
|
2865
|
+
return {
|
|
2866
|
+
tabId: current.id,
|
|
2867
|
+
url: current.url,
|
|
2868
|
+
title: current.title,
|
|
2869
|
+
data,
|
|
2870
|
+
mediaType: plan.mediaType,
|
|
2871
|
+
width: plan.width,
|
|
2872
|
+
height: plan.height
|
|
2873
|
+
};
|
|
2874
|
+
});
|
|
2714
2875
|
}
|
|
2715
2876
|
/**
|
|
2716
2877
|
* Console entries of one tab, newest last.
|
|
@@ -2745,10 +2906,21 @@ var BrowserViewService = class {
|
|
|
2745
2906
|
/** Open tabs, for `browser_tabs`. */
|
|
2746
2907
|
async listTabs() {
|
|
2747
2908
|
if (this.session === void 0 || this.session.transport.closed) {
|
|
2748
|
-
if (this.resolveConfig().mode !== "cdp")
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2909
|
+
if (this.resolveConfig().mode !== "cdp") {
|
|
2910
|
+
if (this.session !== void 0 && this.session.transport.closed) {
|
|
2911
|
+
const stale = this.forgetSession();
|
|
2912
|
+
if (stale !== void 0) stale.dispose().catch(() => void 0);
|
|
2913
|
+
this.broadcast({
|
|
2914
|
+
v: 1,
|
|
2915
|
+
kind: "state",
|
|
2916
|
+
state: this.state()
|
|
2917
|
+
});
|
|
2918
|
+
}
|
|
2919
|
+
return {
|
|
2920
|
+
tabs: [],
|
|
2921
|
+
activeTabId: null
|
|
2922
|
+
};
|
|
2923
|
+
}
|
|
2752
2924
|
await this.requireSession();
|
|
2753
2925
|
}
|
|
2754
2926
|
const session = this.session;
|
|
@@ -2884,11 +3056,29 @@ var BrowserViewService = class {
|
|
|
2884
3056
|
if (this.sinks.size > 0) this.startStreaming().catch(() => void 0);
|
|
2885
3057
|
return session;
|
|
2886
3058
|
}
|
|
2887
|
-
/**
|
|
3059
|
+
/**
|
|
3060
|
+
* Run one operation against a live session; if a reused transport closes
|
|
3061
|
+
* mid-command, recycle the dead session and replay once so transient socket
|
|
3062
|
+
* drops self-heal in-flight (#2051).
|
|
3063
|
+
*/
|
|
3064
|
+
async runWithSession(operation) {
|
|
3065
|
+
const session = await this.requireSession();
|
|
3066
|
+
try {
|
|
3067
|
+
return await operation();
|
|
3068
|
+
} catch (error) {
|
|
3069
|
+
if (!session.transport.closed || this.disposed) throw error;
|
|
3070
|
+
await this.requireSession();
|
|
3071
|
+
return await operation();
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
/**
|
|
3075
|
+
* Start the browser once (retrying isolated launches once on transient
|
|
3076
|
+
* startup errors), recording persistent failures for the panel.
|
|
3077
|
+
*/
|
|
2888
3078
|
async startSession() {
|
|
2889
3079
|
const generation = this.generation;
|
|
2890
3080
|
const config = this.resolveConfig();
|
|
2891
|
-
|
|
3081
|
+
const attemptOpen = async () => {
|
|
2892
3082
|
const session = await this.openSession({
|
|
2893
3083
|
...config,
|
|
2894
3084
|
jpegQuality: this.jpegQuality,
|
|
@@ -2912,6 +3102,17 @@ var BrowserViewService = class {
|
|
|
2912
3102
|
await session.dispose();
|
|
2913
3103
|
throw new Error("the browser configuration changed while the session was opening");
|
|
2914
3104
|
}
|
|
3105
|
+
return session;
|
|
3106
|
+
};
|
|
3107
|
+
try {
|
|
3108
|
+
let session;
|
|
3109
|
+
try {
|
|
3110
|
+
session = await attemptOpen();
|
|
3111
|
+
} catch (firstError) {
|
|
3112
|
+
const message = firstError instanceof Error ? firstError.message : String(firstError);
|
|
3113
|
+
if (!(config.mode === "isolated" && generation === this.generation && !this.disposed && !/No Chrome binary found/i.test(message))) throw firstError;
|
|
3114
|
+
session = await attemptOpen();
|
|
3115
|
+
}
|
|
2915
3116
|
this.session = session;
|
|
2916
3117
|
this.lastError = void 0;
|
|
2917
3118
|
this.broadcast({
|
|
@@ -3156,6 +3357,7 @@ function makeRoutes(deps) {
|
|
|
3156
3357
|
routes: [{
|
|
3157
3358
|
kind: "exact",
|
|
3158
3359
|
path: BROWSER_VIEW_STATE_PATH,
|
|
3360
|
+
auth: "anonymous",
|
|
3159
3361
|
handler: (req, res) => {
|
|
3160
3362
|
if (!isLoopbackRequest(req)) {
|
|
3161
3363
|
writeJson(res, 403, { error: "forbidden: loopback-only" });
|
|
@@ -3170,6 +3372,7 @@ function makeRoutes(deps) {
|
|
|
3170
3372
|
}],
|
|
3171
3373
|
upgrade: {
|
|
3172
3374
|
path: BROWSER_VIEW_SOCKET_PATH,
|
|
3375
|
+
auth: "anonymous",
|
|
3173
3376
|
handler: (req, socket, head) => {
|
|
3174
3377
|
if (!isLoopbackRequest(req)) {
|
|
3175
3378
|
socket.write("HTTP/1.1 403 Forbidden\r\nConnection: close\r\n\r\n");
|
|
@@ -3214,7 +3417,7 @@ function writeJson(res, status, body) {
|
|
|
3214
3417
|
res.end(text);
|
|
3215
3418
|
}
|
|
3216
3419
|
//#endregion
|
|
3217
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-typert-protocol@0.2.2-rc.
|
|
3420
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-typert-protocol@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-typert-protocol/lib/index.js
|
|
3218
3421
|
/** The one Remote failure class shared by owners, the Gateway, and consumers. */
|
|
3219
3422
|
/**
|
|
3220
3423
|
* One Remote call failure: a real Error carrying its stable code and typed
|
|
@@ -3396,7 +3599,7 @@ function validateName(subject, value) {
|
|
|
3396
3599
|
if (!isTypertRemoteSegment(value)) throw new TypeError(`typert-protocol: ${subject} must contain only RPC endpoint segment characters`);
|
|
3397
3600
|
}
|
|
3398
3601
|
//#endregion
|
|
3399
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-util-values@0.2.2-rc.
|
|
3602
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-util-values@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-util-values/lib/index.js
|
|
3400
3603
|
/**
|
|
3401
3604
|
* Lazily scanned view of one JSON object's top-level fields, built from text
|
|
3402
3605
|
* that may still be streaming or from an already parsed object. Nothing is
|
|
@@ -5102,11 +5305,11 @@ defineMethod("transform", [
|
|
|
5102
5305
|
"preserve"
|
|
5103
5306
|
], ({ inner }, isInner) => inner.toString(isInner));
|
|
5104
5307
|
//#endregion
|
|
5105
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-timeout@0.2.2-rc.
|
|
5308
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-timeout@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-timeout/lib/index.js
|
|
5106
5309
|
/** Largest delay Node schedules without clamping it to one millisecond. */
|
|
5107
5310
|
const MAX_TIMER_DELAY_MS = 2147483647;
|
|
5108
5311
|
//#endregion
|
|
5109
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-error@0.2.2-rc.
|
|
5312
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-error@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-error/lib/index.js
|
|
5110
5313
|
/**
|
|
5111
5314
|
* Harness error base with a stable machine-routable code and chained cause.
|
|
5112
5315
|
* Package errors extend it so tool results and replay can retain failure class.
|
|
@@ -5128,7 +5331,7 @@ var HarnessError = class extends Error {
|
|
|
5128
5331
|
}
|
|
5129
5332
|
};
|
|
5130
5333
|
//#endregion
|
|
5131
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-llm@0.2.2-rc.
|
|
5334
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-llm@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0_@deepseek-ai+dsh-error@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0_/node_modules/@deepseek-ai/dsh-llm/lib/index.js
|
|
5132
5335
|
/**
|
|
5133
5336
|
* Detach and deep-freeze a message whose identity already exists.
|
|
5134
5337
|
* @param message - complete message, including its stable identity.
|
|
@@ -6397,7 +6600,7 @@ function detachDirectoryEntry(entry) {
|
|
|
6397
6600
|
};
|
|
6398
6601
|
}
|
|
6399
6602
|
//#endregion
|
|
6400
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.2-rc.
|
|
6603
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.2-rc.3_c6df380a2007cdef080fa53578fb6f5f/node_modules/@deepseek-ai/dsh-tools/lib/shared-DGx6D7zk.js
|
|
6401
6604
|
/** The selected provider is missing or unloaded; another provider must not take its calls. */
|
|
6402
6605
|
var ToolExecutorUnavailableError = class extends HarnessError {
|
|
6403
6606
|
constructor() {
|
|
@@ -6934,7 +7137,7 @@ var ToolActivationError = class extends HarnessError {
|
|
|
6934
7137
|
}
|
|
6935
7138
|
};
|
|
6936
7139
|
//#endregion
|
|
6937
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2.2-rc.
|
|
7140
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2.2-rc.3_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-scope/lib/index.js
|
|
6938
7141
|
/**
|
|
6939
7142
|
* Shared insertion-ordered storage and effect ownership for scope-aware registries.
|
|
6940
7143
|
*
|
|
@@ -7187,7 +7390,7 @@ function scopeOf(ctx) {
|
|
|
7187
7390
|
return ctx[kScope];
|
|
7188
7391
|
}
|
|
7189
7392
|
//#endregion
|
|
7190
|
-
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.2-rc.
|
|
7393
|
+
//#region ../../node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.2-rc.3_c6df380a2007cdef080fa53578fb6f5f/node_modules/@deepseek-ai/dsh-tools/lib/index.js
|
|
7191
7394
|
/** Unified JSON-value schema DSL, inference, compilation, and tool definition helpers. @module dsh-tools/schema */
|
|
7192
7395
|
const ANNOTATION_KEYS = [
|
|
7193
7396
|
"description",
|
|
@@ -8556,6 +8759,44 @@ function effectiveConfig(config) {
|
|
|
8556
8759
|
const name = "browser-view";
|
|
8557
8760
|
/** Services required before the routes and the tools can mount. */
|
|
8558
8761
|
const inject = ["webServer", "tools"];
|
|
8762
|
+
function readWebServer(ctx) {
|
|
8763
|
+
if (ctx.webServer !== void 0) return ctx.webServer;
|
|
8764
|
+
if (typeof ctx.get !== "function") return void 0;
|
|
8765
|
+
try {
|
|
8766
|
+
return ctx.get("webServer");
|
|
8767
|
+
} catch {
|
|
8768
|
+
return;
|
|
8769
|
+
}
|
|
8770
|
+
}
|
|
8771
|
+
/**
|
|
8772
|
+
* Resolve the host's authenticated entry URL for `url` across SDK cohorts:
|
|
8773
|
+
* legacy hosts expose `connection.authenticatedUrl(url)`, while peer-auth
|
|
8774
|
+
* hosts collect entry URLs via `ctx.emit(webServer, 'webserver/entry-url', url, entries)`.
|
|
8775
|
+
*/
|
|
8776
|
+
function resolveAuthenticatedUrl(ctx, url) {
|
|
8777
|
+
let connection;
|
|
8778
|
+
if (typeof ctx.get === "function") try {
|
|
8779
|
+
connection = ctx.get("connection");
|
|
8780
|
+
} catch {
|
|
8781
|
+
connection = void 0;
|
|
8782
|
+
}
|
|
8783
|
+
if (connection !== void 0 && typeof connection.authenticatedUrl === "function") try {
|
|
8784
|
+
return connection.authenticatedUrl(url);
|
|
8785
|
+
} catch {
|
|
8786
|
+
return;
|
|
8787
|
+
}
|
|
8788
|
+
const webServer = readWebServer(ctx);
|
|
8789
|
+
if (webServer === void 0 || typeof ctx.emit !== "function") return void 0;
|
|
8790
|
+
const entries = [];
|
|
8791
|
+
try {
|
|
8792
|
+
ctx.emit(webServer, "webserver/entry-url", url, entries);
|
|
8793
|
+
} catch {
|
|
8794
|
+
return;
|
|
8795
|
+
}
|
|
8796
|
+
const preferred = entries.find((entry) => entry.open === true && typeof entry.url === "string" && entry.url.length > 0);
|
|
8797
|
+
if (preferred?.url !== void 0) return preferred.url;
|
|
8798
|
+
return entries.find((entry) => typeof entry.url === "string" && entry.url.length > 0)?.url;
|
|
8799
|
+
}
|
|
8559
8800
|
/**
|
|
8560
8801
|
* Mount the routes, the tools, and the browser lifetime.
|
|
8561
8802
|
* @param ctx - host plugin context carrying webServer and tools.
|
|
@@ -8570,11 +8811,10 @@ function apply(ctx, config) {
|
|
|
8570
8811
|
} : { mode: "isolated" };
|
|
8571
8812
|
},
|
|
8572
8813
|
idleCloseDays: () => effectiveConfig(config).idleCloseDays,
|
|
8573
|
-
authenticatedUrl: (url) =>
|
|
8574
|
-
|
|
8575
|
-
if (connection === void 0 || typeof connection.authenticatedUrl !== "function") return void 0;
|
|
8814
|
+
authenticatedUrl: (url) => resolveAuthenticatedUrl(ctx, url),
|
|
8815
|
+
hostOrigin: () => {
|
|
8576
8816
|
try {
|
|
8577
|
-
return
|
|
8817
|
+
return ctx.webServer.getOrigin();
|
|
8578
8818
|
} catch {
|
|
8579
8819
|
return;
|
|
8580
8820
|
}
|
|
@@ -8617,4 +8857,4 @@ function apply(ctx, config) {
|
|
|
8617
8857
|
}, "browser-view: browser");
|
|
8618
8858
|
}
|
|
8619
8859
|
//#endregion
|
|
8620
|
-
export { Config, apply, inject, name };
|
|
8860
|
+
export { Config, apply, inject, name, resolveAuthenticatedUrl };
|