dsh-builtin-browser 1.0.3 → 1.0.4
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 +89 -0
- package/browser-extension/constants.mjs +20 -0
- package/browser-extension/controller.mjs +293 -0
- package/browser-extension/locales.mjs +15 -0
- package/browser-extension/manifest.json +12 -0
- package/browser-extension/options.html +14 -0
- package/browser-extension/options.mjs +9 -0
- package/browser-extension/permission-guard.mjs +13 -0
- package/browser-extension/worker.mjs +74 -0
- package/package.json +20 -2
- package/scripts/build-client.mjs +305 -0
- package/scripts/build.mjs +69 -0
- package/scripts/bundle-host.mjs +28 -0
- package/scripts/fix-exports.mjs +40 -0
- package/scripts/install-electron.mjs +101 -0
- package/scripts/pack.mjs +99 -0
- package/scripts/publish-manifest.mjs +56 -0
- package/scripts/verify-exports.mjs +58 -0
- package/scripts/verify-preview-sdk.mjs +93 -0
- package/skills/dsh-builtin-browser/SKILL.md +98 -0
- package/skills/dsh-builtin-browser/references/batch.md +68 -0
- package/skills/dsh-builtin-browser/references/deliver.md +31 -0
- package/skills/dsh-builtin-browser/references/locate.md +11 -0
- package/skills/dsh-builtin-browser/references/recover.md +11 -0
- package/skills/dsh-builtin-browser/references/verify.md +13 -0
- package/skills/dsh-debug-host/SKILL.md +56 -0
- package/skills/dsh-debug-self/SKILL.md +50 -0
- package/src/bridge-compatibility.ts +39 -0
- package/src/browser/anti-bot.ts +251 -0
- package/src/browser/deep-dom.ts +40 -0
- package/src/browser/handles.ts +89 -0
- package/src/browser/runtime.ts +578 -0
- package/src/browser/takeover-target.ts +45 -0
- package/src/browser/types.ts +870 -0
- package/src/browser-electron/authenticated-route.ts +109 -0
- package/src/browser-electron/automatic-maintenance.ts +736 -0
- package/src/browser-electron/bridge-auto.ts +159 -0
- package/src/browser-electron/bridge-connection.ts +386 -0
- package/src/browser-electron/bridge-endpoint.ts +129 -0
- package/src/browser-electron/bridge-install.ts +290 -0
- package/src/browser-electron/bridge-maintenance.ts +189 -0
- package/src/browser-electron/bridge-status.ts +386 -0
- package/src/browser-electron/desktop-bridge-host.ts +253 -0
- package/src/browser-electron/desktop-identity.ts +353 -0
- package/src/browser-electron/desktop-shell.ts +100 -0
- package/src/browser-electron/document-readiness.ts +45 -0
- package/src/browser-electron/electron-provision.ts +347 -0
- package/src/browser-electron/entry.ts +1378 -0
- package/src/browser-electron/ephemeral-profile.ts +189 -0
- package/src/browser-electron/extension-browser.ts +230 -0
- package/src/browser-electron/extension-setup.ts +67 -0
- package/src/browser-electron/file-write.ts +31 -0
- package/src/browser-electron/foreground-watch.ts +142 -0
- package/src/browser-electron/guest-cookie-jar.ts +177 -0
- package/src/browser-electron/guest-cookie-store.ts +59 -0
- package/src/browser-electron/guest-css-runtime.ts +76 -0
- package/src/browser-electron/guest-css.ts +68 -0
- package/src/browser-electron/guest-route.ts +716 -0
- package/src/browser-electron/guest-runtime.ts +408 -0
- package/src/browser-electron/guest-storage-runtime.ts +54 -0
- package/src/browser-electron/guest-storage.ts +120 -0
- package/src/browser-electron/history-store.ts +224 -0
- package/src/browser-electron/host-main.ts +1385 -0
- package/src/browser-electron/host-patch-maintenance.ts +121 -0
- package/src/browser-electron/http-body.ts +65 -0
- package/src/browser-electron/json-reply.ts +47 -0
- package/src/browser-electron/maintenance-broker.ts +166 -0
- package/src/browser-electron/maintenance-lifecycle.ts +91 -0
- package/src/browser-electron/maintenance-route.ts +68 -0
- package/src/browser-electron/missing-system-browser.ts +114 -0
- package/src/browser-electron/open-slot.ts +49 -0
- package/src/browser-electron/paths.ts +25 -0
- package/src/browser-electron/preferred-browser.ts +130 -0
- package/src/browser-electron/preview-route.ts +215 -0
- package/src/browser-electron/process-ownership.ts +174 -0
- package/src/browser-electron/process.ts +23 -0
- package/src/browser-electron/profile-checkpoint.ts +187 -0
- package/src/browser-electron/profile-command.ts +47 -0
- package/src/browser-electron/profile-extension.ts +129 -0
- package/src/browser-electron/profile-lease.ts +211 -0
- package/src/browser-electron/profile-residue.ts +49 -0
- package/src/browser-electron/provider-core.ts +1107 -0
- package/src/browser-electron/provider-interaction.ts +1034 -0
- package/src/browser-electron/provider-media.ts +589 -0
- package/src/browser-electron/provider-navigation.ts +323 -0
- package/src/browser-electron/provider-observation.ts +664 -0
- package/src/browser-electron/provider-tabs.ts +372 -0
- package/src/browser-electron/provider.ts +666 -0
- package/src/browser-electron/reference-route.ts +598 -0
- package/src/browser-electron/remote-host.ts +1538 -0
- package/src/browser-electron/rpc-input.ts +13 -0
- package/src/browser-electron/rpc-ops.ts +41 -0
- package/src/browser-electron/runtime-diagnostics.ts +38 -0
- package/src/browser-electron/runtime-route.ts +105 -0
- package/src/browser-electron/runtime-status.ts +309 -0
- package/src/browser-electron/settings-route.ts +64 -0
- package/src/browser-electron/settings-store.ts +593 -0
- package/src/browser-electron/shortcuts-route.ts +112 -0
- package/src/browser-electron/sidebar-only-host.ts +300 -0
- package/src/browser-electron/startpage-shortcuts.ts +213 -0
- package/src/browser-electron/system-browser.ts +1850 -0
- package/src/browser-electron/tauri-host.ts +194 -0
- package/src/browser-electron/timing.ts +16 -0
- package/src/browser-electron/virtual-cursor.ts +162 -0
- package/src/browser-electron/windows-system.ts +24 -0
- package/src/browser-reference/delivery.ts +384 -0
- package/src/browser-reference/entry.ts +631 -0
- package/src/browser-reference/export.ts +339 -0
- package/src/browser-reference/import.ts +303 -0
- package/src/browser-reference/page-script.ts +1537 -0
- package/src/browser-reference/service.ts +1346 -0
- package/src/browser-reference/store.ts +172 -0
- package/src/browser-reference/text-quote.ts +219 -0
- package/src/browser-reference/types.ts +195 -0
- package/src/browser-reference/visible.ts +367 -0
- package/src/browser-reference/web-sources.ts +106 -0
- package/src/client/apply-guard.ts +22 -0
- package/src/client/browser/BrowserController.ts +693 -0
- package/src/client/browser/BrowserFrame.ts +78 -0
- package/src/client/browser/BrowserNavigation.ts +169 -0
- package/src/client/browser/BrowserPage.ts +23 -0
- package/src/client/browser/BrowserPersistence.ts +44 -0
- package/src/client/browser/IframeImpl.ts +182 -0
- package/src/client/browser/child-tabs.ts +14 -0
- package/src/client/browser/frame-history.ts +125 -0
- package/src/client/browser/frame-state.ts +27 -0
- package/src/client/browser/iframe-reference.ts +67 -0
- package/src/client/browser/initialization.ts +262 -0
- package/src/client/browser/omnibox.ts +243 -0
- package/src/client/browser/store.ts +38 -0
- package/src/client/browser/takeover-channel.ts +72 -0
- package/src/client/browser/url.ts +46 -0
- package/src/client/browser/web-reference-source.ts +56 -0
- package/src/client/css-modules.d.ts +4 -0
- package/src/client/definition.tsx +36 -0
- package/src/client/electron/ElectronWebViewImpl.ts +371 -0
- package/src/client/electron/ElectronWebviewPresentation.ts +140 -0
- package/src/client/electron/NativeChildPresentation.ts +53 -0
- package/src/client/electron/NativeViewPage.ts +265 -0
- package/src/client/electron/pages.ts +23 -0
- package/src/client/electron/reference-overlay.ts +53 -0
- package/src/client/electron/workspace.ts +33 -0
- package/src/client/index.ts +333 -0
- package/src/client/locales.ts +860 -0
- package/src/client/pages.ts +28 -0
- package/src/client/reference/client/BrowserRefLink.tsx +142 -0
- package/src/client/reference/client/draft-reference.ts +167 -0
- package/src/client/reference/client/index.ts +7 -0
- package/src/client/reference/client/ordered-submission.ts +108 -0
- package/src/client/reference/client/pending-delivery.ts +216 -0
- package/src/client/reference/client/plugin.ts +208 -0
- package/src/client/reference/client/production/ReferenceCapsules.tsx +345 -0
- package/src/client/reference/client/production/ReferenceDock.module.css +193 -0
- package/src/client/reference/client/production/ReferenceDock.tsx +6 -0
- package/src/client/reference/client/production/ReferenceFeedback.tsx +15 -0
- package/src/client/reference/client/production/ReferenceMath.tsx +44 -0
- package/src/client/reference/client/production/ReferenceText.tsx +36 -0
- package/src/client/reference/client/production/assembly.ts +447 -0
- package/src/client/reference/client/production/asset-store.ts +144 -0
- package/src/client/reference/client/production/availability.ts +72 -0
- package/src/client/reference/client/production/bytes.ts +36 -0
- package/src/client/reference/client/production/composer-attachments.ts +44 -0
- package/src/client/reference/client/production/delivery-client.ts +211 -0
- package/src/client/reference/client/production/draft-adapter.ts +512 -0
- package/src/client/reference/client/production/http-transport.ts +212 -0
- package/src/client/reference/client/production/production-submission.ts +70 -0
- package/src/client/reference/client/production/protocol.ts +234 -0
- package/src/client/reference/client/production/reference-card.ts +240 -0
- package/src/client/reference/client/production/reference-labels.ts +29 -0
- package/src/client/reference/client/production/reply-link-bridge.ts +222 -0
- package/src/client/reference/client/production/reveal.ts +215 -0
- package/src/client/reference/client/production/runtime.ts +1056 -0
- package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
- package/src/client/reference/client/production/source-marker.ts +99 -0
- package/src/client/reference/client/production/source-opener.ts +55 -0
- package/src/client/reference/client/production/styles.ts +104 -0
- package/src/client/reference/client/production/user-text-rule.ts +67 -0
- package/src/client/reference/client/reveal.ts +109 -0
- package/src/client/reference/client/scheme.ts +114 -0
- package/src/client/reference/client/session-schedule.ts +36 -0
- package/src/client/reference/client/types.ts +168 -0
- package/src/client/reference/css-modules.d.ts +4 -0
- package/src/client/reference/index.ts +11 -0
- package/src/client/reference-capture-owner.ts +162 -0
- package/src/client/reference-intents.ts +36 -0
- package/src/client/settings/index.ts +42 -0
- package/src/client/settings/mount-guard.ts +31 -0
- package/src/client/settings/panel.ts +2768 -0
- package/src/client/shortcut-open.ts +30 -0
- package/src/client/startpage/binding.ts +99 -0
- package/src/client/startpage/controller.ts +300 -0
- package/src/client/startpage/model.ts +279 -0
- package/src/client/view/Browser.module.css +751 -0
- package/src/client/view/BrowserBody.tsx +315 -0
- package/src/client/view/BrowserPresentation.ts +9 -0
- package/src/client/view/BrowserTitle.tsx +17 -0
- package/src/client/view/IframePresentation.ts +365 -0
- package/src/client/view/StartPage.tsx +598 -0
- package/src/client/view/TakeoverBanner.tsx +21 -0
- package/src/compat/host-features.ts +92 -0
- package/src/index.ts +110 -0
- package/src/reference-owner.ts +5 -0
- package/src/reference-page.ts +9 -0
- package/src/reference-source.ts +3 -0
- package/src/reference-text.ts +219 -0
- package/src/startpage-settings.ts +103 -0
- package/src/startpage.ts +71 -0
- package/src/takeover-protocol.ts +28 -0
- package/src/tool-browser/block-recovery.ts +85 -0
- package/src/tool-browser/code-tool.ts +555 -0
- package/src/tool-browser/code-worker.ts +725 -0
- package/src/tool-browser/element-fields.ts +167 -0
- package/src/tool-browser/errors.ts +40 -0
- package/src/tool-browser/index.ts +265 -0
- package/src/tool-browser/page-probe.ts +675 -0
- package/src/tool-browser/panel-page.ts +126 -0
- package/src/tool-browser/probe-client.ts +183 -0
- package/src/tool-browser/screenshot-annotations.ts +131 -0
- package/src/tool-browser/screenshot-image.ts +49 -0
- package/src/tool-browser/state.ts +375 -0
- package/src/tool-browser/takeover.ts +199 -0
- package/src/tool-browser/tools-debug.ts +806 -0
- package/src/tool-browser/tools-interaction.ts +956 -0
- package/src/tool-browser/tools-navigation.ts +786 -0
- package/src/tool-browser/tools-observation.ts +474 -0
- package/src/tool-browser/tools-reference.ts +294 -0
- package/src/types/electron-shim.d.ts +144 -0
- package/src/types.ts +85 -0
- package/src/web-guest.ts +35 -0
- package/tools/accept-desktop.mjs +148 -0
- package/dist/client.d.cts +0 -516
- package/dist/client.d.mts +0 -516
- package/dist/index.cjs +0 -92
- package/dist/index.d.mts +0 -2960
- package/dist/index.mjs +0 -24
- package/dsh-builtin-browser-1.0.3-publish.tgz +0 -0
- package/dsh-builtin-browser-1.0.3.tgz +0 -0
- package/dsh-host-patch/sources/main/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/main/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/manifest.json +0 -218
- package/dsh-host-patch/sources/rc3/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc3/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0001-feat-sidebar-right-add-session-rendering-holds.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0002-feat-desktop-load-trusted-profile-main-extensions.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0003-feat-desktop-report-resolved-and-running-main-extens.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0004-feat-desktop-compose-admitted-native-sidebar-views.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0005-fix-client-admit-coded-browser-errors-in-native-comp.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0006-fix-desktop-acknowledge-native-same-document-navigat.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0007-fix-desktop-restore-auth-in-the-native-lease-partiti.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0008-feat-desktop-adopt-native-children-in-admitted-sideb.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0009-fix-desktop-publish-complete-native-child-close-reco.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0010-fix-desktop-bundle-structured-errors-in-sandboxed-pr.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0011-feat-desktop-offer-persistent-Sidebar-sessions-per-D.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0012-feat-desktop-retain-sidebar-session-cookies-across-r.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0013-fix-desktop-honor-sidebar-session-cookie-sidecar-con.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0014-fix-desktop-retry-cookie-protection-without-failing-.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0015-fix-desktop-preserve-host-only-cookie-identity-in-se.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0016-fix-desktop-restore-session-cookies-before-checkpoin.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0017-fix-desktop-restore-sidebar-cookies-once-before-gues.patch.gz +0 -0
- package/dsh-host-patch/sources/rc5/0018-fix-sidebar-right-follow-animated-native-slot-placem.patch.gz +0 -0
- package/dsh-host-patch/sources/series.json +0 -260
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { DEFAULT_OPERATION_TIMEOUT_MS } from '../../assets/browser-policy.mjs'
|
|
2
|
+
import { setLastOpen } from './open-slot.ts'
|
|
3
|
+
import { forgetCursor } from './virtual-cursor.ts'
|
|
4
|
+
import { documentReady, mainDocument, type DocumentIdentity } from './document-readiness.ts'
|
|
5
|
+
import type { BrowserOpenRequest, BrowserSessionId } from '../browser/types.ts'
|
|
6
|
+
import { BrowserError } from '../browser/types.ts'
|
|
7
|
+
import { PROVIDER_TIMEOUTS, CDP_PAGE_NAVIGATE, delay, withTimeout, handleSendEvaluate, type ElectronViewHandle, type Tab, type Session, type CdpNavigateParams } from './provider-core.ts'
|
|
8
|
+
import { ProviderTabs } from './provider-tabs.ts'
|
|
9
|
+
|
|
10
|
+
/** Poll interval for the document-settle loop. */
|
|
11
|
+
const SETTLE_POLL_MS = 25
|
|
12
|
+
|
|
13
|
+
export abstract class ProviderNavigation extends ProviderTabs {
|
|
14
|
+
async openUrl(session: BrowserSessionId, request: BrowserOpenRequest, signal?: AbortSignal): Promise<void> {
|
|
15
|
+
try { setLastOpen(request.url, Date.now()) } catch { /* best effort */ }
|
|
16
|
+
const s = this.session(session)
|
|
17
|
+
await this.prepareCarrier(signal, s.id)
|
|
18
|
+
if (request.newTab === true) {
|
|
19
|
+
this.newTab(s)
|
|
20
|
+
}
|
|
21
|
+
// A page the human already has, at the URL being asked for, is the page they mean.
|
|
22
|
+
//
|
|
23
|
+
// Reported as a defect: they opened a page by hand, then a tool call drove the plugin's own
|
|
24
|
+
// blank tab instead and reported nothing about the page on screen — so the obvious conclusion
|
|
25
|
+
// was "the page is broken", and opening the same URL again produced a SECOND tab. Reusing the
|
|
26
|
+
// existing page is both what the request says and what a person expects.
|
|
27
|
+
//
|
|
28
|
+
// Only an exact match after normalisation: a deliberate navigation to a different URL must not
|
|
29
|
+
// be redirected to whatever page happens to be open.
|
|
30
|
+
const tab = this.activeTab(s)
|
|
31
|
+
const transaction = this.beginNavigation(tab, signal)
|
|
32
|
+
const { navigation } = transaction
|
|
33
|
+
signal = transaction.signal
|
|
34
|
+
if (request.newTab !== true && await this.adoptMatchingPage(s, request.url, tab, navigation, signal)) return
|
|
35
|
+
await this.navigateTab(s, tab, request.url, navigation, signal)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Navigate the active tab's view to a URL, honoring HTTP(S)-only admission. */
|
|
39
|
+
async navigate(session: BrowserSessionId, request: { readonly url: string }, signal?: AbortSignal): Promise<void> {
|
|
40
|
+
const s = this.session(session)
|
|
41
|
+
await this.prepareCarrier(signal, s.id)
|
|
42
|
+
const tab = this.activeTab(s)
|
|
43
|
+
const transaction = this.beginNavigation(tab, signal)
|
|
44
|
+
const { navigation } = transaction
|
|
45
|
+
signal = transaction.signal
|
|
46
|
+
await this.navigateTab(s, tab, request.url, navigation, signal)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private beginNavigation(tab: Tab, signal?: AbortSignal): { navigation: symbol; signal: AbortSignal } {
|
|
50
|
+
signal?.throwIfAborted()
|
|
51
|
+
const previous = tab.navigationAbort
|
|
52
|
+
tab.navigation = Symbol()
|
|
53
|
+
tab.navigationAbort = new AbortController()
|
|
54
|
+
previous?.abort(Object.assign(new Error('a newer navigation was requested for this browser tab'), { code: 'panel-navigation-superseded' }))
|
|
55
|
+
return { navigation: tab.navigation, signal: signal === undefined ? tab.navigationAbort.signal : AbortSignal.any([signal, tab.navigationAbort.signal]) }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
protected checkNavigation(tab: Tab, navigation: symbol): void {
|
|
59
|
+
if (tab.failure !== undefined) throw tab.failure
|
|
60
|
+
if (![...this.sessions.values()].some(session => session.tabs.includes(tab))) {
|
|
61
|
+
throw new BrowserError('browser: the navigation guest was closed', 'BROWSER_GUEST_CLOSED')
|
|
62
|
+
}
|
|
63
|
+
if (tab.navigation !== navigation) {
|
|
64
|
+
throw Object.assign(new Error('a newer navigation was requested for this browser tab'), { code: 'panel-navigation-superseded' })
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private async navigateTab(s: Session, tab: Tab, url: string, navigation: symbol, signal?: AbortSignal): Promise<void> {
|
|
69
|
+
const { handle } = tab
|
|
70
|
+
this.checkNavigation(tab, navigation)
|
|
71
|
+
try {
|
|
72
|
+
if (this.httpOnly) {
|
|
73
|
+
let parsed: URL
|
|
74
|
+
try {
|
|
75
|
+
parsed = new URL(url)
|
|
76
|
+
} catch {
|
|
77
|
+
throw new BrowserError(`browser: refusing navigation to unparseable URL "${url}"`, 'BROWSER_NAVIGATION_BLOCKED')
|
|
78
|
+
}
|
|
79
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
80
|
+
throw new BrowserError(`browser: refusing navigation to non-HTTP(S) URL "${url}"`, 'BROWSER_NAVIGATION_BLOCKED')
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
signal?.throwIfAborted()
|
|
84
|
+
// Page.navigate can hang on an unreachable/slow host; bound it like the
|
|
85
|
+
// evaluate paths so a wedged navigation surfaces as an error instead of
|
|
86
|
+
// blocking the tool call forever.
|
|
87
|
+
const timeoutMs = DEFAULT_OPERATION_TIMEOUT_MS
|
|
88
|
+
const deadline = Date.now() + timeoutMs
|
|
89
|
+
// Document identity of the page we are leaving (see settleDocument).
|
|
90
|
+
const before = await this.documentIdentity(handle, signal, () => { this.checkNavigation(tab, navigation) }, deadline).catch(() => undefined)
|
|
91
|
+
this.checkNavigation(tab, navigation)
|
|
92
|
+
signal?.throwIfAborted()
|
|
93
|
+
const result = await withTimeout(
|
|
94
|
+
handle.sendCommand(CDP_PAGE_NAVIGATE, { url } satisfies CdpNavigateParams, { deadline, signal }),
|
|
95
|
+
Math.max(1, deadline - Date.now()),
|
|
96
|
+
signal,
|
|
97
|
+
`browser: navigation timed out after ${timeoutMs}ms`,
|
|
98
|
+
// A wedged navigation quarantines the guest. A cancelled one only stops loading:
|
|
99
|
+
// terminating script execution here, with no script running, would kill the next
|
|
100
|
+
// evaluation instead, so the tab's next operation stalls into quarantine.
|
|
101
|
+
timedOut => {
|
|
102
|
+
if (tab.navigation !== navigation) return
|
|
103
|
+
if (timedOut) this.interrupt(handle, timedOut)
|
|
104
|
+
// Never initialize a guest just to stop it: a cancelled first sidebar load must not reopen the sidebar.
|
|
105
|
+
else void handle.sendCommand('Page.stopLoading', undefined, { present: false, initialize: false }).catch(() => {})
|
|
106
|
+
},
|
|
107
|
+
)
|
|
108
|
+
// Page.navigate resolves even when the navigation fails; surface the
|
|
109
|
+
// failure instead of leaving a silent white screen.
|
|
110
|
+
this.checkNavigation(tab, navigation)
|
|
111
|
+
const errorText = (result as { errorText?: string } | undefined)?.errorText
|
|
112
|
+
if (typeof errorText === 'string' && errorText !== '') {
|
|
113
|
+
throw new BrowserError(`browser: navigation to "${url}" failed: ${errorText}`, 'BROWSER_NAVIGATION_FAILED')
|
|
114
|
+
}
|
|
115
|
+
signal?.throwIfAborted()
|
|
116
|
+
const acknowledgement = result as { frameId?: string; loaderId?: string } | undefined
|
|
117
|
+
if (typeof acknowledgement?.frameId !== 'string' || acknowledgement.frameId === '') {
|
|
118
|
+
throw new BrowserError('browser: navigation returned no frame acknowledgement', 'BROWSER_DOCUMENT_UNACKNOWLEDGED')
|
|
119
|
+
}
|
|
120
|
+
if (acknowledgement.loaderId === undefined ? before === undefined
|
|
121
|
+
: typeof acknowledgement.loaderId !== 'string' || acknowledgement.loaderId === '') {
|
|
122
|
+
throw new BrowserError('browser: navigation returned no document acknowledgement', 'BROWSER_DOCUMENT_UNACKNOWLEDGED')
|
|
123
|
+
}
|
|
124
|
+
tab.url = url
|
|
125
|
+
await this.settleDocument(handle, before, signal, acknowledgement, () => { this.checkNavigation(tab, navigation) }, undefined, deadline)
|
|
126
|
+
this.checkNavigation(tab, navigation)
|
|
127
|
+
this.record(s, 'navigate', { url }, true)
|
|
128
|
+
this.recordVisit(s, handle)
|
|
129
|
+
this.showActive(s, true)
|
|
130
|
+
} catch (error) {
|
|
131
|
+
const code = (error as { code?: string })?.code
|
|
132
|
+
if (tab.navigation === navigation && (code === 'BROWSER_DOCUMENT_TIMEOUT' || code === 'BROWSER_DOCUMENT_UNACKNOWLEDGED')) {
|
|
133
|
+
this.quarantine(handle)
|
|
134
|
+
}
|
|
135
|
+
if (!(error instanceof BrowserError && (error as { code?: string }).code === 'BROWSER_NAVIGATION_BLOCKED')) {
|
|
136
|
+
this.record(s, 'navigate', { url }, false, { error: String(error) })
|
|
137
|
+
}
|
|
138
|
+
throw error
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
protected async documentIdentity(handle: ElectronViewHandle, signal?: AbortSignal, checkCurrent?: () => void,
|
|
143
|
+
deadline = Date.now() + PROVIDER_TIMEOUTS.evaluation, allowErrorDocument = false): Promise<DocumentIdentity> {
|
|
144
|
+
signal?.throwIfAborted()
|
|
145
|
+
checkCurrent?.()
|
|
146
|
+
return mainDocument(await withTimeout(
|
|
147
|
+
handle.sendCommand('Page.getFrameTree', undefined, { present: false, initialize: false }),
|
|
148
|
+
Math.max(1, Math.min(PROVIDER_TIMEOUTS.evaluation, deadline - Date.now())), signal, 'browser: document identity timed out', timedOut => {
|
|
149
|
+
try { checkCurrent?.() } catch { return }
|
|
150
|
+
this.interrupt(handle, timedOut)
|
|
151
|
+
},
|
|
152
|
+
), { allowErrorDocument })
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Page.navigate resolves at navigation COMMIT, not at load: the new document
|
|
157
|
+
* is already current (so location.href and document.title are the new page's)
|
|
158
|
+
* while its DOM is still being parsed. dsh_browser_open snapshots immediately
|
|
159
|
+
* after navigating, which is why it could report the right title with zero
|
|
160
|
+
* interactive elements — and why a separate dsh_browser_snapshot right after
|
|
161
|
+
* always found them.
|
|
162
|
+
*
|
|
163
|
+
* The CDP frame/loader acknowledgement, not elapsed time or URL equality,
|
|
164
|
+
* identifies the document whose parse readiness can complete the transaction.
|
|
165
|
+
*/
|
|
166
|
+
protected async settleDocument(handle: ElectronViewHandle, before: DocumentIdentity | undefined, signal?: AbortSignal,
|
|
167
|
+
acknowledgement?: { readonly frameId?: string; readonly loaderId?: string }, checkCurrent?: () => void,
|
|
168
|
+
historyEntry?: number, deadline = Date.now() + DEFAULT_OPERATION_TIMEOUT_MS, allowErrorDocument = false): Promise<void> {
|
|
169
|
+
// The document is being replaced, so the synthetic pointer drawn into the old one
|
|
170
|
+
// is gone. Dropping the remembered position is what lets it be painted again:
|
|
171
|
+
// without this, a paint at coincidentally identical coordinates would be skipped
|
|
172
|
+
// and the pointer would never come back after a navigation.
|
|
173
|
+
forgetCursor(handle)
|
|
174
|
+
for (;;) {
|
|
175
|
+
signal?.throwIfAborted()
|
|
176
|
+
checkCurrent?.()
|
|
177
|
+
const remaining = deadline - Date.now()
|
|
178
|
+
if (remaining <= 0) {
|
|
179
|
+
this.quarantine(handle)
|
|
180
|
+
throw new BrowserError('browser: the navigation document was not ready within its deadline', 'BROWSER_DOCUMENT_TIMEOUT')
|
|
181
|
+
}
|
|
182
|
+
const ready = await withTimeout((async () => {
|
|
183
|
+
if (historyEntry !== undefined) {
|
|
184
|
+
const history = await handle.sendCommand('Page.getNavigationHistory') as { entries?: Array<{ id?: number }>; currentIndex?: number }
|
|
185
|
+
if (history.entries?.[history.currentIndex ?? -1]?.id !== historyEntry) return false
|
|
186
|
+
}
|
|
187
|
+
const current = await this.documentIdentity(handle, signal, checkCurrent, deadline, allowErrorDocument)
|
|
188
|
+
if (acknowledgement?.frameId !== undefined && current.id !== acknowledgement.frameId) {
|
|
189
|
+
throw new BrowserError('browser: navigation frame was superseded', 'BROWSER_NAVIGATION_SUPERSEDED')
|
|
190
|
+
}
|
|
191
|
+
const loader = acknowledgement?.loaderId ?? (acknowledgement === undefined ? undefined : before?.loaderId)
|
|
192
|
+
if (loader !== undefined && current.loaderId !== loader) {
|
|
193
|
+
if (current.loaderId === before?.loaderId) return false
|
|
194
|
+
throw new BrowserError('browser: navigation document was superseded', 'BROWSER_NAVIGATION_SUPERSEDED')
|
|
195
|
+
}
|
|
196
|
+
if (acknowledgement === undefined && current.loaderId === before?.loaderId) return false
|
|
197
|
+
return documentReady(handle, current, () => {
|
|
198
|
+
signal?.throwIfAborted()
|
|
199
|
+
checkCurrent?.()
|
|
200
|
+
if (Date.now() >= deadline) {
|
|
201
|
+
this.quarantine(handle)
|
|
202
|
+
throw new BrowserError('browser: document readiness deadline expired', 'BROWSER_DOCUMENT_TIMEOUT')
|
|
203
|
+
}
|
|
204
|
+
})
|
|
205
|
+
})(), remaining, signal, 'browser: document readiness timed out', timedOut => {
|
|
206
|
+
try { checkCurrent?.() } catch { return }
|
|
207
|
+
this.interrupt(handle, timedOut)
|
|
208
|
+
})
|
|
209
|
+
signal?.throwIfAborted()
|
|
210
|
+
checkCurrent?.()
|
|
211
|
+
if (ready) return
|
|
212
|
+
await delay(Math.min(SETTLE_POLL_MS, Math.max(0, deadline - Date.now())), signal)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Go back (-1) or forward (+1) in the active tab's navigation history. */
|
|
217
|
+
private async historyStep(session: BrowserSessionId, direction: -1 | 1, signal?: AbortSignal): Promise<void> {
|
|
218
|
+
const s = this.session(session)
|
|
219
|
+
const tab = this.activeTab(s)
|
|
220
|
+
const { handle } = tab
|
|
221
|
+
const transaction = this.beginNavigation(tab, signal)
|
|
222
|
+
const { navigation } = transaction
|
|
223
|
+
signal = transaction.signal
|
|
224
|
+
signal?.throwIfAborted()
|
|
225
|
+
const timeoutMs = DEFAULT_OPERATION_TIMEOUT_MS
|
|
226
|
+
const deadline = Date.now() + timeoutMs
|
|
227
|
+
const hist = await withTimeout(
|
|
228
|
+
handle.sendCommand('Page.getNavigationHistory'),
|
|
229
|
+
timeoutMs,
|
|
230
|
+
signal,
|
|
231
|
+
`browser: history read timed out after ${timeoutMs}ms`,
|
|
232
|
+
) as { entries?: Array<{ id?: number; url?: string }>; currentIndex?: number }
|
|
233
|
+
this.checkNavigation(tab, navigation)
|
|
234
|
+
const entries = hist.entries ?? []
|
|
235
|
+
const currentIndex = hist.currentIndex ?? -1
|
|
236
|
+
const target = currentIndex + direction
|
|
237
|
+
if (target < 0 || target >= entries.length) {
|
|
238
|
+
// Nothing to step to; treat it as a successful no-op so the agent can
|
|
239
|
+
// proceed without an error dance.
|
|
240
|
+
this.record(s, direction === -1 ? 'back' : 'forward', {}, true)
|
|
241
|
+
return
|
|
242
|
+
}
|
|
243
|
+
const entry = entries[target]
|
|
244
|
+
if (entry?.id === undefined) throw new BrowserError('browser: history entry missing id', 'BROWSER_HISTORY_INVALID')
|
|
245
|
+
// A history step is a navigation too: the classic A→B→A redirect would
|
|
246
|
+
// otherwise read the outgoing document's identity (see settleDocument).
|
|
247
|
+
const before = await this.documentIdentity(handle, signal, () => { this.checkNavigation(tab, navigation) }, deadline, true)
|
|
248
|
+
const inPage = await withTimeout(handleSendEvaluate(handle, `(() => {
|
|
249
|
+
if (typeof navigation === 'undefined') return false;
|
|
250
|
+
const entry = navigation.entries().find(entry => entry.index === navigation.currentEntry.index + ${direction});
|
|
251
|
+
return entry?.url === ${JSON.stringify(entry.url)} && entry.sameDocument === true;
|
|
252
|
+
})()`), Math.max(1, deadline - Date.now()), signal, 'browser: history document identity timed out', timedOut => { this.interrupt(handle, timedOut) })
|
|
253
|
+
this.checkNavigation(tab, navigation)
|
|
254
|
+
signal?.throwIfAborted()
|
|
255
|
+
await withTimeout(
|
|
256
|
+
handle.sendCommand('Page.navigateToHistoryEntry', { entryId: entry.id }),
|
|
257
|
+
Math.max(1, deadline - Date.now()),
|
|
258
|
+
signal,
|
|
259
|
+
`browser: history navigation timed out after ${timeoutMs}ms`,
|
|
260
|
+
() => { if (tab.navigation === navigation) void handle.sendCommand('Page.stopLoading').catch(() => {}) },
|
|
261
|
+
)
|
|
262
|
+
await this.settleDocument(handle, before, signal,
|
|
263
|
+
inPage.ok && inPage.value === true ? { frameId: before.id, loaderId: before.loaderId } : undefined,
|
|
264
|
+
() => { this.checkNavigation(tab, navigation) }, entry.id, deadline, true)
|
|
265
|
+
this.record(s, direction === -1 ? 'back' : 'forward', {}, true)
|
|
266
|
+
this.recordVisit(s, handle)
|
|
267
|
+
this.showActive(s)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Go back in the active tab's history. */
|
|
271
|
+
async back(session: BrowserSessionId, signal?: AbortSignal): Promise<void> {
|
|
272
|
+
return this.historyStep(session, -1, signal)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Go forward in the active tab's history. */
|
|
276
|
+
async forward(session: BrowserSessionId, signal?: AbortSignal): Promise<void> {
|
|
277
|
+
return this.historyStep(session, 1, signal)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Reload the active tab. */
|
|
281
|
+
async reload(session: BrowserSessionId, signal?: AbortSignal): Promise<void> {
|
|
282
|
+
const s = this.session(session)
|
|
283
|
+
const tab = this.activeTab(s)
|
|
284
|
+
const { handle } = tab
|
|
285
|
+
const transaction = this.beginNavigation(tab, signal)
|
|
286
|
+
const { navigation } = transaction
|
|
287
|
+
signal = transaction.signal
|
|
288
|
+
signal?.throwIfAborted()
|
|
289
|
+
const timeoutMs = DEFAULT_OPERATION_TIMEOUT_MS
|
|
290
|
+
const deadline = Date.now() + timeoutMs
|
|
291
|
+
// Same-URL reload: only the per-load document identity can tell the new
|
|
292
|
+
// document from the old one, so capture it before reloading.
|
|
293
|
+
const before = await this.documentIdentity(handle, signal, () => { this.checkNavigation(tab, navigation) }, deadline, true)
|
|
294
|
+
this.checkNavigation(tab, navigation)
|
|
295
|
+
signal?.throwIfAborted()
|
|
296
|
+
await withTimeout(
|
|
297
|
+
handle.sendCommand('Page.reload', { ignoreCache: false }),
|
|
298
|
+
Math.max(1, deadline - Date.now()),
|
|
299
|
+
signal,
|
|
300
|
+
`browser: reload timed out after ${timeoutMs}ms`,
|
|
301
|
+
// Best-effort: cancel the reload if it wedges the debugger queue.
|
|
302
|
+
() => { if (tab.navigation === navigation) void handle.sendCommand('Page.stopLoading').catch(() => {}) },
|
|
303
|
+
)
|
|
304
|
+
await this.settleDocument(handle, before, signal, undefined, () => { this.checkNavigation(tab, navigation) }, undefined, deadline, true)
|
|
305
|
+
this.record(s, 'reload', {}, true)
|
|
306
|
+
this.recordVisit(s, handle)
|
|
307
|
+
this.showActive(s)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** Read the current URL of a view through CDP. */
|
|
311
|
+
protected async currentUrl(handle: ElectronViewHandle): Promise<string> {
|
|
312
|
+
// Bound the read: a wedged renderer would otherwise hang listTabs.
|
|
313
|
+
const timeoutMs = PROVIDER_TIMEOUTS.lookup
|
|
314
|
+
const result = await withTimeout(
|
|
315
|
+
handleSendEvaluate(handle, 'location.href'),
|
|
316
|
+
timeoutMs,
|
|
317
|
+
undefined,
|
|
318
|
+
`browser: url read timed out after ${timeoutMs}ms`,
|
|
319
|
+
timedOut => { this.interrupt(handle, timedOut) },
|
|
320
|
+
)
|
|
321
|
+
return result.ok && typeof result.value === 'string' ? result.value : ''
|
|
322
|
+
}
|
|
323
|
+
}
|