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,365 @@
|
|
|
1
|
+
/// <reference path="../css-modules.d.ts" />
|
|
2
|
+
import { GUEST_ROUTE, RELAXED_BROWSER_SANDBOX, WEB_BROWSER_SANDBOX } from '../../../assets/browser-policy.mjs'
|
|
3
|
+
/** Iframe DOM and revision-tagged load observations. */
|
|
4
|
+
import type { BrowserTarget } from '../browser/url.ts'
|
|
5
|
+
import type { BrowserPresentation } from './BrowserPresentation.ts'
|
|
6
|
+
import css from './Browser.module.css'
|
|
7
|
+
import { GuestFrameHistory } from '../browser/frame-history.ts'
|
|
8
|
+
import { registerIframePage, registerIframeReference, type GuestReferenceCommand } from '../browser/iframe-reference.ts'
|
|
9
|
+
import { connectWebReferenceSource } from '../browser/web-reference-source.ts'
|
|
10
|
+
import { registerTakeoverSummary } from '../browser/takeover-channel.ts'
|
|
11
|
+
import type { TakeoverSummary } from '../../takeover-protocol.ts'
|
|
12
|
+
import { sameReferenceDocument } from '../../reference-page.ts'
|
|
13
|
+
import { dispatchChildTab } from '../browser/child-tabs.ts'
|
|
14
|
+
import { reportReferenceCaptureFailure } from '../reference-intents.ts'
|
|
15
|
+
import type { BrowserChildTabRequest } from '../../types.ts'
|
|
16
|
+
|
|
17
|
+
/** Route Web pages through the opaque-origin proxy. */
|
|
18
|
+
function guestProxyUrl(url: string, context: string): string {
|
|
19
|
+
if (!/^https?:\/\//iu.test(url)) return url
|
|
20
|
+
if (url.includes(GUEST_ROUTE)) return url
|
|
21
|
+
return `${location.origin}${GUEST_ROUTE}?u=${encodeURIComponent(url)}&runtime=3&storage-context=${encodeURIComponent(context)}`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function capturedSourceUrl(value: unknown): unknown {
|
|
25
|
+
if (typeof value !== 'string') return value
|
|
26
|
+
try {
|
|
27
|
+
const proxy = new URL(value)
|
|
28
|
+
if (proxy.origin === location.origin && proxy.pathname === GUEST_ROUTE) {
|
|
29
|
+
const source = proxy.searchParams.get('u')
|
|
30
|
+
if (source !== null && /^https?:\/\//iu.test(source)) return new URL(source).href
|
|
31
|
+
}
|
|
32
|
+
} catch { /* Invalid source URLs remain subject to capture validation. */ }
|
|
33
|
+
return value
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface IframeDocument {
|
|
37
|
+
readonly target: BrowserTarget
|
|
38
|
+
readonly revision: number
|
|
39
|
+
readonly sandboxed: boolean
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Reports only what an iframe can observe without inspecting cross-origin content. */
|
|
43
|
+
export interface IframePresentationEvents {
|
|
44
|
+
/** @param revision - document generation whose native load completed. */
|
|
45
|
+
readonly loaded: (revision: number) => void
|
|
46
|
+
/** @param revision - document generation. @param observedUrl - URL reported by the owned opaque guest. */
|
|
47
|
+
readonly observed: (revision: number, observedUrl: string) => void
|
|
48
|
+
readonly reference?: (intent: object) => Promise<void>
|
|
49
|
+
readonly childRequested?: (url: string) => void
|
|
50
|
+
readonly capabilityFailed?: (description: string) => void
|
|
51
|
+
readonly guestReady?: (revision: number, pageId: string) => void
|
|
52
|
+
readonly guestPending?: () => void
|
|
53
|
+
readonly guestFailed?: (revision: number, description: string) => void
|
|
54
|
+
readonly failed: (revision: number) => void
|
|
55
|
+
readonly remounted: () => void
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Owns the iframe element; navigation and history remain in IframeImpl. */
|
|
59
|
+
export class IframePresentation implements BrowserPresentation {
|
|
60
|
+
private readonly pageId = `iframe:${crypto.randomUUID()}`
|
|
61
|
+
private readonly unregisterReference: (() => void) | undefined
|
|
62
|
+
private readonly sourceLifetime = new AbortController()
|
|
63
|
+
private sourceConnection: Promise<void> | undefined
|
|
64
|
+
private observedUrl: string | undefined
|
|
65
|
+
private unregisterPage: (() => void) | undefined
|
|
66
|
+
private nextRequestId = 0
|
|
67
|
+
private readonly pending = new Map<number, { readonly loadId: number; readonly url: string; readonly resolve: (value: Record<string, unknown>) => void; readonly reject: (error: Error) => void }>()
|
|
68
|
+
private host: HTMLElement | undefined
|
|
69
|
+
private element: HTMLIFrameElement | undefined
|
|
70
|
+
private document: IframeDocument | undefined
|
|
71
|
+
private rendered = false
|
|
72
|
+
private readonly frameHistory = new GuestFrameHistory()
|
|
73
|
+
private loadId: number | undefined
|
|
74
|
+
private documentId: string | undefined
|
|
75
|
+
private loadedId: number | undefined
|
|
76
|
+
private nativeLoadId: number | undefined
|
|
77
|
+
private nextLoadId = 0
|
|
78
|
+
private childRequestId = 0
|
|
79
|
+
private identityTimer: ReturnType<typeof setTimeout> | undefined
|
|
80
|
+
private identityRetried = false
|
|
81
|
+
private readonly receive = (event: MessageEvent): void => {
|
|
82
|
+
// A sandboxed guest posts from the opaque origin `null`. A carrier that granted the guest its
|
|
83
|
+
// own origin (storage-compatible mode) posts from this application's origin instead. Both can
|
|
84
|
+
// only be this frame's own document; the source check is what proves it, and any other origin
|
|
85
|
+
// is a different frame and is dropped.
|
|
86
|
+
const ownOrigin = event.origin === 'null' || event.origin === location.origin
|
|
87
|
+
if (!ownOrigin || event.source !== this.element?.contentWindow) return
|
|
88
|
+
const data = event.data
|
|
89
|
+
if (data?.type === 'dsh.browser.guest.child.request') {
|
|
90
|
+
if (this.loadId === undefined || data.loadId !== this.loadId || !Number.isSafeInteger(data.requestId)
|
|
91
|
+
|| data.requestId <= this.childRequestId || typeof data.url !== 'string'
|
|
92
|
+
|| !['url-only', 'native-opener'].includes(data.mode)) return
|
|
93
|
+
this.childRequestId = data.requestId
|
|
94
|
+
const result = dispatchChildTab(data as BrowserChildTabRequest, location.origin, url => { this.events.childRequested?.(url) })
|
|
95
|
+
if (result.status === 'unsupported') this.events.capabilityFailed?.(result.code)
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
if (data?.type === 'dsh.browser.guest.reference.ack') {
|
|
99
|
+
const request = this.pending.get(data.requestId)
|
|
100
|
+
if (request === undefined) return
|
|
101
|
+
if (data.loadId !== request.loadId || data.loadId !== this.loadId || data.documentId !== this.documentId
|
|
102
|
+
|| typeof data.url !== 'string' || !sameReferenceDocument(data.url, request.url)) {
|
|
103
|
+
request.reject(new Error('GUEST_REFERENCE_IDENTITY_MISMATCH: source iframe acknowledgement belongs to another document'))
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
if (data.ok === false) request.reject(new Error(typeof data.reason === 'string' ? data.reason : 'guest reference failed'))
|
|
107
|
+
else if (data.ok === true && data.value !== null && typeof data.value === 'object' && !Array.isArray(data.value)) request.resolve(data.value)
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
if (data?.type === 'dsh-browser-ref:intent') {
|
|
111
|
+
void this.capture(data).catch(reportReferenceCaptureFailure)
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
if (!data || data.type !== 'dsh.browser.guest.navigation' || typeof data.url !== 'string'
|
|
115
|
+
|| !/^https?:\/\//iu.test(data.url) || this.document === undefined) return
|
|
116
|
+
if (this.loadId === undefined) return
|
|
117
|
+
if (typeof data.documentId !== 'string' || !data.documentId || data.documentId.length > 100) {
|
|
118
|
+
this.observedUrl = undefined
|
|
119
|
+
for (const request of [...this.pending.values()]) request.reject(new Error('GUEST_DOCUMENT_IDENTITY_UNAVAILABLE: source iframe identity is missing'))
|
|
120
|
+
this.events.guestPending?.()
|
|
121
|
+
this.awaitIdentity()
|
|
122
|
+
if (!this.identityRetried) { this.identityRetried = true; this.requestNavigation() }
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
if (data.loadId !== undefined && data.loadId !== this.loadId) {
|
|
126
|
+
this.awaitIdentity()
|
|
127
|
+
this.requestNavigation()
|
|
128
|
+
return
|
|
129
|
+
}
|
|
130
|
+
if (data.documentId !== this.documentId) {
|
|
131
|
+
const nativeLoaded = this.documentId === undefined && this.nativeLoadId === this.loadId
|
|
132
|
+
this.invalidateGuest()
|
|
133
|
+
this.frameHistory.noteDocumentChange()
|
|
134
|
+
this.loadId = ++this.nextLoadId
|
|
135
|
+
this.documentId = data.documentId
|
|
136
|
+
if (nativeLoaded) this.nativeLoadId = this.loadId
|
|
137
|
+
this.awaitIdentity()
|
|
138
|
+
this.requestNavigation()
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
if (data.loadId !== this.loadId) {
|
|
142
|
+
this.awaitIdentity()
|
|
143
|
+
this.requestNavigation()
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
clearTimeout(this.identityTimer)
|
|
147
|
+
this.identityTimer = undefined
|
|
148
|
+
this.identityRetried = false
|
|
149
|
+
this.frameHistory.record({
|
|
150
|
+
depth: Number.isSafeInteger(data.depth) && data.depth > 0 ? data.depth : 1,
|
|
151
|
+
reason: typeof data.reason === 'string' ? data.reason : undefined,
|
|
152
|
+
navigationType: typeof data.navigationType === 'string' ? data.navigationType : undefined,
|
|
153
|
+
})
|
|
154
|
+
if (data.ready === true) this.markLoaded()
|
|
155
|
+
this.observedUrl = data.url
|
|
156
|
+
this.events.observed(this.document.revision, data.url)
|
|
157
|
+
if (data.ready === true && this.owner !== undefined && this.host !== undefined) {
|
|
158
|
+
this.unregisterPage?.()
|
|
159
|
+
this.unregisterPage = registerIframePage(this.owner, this.host.id, this.pageId, data.url, this.document.target.url)
|
|
160
|
+
}
|
|
161
|
+
if (data.ready === true) this.events.guestReady?.(this.document.revision, this.pageId)
|
|
162
|
+
}
|
|
163
|
+
private readonly events: IframePresentationEvents
|
|
164
|
+
private readonly owner?: string
|
|
165
|
+
constructor(events: IframePresentationEvents, owner?: string) {
|
|
166
|
+
this.events = events
|
|
167
|
+
this.owner = owner
|
|
168
|
+
if (owner !== undefined) this.sourceLifetime.signal.addEventListener('abort', registerTakeoverSummary(this.pageId, owner, async signal => {
|
|
169
|
+
const result = await this.command('summary', { maxChars: 1500, legacy: false }, signal, this.observedUrl ?? '', this.loadId)
|
|
170
|
+
return result as unknown as TakeoverSummary
|
|
171
|
+
}), { once: true })
|
|
172
|
+
if (owner !== undefined) this.unregisterReference = registerIframeReference(this.pageId, owner, url => {
|
|
173
|
+
const loadId = this.loadId
|
|
174
|
+
return (operation, spec, signal) => this.command(operation, spec, signal, url, loadId)
|
|
175
|
+
})
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private command(operation: Parameters<GuestReferenceCommand>[0], spec: object, signal: AbortSignal,
|
|
179
|
+
url: string, loadId: number | undefined): Promise<Record<string, unknown>> {
|
|
180
|
+
signal.throwIfAborted()
|
|
181
|
+
if (loadId === undefined || loadId !== this.loadId || this.documentId === undefined || this.observedUrl === undefined
|
|
182
|
+
|| !sameReferenceDocument(url, this.observedUrl) || this.element?.contentWindow == null) {
|
|
183
|
+
return Promise.reject(new Error('source iframe document is not ready'))
|
|
184
|
+
}
|
|
185
|
+
const win = this.element.contentWindow
|
|
186
|
+
const requestId = ++this.nextRequestId
|
|
187
|
+
return new Promise((resolve, reject) => {
|
|
188
|
+
const timer = setTimeout(() => { finish(undefined, new Error('GUEST_REFERENCE_TIMEOUT: source iframe did not acknowledge the reveal')) }, 5000)
|
|
189
|
+
const finish = (value?: Record<string, unknown>, error?: Error): void => {
|
|
190
|
+
clearTimeout(timer)
|
|
191
|
+
this.pending.delete(requestId)
|
|
192
|
+
signal.removeEventListener('abort', abort)
|
|
193
|
+
if (error !== undefined) reject(error)
|
|
194
|
+
else resolve(value!)
|
|
195
|
+
}
|
|
196
|
+
const abort = (): void => { finish(undefined, new Error('source reveal cancelled')) }
|
|
197
|
+
this.pending.set(requestId, { loadId, url, resolve: value => { finish(value) }, reject: error => { finish(undefined, error) } })
|
|
198
|
+
signal.addEventListener('abort', abort, { once: true })
|
|
199
|
+
try { win.postMessage({ type: 'dsh.browser.guest.reference.request', operation, spec, url, loadId, documentId: this.documentId, requestId }, '*') }
|
|
200
|
+
catch (error) { finish(undefined, error instanceof Error ? error : new Error(String(error))) }
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private invalidateGuest(): void {
|
|
205
|
+
this.unregisterPage?.()
|
|
206
|
+
this.unregisterPage = undefined
|
|
207
|
+
clearTimeout(this.identityTimer)
|
|
208
|
+
this.identityTimer = undefined
|
|
209
|
+
this.identityRetried = false
|
|
210
|
+
this.childRequestId = 0
|
|
211
|
+
this.loadId = undefined
|
|
212
|
+
this.documentId = undefined
|
|
213
|
+
this.loadedId = undefined
|
|
214
|
+
this.nativeLoadId = undefined
|
|
215
|
+
this.observedUrl = undefined
|
|
216
|
+
for (const request of this.pending.values()) request.reject(new Error('source iframe document changed'))
|
|
217
|
+
this.events.guestPending?.()
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private async capture(data: object): Promise<void> {
|
|
221
|
+
if (this.owner !== undefined) {
|
|
222
|
+
this.sourceConnection ??= connectWebReferenceSource(this.owner, this.pageId, () => this.observedUrl ?? this.document?.target.url ?? '', this.sourceLifetime.signal)
|
|
223
|
+
try { await this.sourceConnection }
|
|
224
|
+
catch (error) { this.sourceConnection = undefined; throw error }
|
|
225
|
+
if (this.sourceLifetime.signal.aborted) throw new Error('source iframe was disposed')
|
|
226
|
+
}
|
|
227
|
+
const frozen = (data as { readonly capture?: Record<string, unknown> }).capture
|
|
228
|
+
const intent = frozen !== null && typeof frozen === 'object' && !Array.isArray(frozen)
|
|
229
|
+
? { ...data, capture: { ...frozen, url: capturedSourceUrl(frozen.url),
|
|
230
|
+
...typeof frozen.frameUrl === 'string' ? { frameUrl: capturedSourceUrl(frozen.frameUrl) } : {} } }
|
|
231
|
+
: data
|
|
232
|
+
await this.events.reference?.({ ...intent, ...this.owner === undefined ? {} : { sourcePageId: this.pageId } })
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Request history movement in the guest without reading its cross-origin window. */
|
|
236
|
+
historyStep(delta: number): boolean {
|
|
237
|
+
if (!this.frameHistory.canStep(delta)) return false
|
|
238
|
+
const win = this.element?.contentWindow
|
|
239
|
+
if (win === undefined || win === null) return false
|
|
240
|
+
try {
|
|
241
|
+
win.postMessage({ type: 'dsh.browser.guest.history', delta: delta < 0 ? -1 : 1 }, '*')
|
|
242
|
+
} catch {
|
|
243
|
+
return false
|
|
244
|
+
}
|
|
245
|
+
return this.frameHistory.step(delta)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Entries this guest iframe itself added, counting the current one; the joint session history is excluded. */
|
|
249
|
+
historyDepth(): number {
|
|
250
|
+
return this.frameHistory.depth()
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** Whether the guest iframe has a forward entry of its own. */
|
|
254
|
+
canGoForward(): boolean {
|
|
255
|
+
return this.frameHistory.canGoForward()
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** @param viewportId - mounted placeholder. @returns removes only the iframe presentation. */
|
|
259
|
+
mount(viewportId: string): () => void {
|
|
260
|
+
const host = document.getElementById(viewportId)
|
|
261
|
+
if (host === null) throw new Error('iframe presentation: viewport is not mounted')
|
|
262
|
+
this.element?.remove()
|
|
263
|
+
this.invalidateGuest()
|
|
264
|
+
this.element = undefined
|
|
265
|
+
this.host = host
|
|
266
|
+
window.addEventListener('message', this.receive)
|
|
267
|
+
if (this.rendered) this.events.remounted()
|
|
268
|
+
else this.render()
|
|
269
|
+
return () => {
|
|
270
|
+
if (this.host !== host) return
|
|
271
|
+
window.removeEventListener('message', this.receive)
|
|
272
|
+
this.invalidateGuest()
|
|
273
|
+
this.element?.remove()
|
|
274
|
+
this.element = undefined
|
|
275
|
+
this.host = undefined
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Retain the prepared document and render it when a container is mounted.
|
|
281
|
+
* @param value - prepared document and event generation.
|
|
282
|
+
*/
|
|
283
|
+
show(value: IframeDocument): void {
|
|
284
|
+
this.document = value
|
|
285
|
+
this.render()
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Remove the owned DOM and retained presentation data. */
|
|
289
|
+
dispose(): void {
|
|
290
|
+
this.sourceLifetime.abort()
|
|
291
|
+
window.removeEventListener('message', this.receive)
|
|
292
|
+
this.invalidateGuest()
|
|
293
|
+
this.unregisterReference?.()
|
|
294
|
+
this.element?.remove()
|
|
295
|
+
this.element = undefined
|
|
296
|
+
this.host = undefined
|
|
297
|
+
this.document = undefined
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
private requestNavigation(): void {
|
|
301
|
+
try {
|
|
302
|
+
this.element?.contentWindow?.postMessage({ type: 'dsh.browser.guest.navigation.request', loadId: this.loadId, documentId: this.documentId }, '*')
|
|
303
|
+
} catch {
|
|
304
|
+
// Native load completion does not depend on a scriptable guest.
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
private awaitIdentity(): void {
|
|
309
|
+
if (this.identityTimer !== undefined) return
|
|
310
|
+
const revision = this.document?.revision
|
|
311
|
+
this.identityTimer = setTimeout(() => {
|
|
312
|
+
this.identityTimer = undefined
|
|
313
|
+
if (revision === undefined || this.document?.revision !== revision) return
|
|
314
|
+
// Nothing answers this handshake today: the guest overlay listens for `dsh-browser-ref:intent`
|
|
315
|
+
// and never posts a `dsh.browser.guest.navigation` identity, and a directly loaded document
|
|
316
|
+
// carries no overlay at all. Failing the document here painted a five-second "load failed"
|
|
317
|
+
// banner over a page that had already loaded, and `guestFailed` also marked the whole carrier
|
|
318
|
+
// unusable. Report the document as loaded instead; the reference channel stays unavailable,
|
|
319
|
+
// which is what the states actually are.
|
|
320
|
+
this.markLoaded()
|
|
321
|
+
}, 5000)
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
private markLoaded(): void {
|
|
325
|
+
if (this.document === undefined || this.loadedId === this.loadId) return
|
|
326
|
+
this.loadedId = this.loadId
|
|
327
|
+
this.events.loaded(this.document.revision)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private render(): void {
|
|
331
|
+
const current = this.document
|
|
332
|
+
const host = this.host
|
|
333
|
+
if (current === undefined || host === undefined) return
|
|
334
|
+
this.invalidateGuest()
|
|
335
|
+
this.element?.remove()
|
|
336
|
+
const element = document.createElement('iframe')
|
|
337
|
+
element.className = css.frame as string
|
|
338
|
+
element.src = guestProxyUrl(current.target.url, this.pageId)
|
|
339
|
+
element.title = current.target.title
|
|
340
|
+
element.referrerPolicy = 'no-referrer'
|
|
341
|
+
element.dataset.sidebarBrowserFrame = 'iframe'
|
|
342
|
+
element.setAttribute('sandbox', current.sandboxed ? WEB_BROWSER_SANDBOX : RELAXED_BROWSER_SANDBOX)
|
|
343
|
+
element.addEventListener('load', () => {
|
|
344
|
+
if (this.element !== element) return
|
|
345
|
+
if (this.nativeLoadId === this.loadId) {
|
|
346
|
+
this.invalidateGuest()
|
|
347
|
+
this.loadId = ++this.nextLoadId
|
|
348
|
+
}
|
|
349
|
+
this.observedUrl = undefined
|
|
350
|
+
this.events.guestPending?.()
|
|
351
|
+
this.markLoaded()
|
|
352
|
+
this.nativeLoadId = this.loadId
|
|
353
|
+
this.awaitIdentity()
|
|
354
|
+
this.requestNavigation()
|
|
355
|
+
})
|
|
356
|
+
element.addEventListener('error', () => {
|
|
357
|
+
if (this.element === element) { this.invalidateGuest(); this.events.failed(current.revision) }
|
|
358
|
+
})
|
|
359
|
+
this.frameHistory.reset(history.length)
|
|
360
|
+
this.loadId = ++this.nextLoadId
|
|
361
|
+
this.element = element
|
|
362
|
+
this.rendered = true
|
|
363
|
+
host.append(element)
|
|
364
|
+
}
|
|
365
|
+
}
|