dsh-builtin-browser 0.5.8 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +410 -1
- package/README.en.md +16 -64
- package/README.md +33 -64
- package/assets/browser-carriers.svg +20 -0
- package/assets/browser-extension-identity.d.mts +2 -0
- package/assets/browser-extension-identity.mjs +2 -0
- package/assets/browser-messages.d.mts +5 -0
- package/assets/browser-messages.mjs +64 -0
- package/assets/browser-panel-locales.d.mts +2 -0
- package/assets/browser-panel-locales.mjs +380 -0
- package/assets/browser-policy.d.mts +37 -0
- package/assets/browser-policy.mjs +37 -0
- package/assets/browser-products.d.mts +6 -0
- package/assets/browser-products.mjs +76 -0
- package/assets/screenshots/1-main.png +0 -0
- package/assets/screenshots/2-form-fill.png +0 -0
- package/assets/screenshots/3-challenge.png +0 -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/cordis.patch.yml +23 -48
- package/desktop-bridge/desktop-discovery.d.mts +2 -0
- package/desktop-bridge/desktop-discovery.mjs +36 -0
- package/desktop-bridge/desktop-identity.json +17 -1
- package/desktop-bridge/desktop-processes.d.mts +1 -0
- package/desktop-bridge/desktop-processes.mjs +15 -0
- package/desktop-bridge/guest-proxy.mjs +109 -0
- package/desktop-bridge/install.mjs +197 -74
- package/desktop-bridge/main.mjs +11 -0
- package/desktop-bridge/maintenance-files.d.mts +8 -0
- package/desktop-bridge/maintenance-files.mjs +28 -0
- package/desktop-bridge/maintenance-progress.ps1 +2 -2
- package/desktop-bridge/native-guests.mjs +41 -0
- package/desktop-bridge/plugin-browser-bridge.js +618 -370
- package/desktop-bridge/profile-loader.mjs +26 -0
- package/dist/client.cjs +43167 -0
- package/dist/client.d.cts +516 -0
- package/dist/client.d.mts +516 -0
- package/dist/index.cjs +92 -0
- package/dist/index.d.mts +2960 -0
- package/dist/index.mjs +24 -0
- package/docs/HANDOVER-2026-11-15.md +178 -0
- package/docs/README.md +10 -19
- package/docs/architecture.md +17 -145
- package/docs/child-tabs.md +13 -0
- package/docs/desktop-acceptance.md +9 -0
- package/docs/development.md +88 -18
- package/docs/extension-browser.md +44 -0
- package/docs/hardcoding-audit.md +64 -0
- package/docs/limitations.md +23 -73
- package/docs/pr64-extension-status.md +46 -0
- package/docs/pr64-maintenance.md +25 -0
- package/docs/pr64-native-children.md +52 -0
- package/docs/pr64-native-views.md +60 -0
- package/docs/tool-reference.md +87 -11
- package/docs/user-guide.md +47 -255
- package/docs/why-browser.md +6 -39
- package/dsh-host-patch/README.md +60 -0
- package/dsh-host-patch/apply.mjs +194 -0
- package/dsh-host-patch/legacy-bridge.mjs +53 -0
- package/dsh-host-patch/rc3-revision1.json +90 -0
- package/dsh-host-patch/rc3-revision2.json +112 -0
- package/dsh-host-patch/rc3-revision3.json.gz +0 -0
- package/dsh-host-patch/rc3-revision4.json.gz +0 -0
- package/dsh-host-patch/rc3-revision5.json.gz +0 -0
- package/dsh-host-patch/rc3-revision6.json.gz +0 -0
- package/dsh-host-patch/rc3-revision7.json.gz +0 -0
- package/dsh-host-patch/rc3-revision8.json.gz +0 -0
- package/dsh-host-patch/rc3.json +148 -0
- package/dsh-host-patch/rc5-revision1.json +90 -0
- package/dsh-host-patch/rc5-revision2.json +112 -0
- package/dsh-host-patch/rc5-revision3.json.gz +0 -0
- package/dsh-host-patch/rc5-revision4.json.gz +0 -0
- package/dsh-host-patch/rc5-revision5.json.gz +0 -0
- package/dsh-host-patch/rc5-revision6.json.gz +0 -0
- package/dsh-host-patch/rc5-revision7.json.gz +0 -0
- package/dsh-host-patch/rc5-revision8.json.gz +0 -0
- package/dsh-host-patch/rc5.json +148 -0
- package/lib/bridge-compatibility.js +38 -0
- package/lib/browser/handles.js +78 -0
- package/lib/browser/runtime.js +155 -43
- package/lib/browser/takeover-target.js +24 -0
- package/lib/browser-electron/authenticated-route.js +23 -0
- package/lib/browser-electron/automatic-maintenance.js +394 -51
- package/lib/browser-electron/bridge-auto.js +2 -1
- package/lib/browser-electron/bridge-connection.js +8 -1
- package/lib/browser-electron/bridge-install.js +27 -2
- package/lib/browser-electron/bridge-maintenance.js +35 -10
- package/lib/browser-electron/bridge-status.js +98 -27
- package/lib/browser-electron/desktop-bridge-host.js +193 -560
- package/lib/browser-electron/desktop-identity.js +40 -2
- package/lib/browser-electron/document-readiness.js +34 -0
- package/lib/browser-electron/electron-provision.js +14 -44
- package/lib/browser-electron/entry.js +659 -252
- package/lib/browser-electron/extension-browser.js +234 -0
- package/lib/browser-electron/extension-setup.js +69 -0
- package/lib/browser-electron/guest-cookie-jar.LICENSE.txt +32 -0
- package/lib/browser-electron/guest-cookie-jar.js +10559 -0
- package/lib/browser-electron/guest-cookie-store.js +74 -0
- package/lib/browser-electron/guest-css-runtime.js +75 -0
- package/lib/browser-electron/guest-css.js +106 -0
- package/lib/browser-electron/guest-route.js +603 -0
- package/lib/browser-electron/guest-runtime.js +356 -0
- package/lib/browser-electron/guest-storage-runtime.js +52 -0
- package/lib/browser-electron/guest-storage.js +163 -0
- package/lib/browser-electron/history-store.js +2 -1
- package/lib/browser-electron/host-main.js +162 -7
- package/lib/browser-electron/host-patch-maintenance.js +141 -0
- package/lib/browser-electron/http-body.js +22 -0
- package/lib/browser-electron/maintenance-broker.js +35 -5
- package/lib/browser-electron/maintenance-lifecycle.js +7 -5
- package/lib/browser-electron/maintenance-route.js +9 -6
- package/lib/browser-electron/open-slot.js +47 -0
- package/lib/browser-electron/paths.js +4 -1
- package/lib/browser-electron/preferred-browser.js +144 -0
- package/lib/browser-electron/preview-route.js +11 -8
- package/lib/browser-electron/process-ownership.js +198 -0
- package/lib/browser-electron/profile-checkpoint.js +222 -0
- package/lib/browser-electron/profile-command.js +60 -0
- package/lib/browser-electron/profile-extension.js +126 -0
- package/lib/browser-electron/profile-lease.js +157 -0
- package/lib/browser-electron/profile-residue.js +61 -0
- package/lib/browser-electron/provider.js +719 -262
- package/lib/browser-electron/reference-route.js +635 -0
- package/lib/browser-electron/remote-host.js +12 -13
- package/lib/browser-electron/runtime-route.js +6 -5
- package/lib/browser-electron/runtime-status.js +30 -29
- package/lib/browser-electron/settings-store.js +10 -5
- package/lib/browser-electron/shortcuts-route.js +108 -0
- package/lib/browser-electron/sidebar-only-host.js +119 -18
- package/lib/browser-electron/startpage-shortcuts.js +172 -0
- package/lib/browser-electron/system-browser.js +352 -371
- package/lib/browser-electron/windows-system.js +2 -1
- package/lib/browser-reference/delivery.js +326 -0
- package/lib/browser-reference/entry.js +597 -0
- package/lib/browser-reference/export.js +298 -0
- package/lib/browser-reference/import.js +295 -0
- package/lib/browser-reference/page-script.js +1406 -0
- package/lib/browser-reference/service.js +1062 -0
- package/lib/browser-reference/store.js +177 -0
- package/lib/browser-reference/submission-receipts.js +139 -0
- package/lib/browser-reference/text-quote.js +167 -0
- package/lib/browser-reference/types.js +11 -0
- package/lib/browser-reference/visible.js +311 -0
- package/lib/browser-reference/web-sources.js +97 -0
- package/lib/index.js +10 -3
- package/lib/reference-owner.js +5 -0
- package/lib/reference-page.js +12 -0
- package/lib/reference-source.js +2 -0
- package/lib/reference-text.js +188 -0
- package/lib/startpage-settings.js +63 -0
- package/lib/startpage.js +44 -0
- package/lib/takeover-protocol.js +2 -0
- package/lib/tool-browser/code-tool.js +416 -0
- package/lib/tool-browser/code-worker.js +872 -0
- package/lib/tool-browser/index.js +940 -76
- package/lib/tool-browser/page-probe.js +3 -3
- package/lib/tool-browser/panel-page.js +95 -0
- package/lib/tool-browser/screenshot-image.js +51 -0
- package/lib/tool-browser/takeover.js +205 -0
- package/lib/types.js +1 -0
- package/lib/web-guest.js +26 -0
- package/native-host/client.d.mts +17 -0
- package/native-host/client.mjs +100 -0
- package/native-host/host.mjs +150 -0
- package/native-host/identity.d.mts +2 -0
- package/native-host/identity.mjs +1 -0
- package/native-host/install.mjs +168 -0
- package/native-host/protocol.mjs +75 -0
- package/package.json +80 -92
- package/scripts/build.mjs +66 -0
- package/scripts/bundle-host.mjs +28 -0
- package/scripts/fix-exports.mjs +50 -0
- package/scripts/install-electron.mjs +11 -26
- package/scripts/verify-exports.mjs +47 -0
- package/scripts/verify-preview-sdk.mjs +93 -0
- package/skills/dsh-builtin-browser/SKILL.md +56 -47
- package/skills/dsh-builtin-browser/references/batch.md +31 -1
- 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/handles.ts +89 -0
- package/src/browser/runtime.ts +146 -50
- package/src/browser/takeover-target.ts +36 -0
- package/src/browser/types.ts +19 -7
- package/src/browser-electron/authenticated-route.ts +29 -1
- package/src/browser-electron/automatic-maintenance.ts +368 -56
- package/src/browser-electron/bridge-auto.ts +5 -4
- package/src/browser-electron/bridge-connection.ts +20 -2
- package/src/browser-electron/bridge-endpoint.ts +3 -3
- package/src/browser-electron/bridge-install.ts +40 -4
- package/src/browser-electron/bridge-maintenance.ts +42 -14
- package/src/browser-electron/bridge-status.ts +94 -23
- package/src/browser-electron/desktop-bridge-host.ts +185 -585
- package/src/browser-electron/desktop-identity.ts +53 -2
- package/src/browser-electron/document-readiness.ts +45 -0
- package/src/browser-electron/electron-provision.ts +12 -45
- package/src/browser-electron/entry.ts +1299 -882
- package/src/browser-electron/ephemeral-profile.ts +1 -1
- package/src/browser-electron/extension-browser.ts +223 -0
- package/src/browser-electron/extension-setup.ts +67 -0
- package/src/browser-electron/guest-cookie-jar.ts +176 -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 +568 -0
- package/src/browser-electron/guest-runtime.ts +357 -0
- package/src/browser-electron/guest-storage-runtime.ts +54 -0
- package/src/browser-electron/guest-storage.ts +117 -0
- package/src/browser-electron/history-store.ts +5 -4
- package/src/browser-electron/host-main.ts +156 -11
- package/src/browser-electron/host-patch-maintenance.ts +112 -0
- package/src/browser-electron/http-body.ts +23 -0
- package/src/browser-electron/maintenance-broker.ts +29 -5
- package/src/browser-electron/maintenance-lifecycle.ts +14 -9
- package/src/browser-electron/maintenance-route.ts +17 -14
- package/src/browser-electron/missing-system-browser.ts +2 -2
- package/src/browser-electron/open-slot.ts +49 -0
- package/src/browser-electron/paths.ts +5 -1
- package/src/browser-electron/preferred-browser.ts +120 -0
- package/src/browser-electron/preview-route.ts +18 -11
- package/src/browser-electron/process-ownership.ts +168 -0
- package/src/browser-electron/profile-checkpoint.ts +187 -0
- package/src/browser-electron/profile-command.ts +46 -0
- package/src/browser-electron/profile-extension.ts +124 -0
- package/src/browser-electron/profile-lease.ts +115 -0
- package/src/browser-electron/profile-residue.ts +49 -0
- package/src/browser-electron/provider.ts +771 -289
- package/src/browser-electron/reference-route.ts +608 -0
- package/src/browser-electron/remote-host.ts +15 -15
- package/src/browser-electron/runtime-route.ts +11 -10
- package/src/browser-electron/runtime-status.ts +51 -32
- package/src/browser-electron/settings-store.ts +27 -7
- package/src/browser-electron/shortcuts-route.ts +112 -0
- package/src/browser-electron/sidebar-only-host.ts +118 -19
- package/src/browser-electron/startpage-shortcuts.ts +213 -0
- package/src/browser-electron/system-browser.ts +309 -338
- package/src/browser-electron/windows-system.ts +2 -1
- 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 +1315 -0
- package/src/browser-reference/store.ts +172 -0
- package/src/browser-reference/submission-receipts.ts +122 -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 +103 -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 +176 -0
- package/src/client/browser/child-tabs.ts +14 -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 +52 -0
- package/src/client/css-modules.d.ts +4 -0
- package/src/client/definition.tsx +30 -0
- package/src/client/electron/ElectronWebViewImpl.ts +364 -0
- package/src/client/electron/ElectronWebviewPresentation.ts +138 -0
- package/src/client/electron/NativeChildPresentation.ts +45 -0
- package/src/client/electron/NativeViewPage.ts +251 -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 +293 -0
- package/src/client/locales.ts +857 -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 +189 -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 +471 -0
- package/src/client/reference/client/production/asset-store.ts +144 -0
- package/src/client/reference/client/production/availability.ts +74 -0
- package/src/client/reference/client/production/bytes.ts +36 -0
- package/src/client/reference/client/production/delivery-client.ts +211 -0
- package/src/client/reference/client/production/draft-adapter.ts +508 -0
- package/src/client/reference/client/production/http-transport.ts +217 -0
- package/src/client/reference/client/production/production-submission.ts +310 -0
- package/src/client/reference/client/production/protocol.ts +231 -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 +1101 -0
- package/src/client/reference/client/production/snapshot-adapter.ts +154 -0
- package/src/client/reference/client/production/source-marker.ts +63 -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 +58 -0
- package/src/client/reference/client/reveal.ts +107 -0
- package/src/client/reference/client/scheme.ts +114 -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 +34 -0
- package/{client.js → src/client/settings/panel.ts} +2657 -2231
- package/src/client/shortcut-open.ts +30 -0
- package/src/client/startpage/binding.ts +99 -0
- package/src/client/startpage/controller.ts +303 -0
- package/src/client/startpage/model.ts +279 -0
- package/src/client/view/Browser.module.css +751 -0
- package/src/client/view/BrowserBody.tsx +314 -0
- package/src/client/view/BrowserPresentation.ts +9 -0
- package/src/client/view/BrowserTitle.tsx +17 -0
- package/src/client/view/IframePresentation.ts +344 -0
- package/src/client/view/StartPage.tsx +597 -0
- package/src/client/view/TakeoverBanner.tsx +21 -0
- package/src/index.ts +110 -73
- 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 +197 -0
- package/src/startpage-settings.ts +103 -0
- package/src/startpage.ts +71 -0
- package/src/takeover-protocol.ts +19 -0
- package/src/tool-browser/code-tool.ts +401 -0
- package/src/tool-browser/code-worker.ts +639 -0
- package/src/tool-browser/index.ts +908 -77
- package/src/tool-browser/page-probe.ts +4 -4
- package/src/tool-browser/panel-page.ts +124 -0
- package/src/tool-browser/screenshot-image.ts +49 -0
- package/src/tool-browser/takeover.ts +198 -0
- package/src/types/electron-shim.d.ts +20 -0
- package/src/types.ts +85 -0
- package/src/web-guest.ts +34 -0
- package/tools/accept-desktop.mjs +148 -0
- package/lib/browser/runtime.d.ts +0 -175
- package/lib/browser/types.d.ts +0 -797
- package/lib/browser-electron/authenticated-route.d.ts +0 -27
- package/lib/browser-electron/automatic-maintenance.d.ts +0 -41
- package/lib/browser-electron/bridge-auto.d.ts +0 -93
- package/lib/browser-electron/bridge-connection.d.ts +0 -93
- package/lib/browser-electron/bridge-endpoint.d.ts +0 -30
- package/lib/browser-electron/bridge-install.d.ts +0 -85
- package/lib/browser-electron/bridge-maintenance.d.ts +0 -24
- package/lib/browser-electron/bridge-status.d.ts +0 -50
- package/lib/browser-electron/desktop-bridge-host.d.ts +0 -248
- package/lib/browser-electron/desktop-identity.d.ts +0 -58
- package/lib/browser-electron/electron-provision.d.ts +0 -92
- package/lib/browser-electron/entry.d.ts +0 -64
- package/lib/browser-electron/ephemeral-profile.d.ts +0 -37
- package/lib/browser-electron/file-write.d.ts +0 -2
- package/lib/browser-electron/history-store.d.ts +0 -98
- package/lib/browser-electron/host-main.d.ts +0 -26
- package/lib/browser-electron/http-body.d.ts +0 -24
- package/lib/browser-electron/json-reply.d.ts +0 -33
- package/lib/browser-electron/maintenance-broker.d.ts +0 -35
- package/lib/browser-electron/maintenance-lifecycle.d.ts +0 -32
- package/lib/browser-electron/maintenance-route.d.ts +0 -18
- package/lib/browser-electron/missing-system-browser.d.ts +0 -54
- package/lib/browser-electron/paths.d.ts +0 -4
- package/lib/browser-electron/preview-route.d.ts +0 -89
- package/lib/browser-electron/process.d.ts +0 -14
- package/lib/browser-electron/provider.d.ts +0 -959
- package/lib/browser-electron/remote-host.d.ts +0 -256
- package/lib/browser-electron/rpc-input.d.ts +0 -4
- package/lib/browser-electron/rpc-ops.d.ts +0 -18
- package/lib/browser-electron/runtime-diagnostics.d.ts +0 -12
- package/lib/browser-electron/runtime-route.d.ts +0 -55
- package/lib/browser-electron/runtime-status.d.ts +0 -116
- package/lib/browser-electron/settings-route.d.ts +0 -15
- package/lib/browser-electron/settings-store.d.ts +0 -224
- package/lib/browser-electron/sidebar-only-host.d.ts +0 -36
- package/lib/browser-electron/system-browser.d.ts +0 -367
- package/lib/browser-electron/timing.d.ts +0 -8
- package/lib/browser-electron/virtual-cursor.d.ts +0 -67
- package/lib/browser-electron/windows-system.d.ts +0 -3
- package/lib/index.d.ts +0 -30
- package/lib/tool-browser/element-fields.d.ts +0 -145
- package/lib/tool-browser/index.d.ts +0 -53
- package/lib/tool-browser/page-probe.d.ts +0 -86
- package/scripts/consumer-install-check.mjs +0 -72
- package/scripts/run-tests.mjs +0 -32
- package/scripts/verify-host-compat.mjs +0 -195
- package/scripts/verify-preview-route.mjs +0 -168
- package/scripts/verify-runtime-status.mjs +0 -179
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { guestReferenceHandlerScript } from '../browser-reference/page-script.js';
|
|
2
|
+
import { guestStorageScript } from './guest-storage-runtime.js';
|
|
3
|
+
import { guestCssRuntimeScript } from './guest-css-runtime.js';
|
|
4
|
+
/** Early, self-contained interception for documents served from the guest proxy. */
|
|
5
|
+
export function guestRuntimeScript(pageUrl, storage) {
|
|
6
|
+
return `(() => {
|
|
7
|
+
if (window.__dshGuestRuntime) return;
|
|
8
|
+
window.__dshGuestRuntime = true;
|
|
9
|
+
let real = ${JSON.stringify(pageUrl).replace(/</gu, '\\u003c')};
|
|
10
|
+
const route = '/dsh-builtin-browser/browser-view/isolated-guest';
|
|
11
|
+
const attempt = fn => { try { return fn(); } catch {} };
|
|
12
|
+
attempt(() => {
|
|
13
|
+
const cache = { match: async () => undefined, matchAll: async () => [], keys: async () => [],
|
|
14
|
+
add: async () => {}, addAll: async () => {}, put: async () => {}, delete: async () => false };
|
|
15
|
+
const caches = { open: async () => cache, match: async () => undefined, has: async () => false,
|
|
16
|
+
delete: async () => false, keys: async () => [] };
|
|
17
|
+
Object.defineProperty(window, 'caches', { configurable: true, enumerable: true, get: () => caches });
|
|
18
|
+
});
|
|
19
|
+
${storage === undefined ? '' : 'attempt(() => { ' + guestStorageScript(storage) + ' });'}
|
|
20
|
+
const storageContext = ${JSON.stringify(storage?.context ?? '')};
|
|
21
|
+
const contextual = value => {
|
|
22
|
+
if (!storageContext) return value;
|
|
23
|
+
const url = new URL(value, location.href);
|
|
24
|
+
url.searchParams.set('storage-context', storageContext);
|
|
25
|
+
return value.startsWith('/') ? url.pathname + url.search + url.hash : url.href;
|
|
26
|
+
};
|
|
27
|
+
const realURL = value => {
|
|
28
|
+
const raw = String(value);
|
|
29
|
+
const proxyURL = new URL(raw, location.origin + '/');
|
|
30
|
+
if (proxyURL.origin === location.origin && proxyURL.pathname === route) {
|
|
31
|
+
const inner = proxyURL.searchParams.get('u');
|
|
32
|
+
if (inner) return new URL(inner);
|
|
33
|
+
}
|
|
34
|
+
let url = new URL(raw, real);
|
|
35
|
+
if (url.origin === location.origin) {
|
|
36
|
+
url = new URL(url.pathname + url.search + url.hash, new URL(real).origin);
|
|
37
|
+
}
|
|
38
|
+
return url;
|
|
39
|
+
};
|
|
40
|
+
const toProxy = value => {
|
|
41
|
+
try {
|
|
42
|
+
const raw = String(value);
|
|
43
|
+
const hostURL = new URL(raw, location.origin + '/');
|
|
44
|
+
if (hostURL.origin === location.origin && hostURL.pathname === route) return contextual(raw);
|
|
45
|
+
const url = realURL(raw);
|
|
46
|
+
return /^https?:$/.test(url.protocol) ? contextual(route + '?u=' + encodeURIComponent(url.href)) : raw;
|
|
47
|
+
} catch { return value; }
|
|
48
|
+
};
|
|
49
|
+
window.__dshGuestToProxy = toProxy;
|
|
50
|
+
const nativeFetch = window.fetch && window.fetch.bind(window);
|
|
51
|
+
window.__dshGuestFetch = nativeFetch;
|
|
52
|
+
attempt(() => {
|
|
53
|
+
window.fetch = (input, init) => {
|
|
54
|
+
try {
|
|
55
|
+
const isRequest = input instanceof Request;
|
|
56
|
+
const url = toProxy(isRequest ? input.url : input);
|
|
57
|
+
if (!/^https?:$/.test(new URL(url, location.href).protocol)) return nativeFetch(input, init);
|
|
58
|
+
const headers = new Headers(init && init.headers || (isRequest ? input.headers : undefined));
|
|
59
|
+
headers.set('x-dsh-guest-headers', [...headers.keys()].filter(name => !name.startsWith('x-dsh-')).join(','));
|
|
60
|
+
headers.set('x-dsh-guest-sub', '1');
|
|
61
|
+
const options = Object.assign({}, init, { headers, mode: 'cors', credentials: 'omit' });
|
|
62
|
+
return nativeFetch(isRequest ? new Request(new URL(url, location.href), input) : url, options);
|
|
63
|
+
} catch (error) { return Promise.reject(error); }
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
attempt(() => {
|
|
67
|
+
const open = XMLHttpRequest.prototype.open;
|
|
68
|
+
const send = XMLHttpRequest.prototype.send;
|
|
69
|
+
const header = XMLHttpRequest.prototype.setRequestHeader;
|
|
70
|
+
const names = new WeakMap();
|
|
71
|
+
XMLHttpRequest.prototype.open = function(method, url, ...args) {
|
|
72
|
+
const result = open.call(this, method, toProxy(url), ...args);
|
|
73
|
+
names.set(this, new Set());
|
|
74
|
+
attempt(() => this.setRequestHeader('x-dsh-guest-sub', '1'));
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
XMLHttpRequest.prototype.setRequestHeader = function(name, value) {
|
|
78
|
+
const result = header.call(this, name, value);
|
|
79
|
+
const key = String(name).toLowerCase();
|
|
80
|
+
if (!key.startsWith('x-dsh-')) names.get(this)?.add(key);
|
|
81
|
+
return result;
|
|
82
|
+
};
|
|
83
|
+
XMLHttpRequest.prototype.send = function(...args) {
|
|
84
|
+
this.withCredentials = false;
|
|
85
|
+
header.call(this, 'x-dsh-guest-headers', [...(names.get(this) || [])].join(','));
|
|
86
|
+
return send.apply(this, args);
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
attempt(() => {
|
|
90
|
+
navigator.sendBeacon = (url, data) => {
|
|
91
|
+
try {
|
|
92
|
+
nativeFetch(toProxy(url), { method: 'POST', body: data, keepalive: true,
|
|
93
|
+
headers: { 'x-dsh-guest-sub': '1' } }).catch(() => {});
|
|
94
|
+
return true;
|
|
95
|
+
} catch { return false; }
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
let childRequestId = 0;
|
|
99
|
+
const childError = code => {
|
|
100
|
+
const error = new Error(code + ': this sidebar supports URL-only tabs, not native child windows or opener relationships');
|
|
101
|
+
error.name = 'NotSupportedError'; error.code = code;
|
|
102
|
+
return error;
|
|
103
|
+
};
|
|
104
|
+
const childRequest = (mode, url) => {
|
|
105
|
+
if (loadId === undefined) throw childError('sidebar-tab-owner-not-ready');
|
|
106
|
+
parent.postMessage({ type: 'dsh.browser.guest.child.request', loadId, requestId: ++childRequestId, mode, url }, '*');
|
|
107
|
+
};
|
|
108
|
+
const nativeChild = url => {
|
|
109
|
+
attempt(() => childRequest('native-opener', url));
|
|
110
|
+
throw childError('BROWSER_NATIVE_CHILD_UNAVAILABLE');
|
|
111
|
+
};
|
|
112
|
+
const detached = features => String(features || '').split(',').some(feature => {
|
|
113
|
+
const [key, value] = feature.trim().toLowerCase().split(/\\s*=\\s*/);
|
|
114
|
+
return ['noopener', 'noreferrer'].includes(key) && !['0', 'no', 'false'].includes(value);
|
|
115
|
+
});
|
|
116
|
+
attempt(() => { window.open = (url, target = '_blank', features = '') => {
|
|
117
|
+
const name = String(target || '_blank').toLowerCase();
|
|
118
|
+
if (name !== '_self' && (name !== '_blank' || !detached(features))) return nativeChild(String(url || ''));
|
|
119
|
+
const next = realURL(url == null || String(url) === '' ? 'about:blank' : url);
|
|
120
|
+
if (!/^https?:$/.test(next.protocol)) throw childError('invalid-child-url');
|
|
121
|
+
if (name === '_self') { location.assign(toProxy(next.href)); return window; }
|
|
122
|
+
childRequest('url-only', next.href);
|
|
123
|
+
return null;
|
|
124
|
+
}; });
|
|
125
|
+
for (const name of ['pushState', 'replaceState']) attempt(() => {
|
|
126
|
+
const original = history[name];
|
|
127
|
+
history[name] = function(state, title, url) {
|
|
128
|
+
if (url == null) return original.call(this, state, title, url);
|
|
129
|
+
const next = attempt(() => realURL(url));
|
|
130
|
+
const result = original.call(this, state, title, toProxy(url));
|
|
131
|
+
if (next && /^https?:$/.test(next.protocol)) real = next.href;
|
|
132
|
+
report();
|
|
133
|
+
return result;
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
let loadId;
|
|
137
|
+
const documentId = String(Date.now()) + ':' + String(Math.random());
|
|
138
|
+
let referenceRequestId = 0;
|
|
139
|
+
const reference = ${guestReferenceHandlerScript()};
|
|
140
|
+
const report = () => attempt(() => parent.postMessage({ type: 'dsh.browser.guest.navigation', url: real, depth: history.length, loadId, documentId, ready: document.readyState !== 'loading' }, '*'));
|
|
141
|
+
attempt(() => window.addEventListener('message', event => {
|
|
142
|
+
if (event.source !== parent || !event.data) return;
|
|
143
|
+
if (event.data.type === 'dsh.browser.guest.navigation.request') {
|
|
144
|
+
if (!Number.isSafeInteger(event.data.loadId) || event.data.loadId <= 0) return;
|
|
145
|
+
loadId = event.data.loadId;
|
|
146
|
+
report();
|
|
147
|
+
} else if (event.data.type === 'dsh.browser.guest.reference.request') {
|
|
148
|
+
const data = event.data;
|
|
149
|
+
if (event.origin !== location.origin || data.loadId !== loadId || loadId === undefined || data.documentId !== documentId
|
|
150
|
+
|| !Number.isSafeInteger(data.requestId) || data.requestId <= referenceRequestId) return;
|
|
151
|
+
referenceRequestId = data.requestId;
|
|
152
|
+
const ack = { type: 'dsh.browser.guest.reference.ack', requestId: data.requestId, loadId, documentId, url: real };
|
|
153
|
+
try {
|
|
154
|
+
const current = new URL(real), source = new URL(data.url);
|
|
155
|
+
current.hash = ''; source.hash = '';
|
|
156
|
+
if (current.href !== source.href || document.readyState === 'loading') throw new Error('source document is not ready');
|
|
157
|
+
if (!data.spec || typeof data.spec !== 'object' || Array.isArray(data.spec) || !['text', 'highlight', 'element', 'summary'].includes(data.operation)) throw new Error('invalid reference command');
|
|
158
|
+
if (data.operation !== 'element' && (!Number.isSafeInteger(data.spec.maxChars) || data.spec.maxChars <= 0
|
|
159
|
+
|| data.spec.maxChars > 2000000 || typeof data.spec.legacy !== 'boolean')) throw new Error('invalid text specification');
|
|
160
|
+
if (data.operation === 'element' && (!['image', 'table'].includes(data.spec.kind)
|
|
161
|
+
|| !data.spec.anchor || typeof data.spec.anchor !== 'object' || Array.isArray(data.spec.anchor))) throw new Error('invalid element specification');
|
|
162
|
+
if (data.operation === 'highlight' && (!Number.isSafeInteger(data.spec.start) || !Number.isSafeInteger(data.spec.end)
|
|
163
|
+
|| data.spec.start < 0 || data.spec.end <= data.spec.start)) throw new Error('invalid text positions');
|
|
164
|
+
const value = data.operation === 'summary'
|
|
165
|
+
? { url: real, title: String(document.title || '').slice(0, 1000), snapshotHint: reference('text', { maxChars: 1500, legacy: false }).text, fresh: true }
|
|
166
|
+
: reference(data.operation, data.spec);
|
|
167
|
+
parent.postMessage({ ...ack, ok: true, value }, event.origin);
|
|
168
|
+
} catch (error) { parent.postMessage({ ...ack, ok: false, reason: String(error).slice(0, 200) }, event.origin); }
|
|
169
|
+
} else if (event.data.type === 'dsh.browser.guest.history') {
|
|
170
|
+
if (event.data.delta === -1) history.back();
|
|
171
|
+
else if (event.data.delta === 1) history.forward();
|
|
172
|
+
}
|
|
173
|
+
}));
|
|
174
|
+
attempt(() => window.addEventListener('DOMContentLoaded', report));
|
|
175
|
+
attempt(() => window.addEventListener('popstate', () => {
|
|
176
|
+
const next = attempt(() => realURL(location.href));
|
|
177
|
+
if (next) real = next.href;
|
|
178
|
+
report();
|
|
179
|
+
}));
|
|
180
|
+
attempt(() => {
|
|
181
|
+
const proxyResource = value => {
|
|
182
|
+
if (/^(#|data:|blob:|about:|javascript:)/i.test(value.trim())) return value;
|
|
183
|
+
return toProxy(value);
|
|
184
|
+
};
|
|
185
|
+
${guestCssRuntimeScript()}
|
|
186
|
+
const proxySrcset = value => {
|
|
187
|
+
let result = '', position = 0;
|
|
188
|
+
while (position < value.length) {
|
|
189
|
+
const start = position;
|
|
190
|
+
while (position < value.length && /[\\s,]/.test(value[position])) position++;
|
|
191
|
+
result += value.slice(start, position);
|
|
192
|
+
if (position === value.length) break;
|
|
193
|
+
const urlStart = position;
|
|
194
|
+
while (position < value.length && !/\\s/.test(value[position])) position++;
|
|
195
|
+
let urlEnd = position;
|
|
196
|
+
while (urlEnd > urlStart && value[urlEnd - 1] === ',') urlEnd--;
|
|
197
|
+
result += proxyResource(value.slice(urlStart, urlEnd)) + value.slice(urlEnd, position);
|
|
198
|
+
if (urlEnd < position) continue;
|
|
199
|
+
const descriptors = position;
|
|
200
|
+
while (position < value.length && value[position] !== ',') position++;
|
|
201
|
+
result += value.slice(descriptors, position);
|
|
202
|
+
}
|
|
203
|
+
return result;
|
|
204
|
+
};
|
|
205
|
+
const resourceAttribute = (name, value) => name.toLowerCase() === 'style' ? proxyCss(value)
|
|
206
|
+
: name.toLowerCase() === 'srcset' ? proxySrcset(String(value)) : proxyResource(String(value));
|
|
207
|
+
const set = Element.prototype.setAttribute;
|
|
208
|
+
Element.prototype.setAttribute = function(name, value) {
|
|
209
|
+
if (this.tagName === 'LINK' && /^integrity$/i.test(name)) {
|
|
210
|
+
this.removeAttribute('integrity');
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
return set.call(this, name, /^(src|href|action|poster|srcset|style)$/i.test(name) ? resourceAttribute(name, value) : value);
|
|
214
|
+
};
|
|
215
|
+
for (const [name, prop] of [['HTMLImageElement', 'src'], ['HTMLScriptElement', 'src'],
|
|
216
|
+
['HTMLIFrameElement', 'src'], ['HTMLLinkElement', 'href'], ['HTMLSourceElement', 'src'],
|
|
217
|
+
['HTMLImageElement', 'srcset'], ['HTMLSourceElement', 'srcset'], ['HTMLVideoElement', 'poster']]) attempt(() => {
|
|
218
|
+
const proto = window[name].prototype;
|
|
219
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, prop);
|
|
220
|
+
if (!descriptor || !descriptor.set) return;
|
|
221
|
+
Object.defineProperty(proto, prop, Object.assign({}, descriptor, {
|
|
222
|
+
set(value) { descriptor.set.call(this, resourceAttribute(prop, value)); }
|
|
223
|
+
}));
|
|
224
|
+
});
|
|
225
|
+
const rewriteResource = node => {
|
|
226
|
+
if (!node || node.nodeType !== 1) return;
|
|
227
|
+
if (node.tagName === 'LINK' && node.hasAttribute('integrity')) node.removeAttribute('integrity');
|
|
228
|
+
rewriteStyleText(node);
|
|
229
|
+
const attributes = /^(A|FORM)$/.test(node.tagName) ? ['style'] : ['src', 'href', 'srcset', 'poster', 'style'];
|
|
230
|
+
for (const attribute of attributes) attempt(() => {
|
|
231
|
+
const value = node.getAttribute(attribute);
|
|
232
|
+
if (!value || !value.trim()) return;
|
|
233
|
+
const next = resourceAttribute(attribute, value);
|
|
234
|
+
if (next !== value) node.setAttribute(attribute, next);
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
const rewriteTree = node => {
|
|
238
|
+
rewriteResource(node);
|
|
239
|
+
if (node && node.querySelectorAll) {
|
|
240
|
+
for (const descendant of node.querySelectorAll('[src],[href],[srcset],[poster],[style],[integrity],style')) rewriteResource(descendant);
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
for (const name of ['Node', 'Element', 'Document', 'DocumentFragment']) {
|
|
244
|
+
for (const method of ['appendChild', 'insertBefore', 'replaceChild', 'append', 'prepend', 'before', 'after', 'replaceWith', 'replaceChildren', 'insertAdjacentElement']) attempt(() => {
|
|
245
|
+
const proto = window[name].prototype;
|
|
246
|
+
if (!Object.prototype.hasOwnProperty.call(proto, method)) return;
|
|
247
|
+
const original = proto[method];
|
|
248
|
+
proto[method] = function(...args) {
|
|
249
|
+
if (isStyle(this)) args = args.map(value => {
|
|
250
|
+
if (typeof value === 'string') return proxyCss(value);
|
|
251
|
+
if (value && value.nodeType === 3) value.textContent = proxyCss(value.textContent);
|
|
252
|
+
return value;
|
|
253
|
+
});
|
|
254
|
+
for (const node of args) if (node && typeof node === 'object') rewriteTree(node);
|
|
255
|
+
return original.apply(this, args);
|
|
256
|
+
};
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
const html = Object.getOwnPropertyDescriptor(Element.prototype, 'innerHTML');
|
|
260
|
+
let inert;
|
|
261
|
+
const rewriteMarkup = (value, context) => {
|
|
262
|
+
if (!inert) inert = document.implementation.createHTMLDocument('');
|
|
263
|
+
const container = context && context.nodeType === 1
|
|
264
|
+
? inert.createElementNS(context.namespaceURI, context.localName) : inert.createElement('div');
|
|
265
|
+
html.set.call(container, value);
|
|
266
|
+
rewriteTree(container.content || container);
|
|
267
|
+
return html.get.call(container);
|
|
268
|
+
};
|
|
269
|
+
for (const prop of ['innerHTML', 'outerHTML']) attempt(() => {
|
|
270
|
+
const descriptor = Object.getOwnPropertyDescriptor(Element.prototype, prop);
|
|
271
|
+
Object.defineProperty(Element.prototype, prop, Object.assign({}, descriptor, {
|
|
272
|
+
set(value) { descriptor.set.call(this, rewriteMarkup(value, prop === 'innerHTML' ? this : this.parentElement)); }
|
|
273
|
+
}));
|
|
274
|
+
});
|
|
275
|
+
attempt(() => {
|
|
276
|
+
const original = Element.prototype.insertAdjacentHTML;
|
|
277
|
+
Element.prototype.insertAdjacentHTML = function(position, value) {
|
|
278
|
+
const outside = /^(beforebegin|afterend)$/i.test(position);
|
|
279
|
+
return original.call(this, position, rewriteMarkup(value, outside ? this.parentElement : this));
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
attempt(() => {
|
|
283
|
+
const original = window.Range.prototype.createContextualFragment;
|
|
284
|
+
window.Range.prototype.createContextualFragment = function(value) {
|
|
285
|
+
const context = this.startContainer.nodeType === 1 ? this.startContainer : this.startContainer.parentElement;
|
|
286
|
+
return original.call(this, rewriteMarkup(value, context));
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
const observer = new MutationObserver(records => {
|
|
290
|
+
for (const record of records) attempt(() => {
|
|
291
|
+
if (record.type === 'attributes') rewriteResource(record.target);
|
|
292
|
+
else if (record.type === 'characterData') rewriteStyleText(record.target.parentNode);
|
|
293
|
+
else for (const node of record.addedNodes) rewriteTree(node);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
observer.observe(document, { childList: true, subtree: true, attributes: true, characterData: true,
|
|
297
|
+
attributeFilter: ['src', 'href', 'srcset', 'poster', 'action', 'style', 'integrity'] });
|
|
298
|
+
rewriteTree(document.documentElement);
|
|
299
|
+
});
|
|
300
|
+
attempt(() => document.addEventListener('click', event => {
|
|
301
|
+
attempt(() => {
|
|
302
|
+
let node = event.target;
|
|
303
|
+
while (node && node.tagName !== 'A') node = node.parentNode;
|
|
304
|
+
if (!node || !node.hasAttribute('href') || node.hasAttribute('download')) return;
|
|
305
|
+
const href = node.getAttribute('href');
|
|
306
|
+
const url = realURL(href);
|
|
307
|
+
if (!/^https?:$/.test(url.protocol)) return;
|
|
308
|
+
event.preventDefault();
|
|
309
|
+
const target = (node.getAttribute('target') || '_self').toLowerCase();
|
|
310
|
+
if (target !== '_self') {
|
|
311
|
+
const opener = /(?:^|\\s)opener(?:\\s|$)/i.test(node.getAttribute('rel') || '');
|
|
312
|
+
try { if (target !== '_blank' || opener) nativeChild(url.href); else childRequest('url-only', url.href); }
|
|
313
|
+
catch (error) { console.error('[dsh-browser]', error); }
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
location.assign(toProxy(href));
|
|
317
|
+
});
|
|
318
|
+
}, true));
|
|
319
|
+
const prepareForm = (form, submitter) => {
|
|
320
|
+
const action = submitter && submitter.getAttribute('formaction') || form.getAttribute('action') || real;
|
|
321
|
+
const method = (submitter && submitter.getAttribute('formmethod') || form.getAttribute('method') || 'GET').toUpperCase();
|
|
322
|
+
const url = realURL(action);
|
|
323
|
+
if (!/^https?:$/.test(url.protocol)) return false;
|
|
324
|
+
const target = (submitter && submitter.getAttribute('formtarget') || form.getAttribute('target') || '_self').toLowerCase();
|
|
325
|
+
if (target !== '_self' && (target !== '_blank' || method !== 'GET'
|
|
326
|
+
|| /(?:^|\\s)opener(?:\\s|$)/i.test(form.getAttribute('rel') || ''))) {
|
|
327
|
+
try { nativeChild(url.href); } catch (error) { console.error('[dsh-browser]', error); }
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
if (method === 'GET') {
|
|
331
|
+
const params = new URLSearchParams();
|
|
332
|
+
const data = submitter ? new FormData(form, submitter) : new FormData(form);
|
|
333
|
+
for (const [key, value] of data) params.append(key, typeof value === 'string' ? value : value.name);
|
|
334
|
+
url.search = params.toString();
|
|
335
|
+
if (target === '_blank') {
|
|
336
|
+
try { childRequest('url-only', url.href); } catch (error) { console.error('[dsh-browser]', error); }
|
|
337
|
+
} else location.assign(toProxy(url.href));
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
form.setAttribute('action', toProxy(url.href));
|
|
341
|
+
form.setAttribute('target', '_self');
|
|
342
|
+
if (submitter && submitter.hasAttribute('formaction')) submitter.setAttribute('formaction', toProxy(url.href));
|
|
343
|
+
if (submitter && submitter.hasAttribute('formtarget')) submitter.setAttribute('formtarget', '_self');
|
|
344
|
+
return false;
|
|
345
|
+
};
|
|
346
|
+
attempt(() => document.addEventListener('submit', event => {
|
|
347
|
+
attempt(() => { if (event.target && event.target.tagName === 'FORM' && prepareForm(event.target, event.submitter)) event.preventDefault(); });
|
|
348
|
+
}, true));
|
|
349
|
+
attempt(() => {
|
|
350
|
+
const submit = HTMLFormElement.prototype.submit;
|
|
351
|
+
HTMLFormElement.prototype.submit = function() {
|
|
352
|
+
if (!attempt(() => prepareForm(this))) return submit.call(this);
|
|
353
|
+
};
|
|
354
|
+
});
|
|
355
|
+
})();`;
|
|
356
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Synchronous Web Storage remains isolated from the application's real origin. */
|
|
2
|
+
export function guestStorageScript(config) {
|
|
3
|
+
return `(() => {
|
|
4
|
+
const config = ${JSON.stringify(config).replace(/</gu, '\\u003c')};
|
|
5
|
+
const XHR = XMLHttpRequest, open = XHR.prototype.open, send = XHR.prototype.send, header = XHR.prototype.setRequestHeader;
|
|
6
|
+
const rpc = (area, op, key, value) => {
|
|
7
|
+
const endpoint = location.pathname + '?u=' + encodeURIComponent(real) + '&storage-token=' + encodeURIComponent(config.token);
|
|
8
|
+
const xhr = new XHR();
|
|
9
|
+
open.call(xhr, 'POST', endpoint, false);
|
|
10
|
+
header.call(xhr, 'content-type', 'text/plain;charset=UTF-8');
|
|
11
|
+
send.call(xhr, JSON.stringify({ area, op, key, value }));
|
|
12
|
+
let response;
|
|
13
|
+
try { response = JSON.parse(xhr.responseText); } catch { throw new DOMException('Guest storage is unavailable', 'UnknownError'); }
|
|
14
|
+
if (xhr.status !== 200 || !response.ok) throw new DOMException('Guest storage request failed', response.name || 'UnknownError');
|
|
15
|
+
return response.value;
|
|
16
|
+
};
|
|
17
|
+
const cookieSnapshots = new Map([[real, config.cookies || '']]);
|
|
18
|
+
Object.defineProperty(Document.prototype, 'cookie', { configurable: true, enumerable: true,
|
|
19
|
+
get: function cookie() {
|
|
20
|
+
if (this !== document) throw new TypeError('Illegal invocation');
|
|
21
|
+
try { const value = rpc('cookies', 'get'); cookieSnapshots.set(real, value); return value; }
|
|
22
|
+
catch (error) { if (error.name === 'NetworkError') return cookieSnapshots.get(real) || ''; throw error; }
|
|
23
|
+
},
|
|
24
|
+
set: function cookie(value) {
|
|
25
|
+
if (this !== document) throw new TypeError('Illegal invocation');
|
|
26
|
+
cookieSnapshots.set(real, rpc('cookies', 'set', undefined, String(value)));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
for (const area of ['local', 'session']) {
|
|
30
|
+
const storage = Object.create(Storage.prototype);
|
|
31
|
+
const entries = () => rpc(area, 'entries');
|
|
32
|
+
Object.defineProperties(storage, {
|
|
33
|
+
getItem: { configurable: true, value: function(key) { if (!arguments.length) throw new TypeError('A key is required'); return rpc(area, 'get', String(key)); } },
|
|
34
|
+
setItem: { configurable: true, value: function(key, value) { if (arguments.length < 2) throw new TypeError('A key and value are required'); rpc(area, 'set', String(key), String(value)); } },
|
|
35
|
+
removeItem: { configurable: true, value: function(key) { if (!arguments.length) throw new TypeError('A key is required'); rpc(area, 'remove', String(key)); } },
|
|
36
|
+
clear: { configurable: true, value: () => { rpc(area, 'clear'); } },
|
|
37
|
+
key: { configurable: true, value: function(index) { if (!arguments.length) throw new TypeError('An index is required'); return entries()[Number(index) >>> 0]?.[0] ?? null; } },
|
|
38
|
+
length: { configurable: true, get: () => entries().length }
|
|
39
|
+
});
|
|
40
|
+
const proxy = new Proxy(storage, {
|
|
41
|
+
get: (target, key) => typeof key !== 'string' || key in target ? Reflect.get(target, key) : rpc(area, 'get', key) ?? undefined,
|
|
42
|
+
set: (_, key, value) => { if (typeof key !== 'string') return false; rpc(area, 'set', key, String(value)); return true; },
|
|
43
|
+
deleteProperty: (_, key) => { if (typeof key !== 'string') return false; rpc(area, 'remove', key); return true; },
|
|
44
|
+
has: (target, key) => key in target || (typeof key === 'string' && rpc(area, 'get', key) !== null),
|
|
45
|
+
ownKeys: target => [...Reflect.ownKeys(target), ...entries().map(pair => pair[0]).filter(key => !Object.hasOwn(target, key))],
|
|
46
|
+
getOwnPropertyDescriptor: (target, key) => Object.getOwnPropertyDescriptor(target, key)
|
|
47
|
+
|| (typeof key === 'string' && rpc(area, 'get', key) !== null ? { configurable: true, enumerable: true, writable: true, value: rpc(area, 'get', key) } : undefined)
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(window, area + 'Storage', { configurable: true, get: () => proxy });
|
|
50
|
+
}
|
|
51
|
+
})();`;
|
|
52
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { BROWSER_PROFILE_DIR } from '../../assets/browser-policy.mjs';
|
|
2
|
+
import { createHmac, randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
|
|
3
|
+
import { closeSync, constants, fchmodSync, fstatSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { dshHome } from './paths.js';
|
|
6
|
+
const MAX_STORE_BYTES = 64 * 1024 * 1024;
|
|
7
|
+
const serialized = (partitions) => JSON.stringify([...partitions].map(([origin, entries]) => [origin, [...entries]]));
|
|
8
|
+
function fail(name) { throw Object.assign(new Error(name), { name }); }
|
|
9
|
+
/** Storage capabilities are issued only in browser navigation responses, never fetchable HTML. */
|
|
10
|
+
export class GuestStorage {
|
|
11
|
+
directory;
|
|
12
|
+
quota;
|
|
13
|
+
secret = randomBytes(32);
|
|
14
|
+
local = new Map();
|
|
15
|
+
session = new Map();
|
|
16
|
+
constructor(directory, quota = 5 * 1024 * 1024) {
|
|
17
|
+
this.directory = directory;
|
|
18
|
+
this.quota = quota;
|
|
19
|
+
if (directory === undefined)
|
|
20
|
+
return;
|
|
21
|
+
let fd;
|
|
22
|
+
try {
|
|
23
|
+
fd = openSync(join(directory, 'storage.json'), constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
24
|
+
if (!fstatSync(fd).isFile() || fstatSync(fd).size > MAX_STORE_BYTES)
|
|
25
|
+
return;
|
|
26
|
+
fchmodSync(fd, 0o600);
|
|
27
|
+
const saved = JSON.parse(readFileSync(fd, 'utf8'));
|
|
28
|
+
if (!saved || typeof saved !== 'object' || !('version' in saved) || saved.version !== 1
|
|
29
|
+
|| !('origins' in saved) || !Array.isArray(saved.origins))
|
|
30
|
+
return;
|
|
31
|
+
for (const item of saved.origins) {
|
|
32
|
+
if (!Array.isArray(item) || item.length !== 2 || typeof item[0] !== 'string' || !Array.isArray(item[1]))
|
|
33
|
+
continue;
|
|
34
|
+
try {
|
|
35
|
+
if (new URL(item[0]).origin !== item[0] || !/^https?:/u.test(item[0]))
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const entries = new Map();
|
|
42
|
+
for (const pair of item[1]) {
|
|
43
|
+
if (Array.isArray(pair) && pair.length === 2 && pair.every(value => typeof value === 'string'))
|
|
44
|
+
entries.set(pair[0], pair[1]);
|
|
45
|
+
}
|
|
46
|
+
if (this.size(entries) <= quota)
|
|
47
|
+
this.local.set(item[0], entries);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch { }
|
|
51
|
+
finally {
|
|
52
|
+
if (fd !== undefined)
|
|
53
|
+
closeSync(fd);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
issue(origin, context) {
|
|
57
|
+
const payload = Buffer.from(JSON.stringify({ origin, context })).toString('base64url');
|
|
58
|
+
return payload + '.' + createHmac('sha256', this.secret).update(payload).digest('base64url');
|
|
59
|
+
}
|
|
60
|
+
authorize(token, origin) {
|
|
61
|
+
if (token.length > 8192)
|
|
62
|
+
fail('SecurityError');
|
|
63
|
+
const [payload, signature, extra] = token.split('.');
|
|
64
|
+
const expected = createHmac('sha256', this.secret).update(payload ?? '').digest();
|
|
65
|
+
const received = Buffer.from(signature ?? '', 'base64url');
|
|
66
|
+
if (extra !== undefined || received.length !== expected.length || !timingSafeEqual(received, expected))
|
|
67
|
+
fail('SecurityError');
|
|
68
|
+
let scope;
|
|
69
|
+
try {
|
|
70
|
+
scope = JSON.parse(Buffer.from(payload, 'base64url').toString('utf8'));
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
fail('SecurityError');
|
|
74
|
+
}
|
|
75
|
+
if (scope?.origin !== origin || typeof scope.context !== 'string')
|
|
76
|
+
fail('SecurityError');
|
|
77
|
+
return { context: scope.context };
|
|
78
|
+
}
|
|
79
|
+
execute(token, origin, input) {
|
|
80
|
+
const scope = this.authorize(token, origin);
|
|
81
|
+
if (!input || typeof input !== 'object' || Array.isArray(input))
|
|
82
|
+
fail('TypeError');
|
|
83
|
+
const { area, op, key, value } = input;
|
|
84
|
+
if (area !== 'local' && area !== 'session')
|
|
85
|
+
fail('TypeError');
|
|
86
|
+
if (!['entries', 'get', 'set', 'remove', 'clear'].includes(String(op)))
|
|
87
|
+
fail('TypeError');
|
|
88
|
+
if (op !== 'entries' && op !== 'clear' && typeof key !== 'string')
|
|
89
|
+
fail('TypeError');
|
|
90
|
+
if (op === 'set' && typeof value !== 'string')
|
|
91
|
+
fail('TypeError');
|
|
92
|
+
const partitions = area === 'local' ? this.local : this.session;
|
|
93
|
+
const partition = area === 'local' ? origin : JSON.stringify([scope.context, origin]);
|
|
94
|
+
const current = partitions.get(partition) ?? new Map();
|
|
95
|
+
if (op === 'entries')
|
|
96
|
+
return [...current];
|
|
97
|
+
if (op === 'get')
|
|
98
|
+
return current.get(key) ?? null;
|
|
99
|
+
const next = new Map(current);
|
|
100
|
+
if (op === 'clear')
|
|
101
|
+
next.clear();
|
|
102
|
+
else if (op === 'remove')
|
|
103
|
+
next.delete(key);
|
|
104
|
+
else
|
|
105
|
+
next.set(key, value);
|
|
106
|
+
if (this.size(next) > this.quota)
|
|
107
|
+
fail('QuotaExceededError');
|
|
108
|
+
const updated = new Map(partitions);
|
|
109
|
+
if (next.size === 0)
|
|
110
|
+
updated.delete(partition);
|
|
111
|
+
else
|
|
112
|
+
updated.set(partition, next);
|
|
113
|
+
if (Buffer.byteLength(serialized(updated), 'utf8') > MAX_STORE_BYTES)
|
|
114
|
+
fail('QuotaExceededError');
|
|
115
|
+
if (area === 'local') {
|
|
116
|
+
this.persist(updated);
|
|
117
|
+
this.local = updated;
|
|
118
|
+
}
|
|
119
|
+
else
|
|
120
|
+
this.session = updated;
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
size(entries) {
|
|
124
|
+
return [...entries].reduce((size, [key, value]) => size + 2 * (key.length + value.length), 0);
|
|
125
|
+
}
|
|
126
|
+
persist(origins) {
|
|
127
|
+
if (this.directory === undefined)
|
|
128
|
+
return;
|
|
129
|
+
const file = join(this.directory, 'storage.json'), temporary = file + '.' + randomUUID() + '.tmp';
|
|
130
|
+
let fd;
|
|
131
|
+
try {
|
|
132
|
+
mkdirSync(this.directory, { recursive: true, mode: 0o700 });
|
|
133
|
+
fd = openSync(temporary, 'wx', 0o600);
|
|
134
|
+
fchmodSync(fd, 0o600);
|
|
135
|
+
writeFileSync(fd, '{"version":1,"origins":' + serialized(origins) + '}');
|
|
136
|
+
fsyncSync(fd);
|
|
137
|
+
closeSync(fd);
|
|
138
|
+
fd = undefined;
|
|
139
|
+
renameSync(temporary, file);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
fail('UnknownError');
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
if (fd !== undefined)
|
|
146
|
+
closeSync(fd);
|
|
147
|
+
try {
|
|
148
|
+
rmSync(temporary, { force: true });
|
|
149
|
+
}
|
|
150
|
+
catch { }
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const stores = new Map();
|
|
155
|
+
export function localGuestStorage() {
|
|
156
|
+
const directory = join(dshHome(), BROWSER_PROFILE_DIR, 'web-storage');
|
|
157
|
+
let store = stores.get(directory);
|
|
158
|
+
if (store === undefined) {
|
|
159
|
+
store = new GuestStorage(directory);
|
|
160
|
+
stores.set(directory, store);
|
|
161
|
+
}
|
|
162
|
+
return store;
|
|
163
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BROWSER_PROFILE_DIR } from '../../assets/browser-policy.mjs';
|
|
1
2
|
/**
|
|
2
3
|
* Persistent browsing history: which pages the shared browser actually visited,
|
|
3
4
|
* kept independently from any session's operation log (`dsh_browser_history`) and
|
|
@@ -29,7 +30,7 @@ const PRUNE_SLACK = 500;
|
|
|
29
30
|
*/
|
|
30
31
|
export function visitedHistoryPath() {
|
|
31
32
|
const home = dshHome();
|
|
32
|
-
return join(home,
|
|
33
|
+
return join(home, BROWSER_PROFILE_DIR, 'history.jsonl');
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
35
36
|
* Append-only browsing history with bounded retention. Every method tolerates a
|