dsh-builtin-browser 1.0.1 → 1.0.3
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 +55 -0
- package/README.md +1 -1
- package/assets/browser-panel-locales.mjs +37 -5
- package/assets/browser-policy.d.mts +29 -0
- package/assets/browser-policy.mjs +40 -0
- package/desktop-bridge/desktop-discovery.d.mts +1 -1
- package/desktop-bridge/desktop-discovery.mjs +59 -9
- package/desktop-bridge/desktop-identity.json +12 -0
- package/desktop-bridge/install.mjs +14 -7
- package/desktop-bridge/plugin-browser-bridge.js +19 -7
- package/docs/acceptance-2026-11-27.md +67 -0
- package/docs/architecture.md +1 -1
- package/docs/development.md +33 -4
- package/docs/dsh-0.2.3-host-patch-task.md +34 -0
- package/docs/hardcoding-audit.md +28 -8
- package/docs/known-issues.md +26 -0
- package/docs/limitations.md +6 -2
- package/docs/tool-reference.md +1 -1
- package/docs/v1.1.0-bu-data-batching-task.md +66 -0
- package/docs/v1.1.0-compat-hardcoding-task.md +85 -0
- 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/README.md +4 -0
- package/dsh-host-patch/apply.mjs +61 -13
- package/dsh-host-patch/rc3-revision9.json.gz +0 -0
- package/dsh-host-patch/rc5-revision9.json.gz +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 +218 -0
- 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 +260 -0
- package/dsh-host-patch/tauri/desktop-main.cjs +62 -0
- package/dsh-host-patch/tauri/sidebar-session.cjs +104 -0
- package/dsh-host-patch/tauri-revision1.json +39 -0
- package/dsh-host-patch/tauri.json +43 -0
- package/dsh-host-patch/v023-alpha2.json +153 -0
- package/lib/browser/anti-bot.js +215 -0
- package/lib/browser/deep-dom.js +39 -0
- package/lib/browser/runtime.js +15 -0
- package/lib/browser/takeover-target.js +13 -6
- package/lib/browser/types.js +30 -1
- package/lib/browser-electron/authenticated-route.js +16 -2
- package/lib/browser-electron/automatic-maintenance.js +16 -10
- package/lib/browser-electron/bridge-connection.js +3 -8
- package/lib/browser-electron/bridge-install.js +2 -1
- package/lib/browser-electron/bridge-status.js +55 -26
- package/lib/browser-electron/desktop-bridge-host.js +7 -6
- package/lib/browser-electron/desktop-identity.js +28 -5
- package/lib/browser-electron/desktop-shell.js +64 -0
- package/lib/browser-electron/electron-provision.js +105 -18
- package/lib/browser-electron/entry.js +129 -44
- package/lib/browser-electron/extension-browser.js +4 -4
- package/lib/browser-electron/foreground-watch.js +134 -0
- package/lib/browser-electron/guest-cookie-jar.js +13 -13
- package/lib/browser-electron/guest-route.js +181 -32
- package/lib/browser-electron/guest-runtime.js +61 -10
- package/lib/browser-electron/guest-storage.js +2 -2
- package/lib/browser-electron/history-store.js +1 -5
- package/lib/browser-electron/host-main.js +8 -4
- package/lib/browser-electron/host-patch-maintenance.js +14 -8
- package/lib/browser-electron/maintenance-route.js +2 -1
- package/lib/browser-electron/missing-system-browser.js +5 -9
- package/lib/browser-electron/preferred-browser.js +7 -3
- package/lib/browser-electron/preview-route.js +9 -13
- package/lib/browser-electron/process-ownership.js +1 -1
- package/lib/browser-electron/profile-command.js +2 -1
- package/lib/browser-electron/profile-extension.js +5 -0
- package/lib/browser-electron/profile-lease.js +152 -47
- package/lib/browser-electron/provider-core.js +527 -0
- package/lib/browser-electron/provider-interaction.js +963 -0
- package/lib/browser-electron/provider-media.js +518 -0
- package/lib/browser-electron/provider-navigation.js +301 -0
- package/lib/browser-electron/provider-observation.js +623 -0
- package/lib/browser-electron/provider-tabs.js +372 -0
- package/lib/browser-electron/provider.js +150 -3301
- package/lib/browser-electron/reference-route.js +9 -18
- package/lib/browser-electron/remote-host.js +79 -34
- package/lib/browser-electron/runtime-status.js +56 -6
- package/lib/browser-electron/settings-store.js +3 -6
- package/lib/browser-electron/sidebar-only-host.js +1 -1
- package/lib/browser-electron/system-browser.js +539 -172
- package/lib/browser-electron/tauri-host.js +208 -0
- package/lib/browser-electron/virtual-cursor.js +23 -13
- package/lib/browser-reference/service.js +22 -4
- package/lib/browser-reference/web-sources.js +1 -1
- package/lib/client.js +43409 -0
- package/lib/compat/host-features.js +75 -0
- package/lib/reference-source.js +1 -1
- package/lib/reference-text.js +23 -1
- package/lib/takeover-protocol.js +1 -1
- package/lib/tool-browser/block-recovery.js +69 -0
- package/lib/tool-browser/code-tool.js +170 -19
- package/lib/tool-browser/code-worker.js +115 -20
- package/lib/tool-browser/errors.js +34 -0
- package/lib/tool-browser/index.js +66 -3593
- package/lib/tool-browser/page-probe.js +227 -28
- package/lib/tool-browser/panel-page.js +2 -1
- package/lib/tool-browser/probe-client.js +157 -0
- package/lib/tool-browser/screenshot-annotations.js +108 -0
- package/lib/tool-browser/state.js +337 -0
- package/lib/tool-browser/takeover.js +1 -1
- package/lib/tool-browser/tools-debug.js +862 -0
- package/lib/tool-browser/tools-interaction.js +993 -0
- package/lib/tool-browser/tools-navigation.js +807 -0
- package/lib/tool-browser/tools-observation.js +461 -0
- package/lib/tool-browser/tools-reference.js +293 -0
- package/lib/web-guest.js +1 -0
- package/package.json +15 -53
- package/README.en.md +0 -89
- package/browser-extension/constants.mjs +0 -20
- package/browser-extension/controller.mjs +0 -293
- package/browser-extension/locales.mjs +0 -15
- package/browser-extension/manifest.json +0 -12
- package/browser-extension/options.html +0 -14
- package/browser-extension/options.mjs +0 -9
- package/browser-extension/permission-guard.mjs +0 -13
- package/browser-extension/worker.mjs +0 -74
- package/dist/client.cjs +0 -43167
- package/lib/browser-reference/submission-receipts.js +0 -139
- package/scripts/build.mjs +0 -66
- package/scripts/bundle-host.mjs +0 -28
- package/scripts/fix-exports.mjs +0 -50
- package/scripts/install-electron.mjs +0 -51
- package/scripts/verify-exports.mjs +0 -47
- package/scripts/verify-preview-sdk.mjs +0 -93
- package/skills/dsh-builtin-browser/SKILL.md +0 -73
- package/skills/dsh-builtin-browser/references/batch.md +0 -53
- package/skills/dsh-builtin-browser/references/deliver.md +0 -31
- package/skills/dsh-builtin-browser/references/locate.md +0 -11
- package/skills/dsh-builtin-browser/references/recover.md +0 -11
- package/skills/dsh-builtin-browser/references/verify.md +0 -13
- package/skills/dsh-debug-host/SKILL.md +0 -56
- package/skills/dsh-debug-self/SKILL.md +0 -50
- package/src/bridge-compatibility.ts +0 -39
- package/src/browser/handles.ts +0 -89
- package/src/browser/runtime.ts +0 -560
- package/src/browser/takeover-target.ts +0 -36
- package/src/browser/types.ts +0 -817
- package/src/browser-electron/authenticated-route.ts +0 -84
- package/src/browser-electron/automatic-maintenance.ts +0 -726
- package/src/browser-electron/bridge-auto.ts +0 -159
- package/src/browser-electron/bridge-connection.ts +0 -385
- package/src/browser-electron/bridge-endpoint.ts +0 -129
- package/src/browser-electron/bridge-install.ts +0 -289
- package/src/browser-electron/bridge-maintenance.ts +0 -189
- package/src/browser-electron/bridge-status.ts +0 -347
- package/src/browser-electron/desktop-bridge-host.ts +0 -251
- package/src/browser-electron/desktop-identity.ts +0 -320
- package/src/browser-electron/document-readiness.ts +0 -45
- package/src/browser-electron/electron-provision.ts +0 -261
- package/src/browser-electron/entry.ts +0 -1299
- package/src/browser-electron/ephemeral-profile.ts +0 -189
- package/src/browser-electron/extension-browser.ts +0 -223
- package/src/browser-electron/extension-setup.ts +0 -67
- package/src/browser-electron/file-write.ts +0 -31
- package/src/browser-electron/guest-cookie-jar.ts +0 -176
- package/src/browser-electron/guest-cookie-store.ts +0 -59
- package/src/browser-electron/guest-css-runtime.ts +0 -76
- package/src/browser-electron/guest-css.ts +0 -68
- package/src/browser-electron/guest-route.ts +0 -568
- package/src/browser-electron/guest-runtime.ts +0 -357
- package/src/browser-electron/guest-storage-runtime.ts +0 -54
- package/src/browser-electron/guest-storage.ts +0 -117
- package/src/browser-electron/history-store.ts +0 -227
- package/src/browser-electron/host-main.ts +0 -1381
- package/src/browser-electron/host-patch-maintenance.ts +0 -112
- package/src/browser-electron/http-body.ts +0 -65
- package/src/browser-electron/json-reply.ts +0 -47
- package/src/browser-electron/maintenance-broker.ts +0 -166
- package/src/browser-electron/maintenance-lifecycle.ts +0 -91
- package/src/browser-electron/maintenance-route.ts +0 -67
- package/src/browser-electron/missing-system-browser.ts +0 -113
- package/src/browser-electron/open-slot.ts +0 -49
- package/src/browser-electron/paths.ts +0 -25
- package/src/browser-electron/preferred-browser.ts +0 -120
- package/src/browser-electron/preview-route.ts +0 -218
- package/src/browser-electron/process-ownership.ts +0 -168
- package/src/browser-electron/process.ts +0 -23
- package/src/browser-electron/profile-checkpoint.ts +0 -187
- package/src/browser-electron/profile-command.ts +0 -46
- package/src/browser-electron/profile-extension.ts +0 -124
- package/src/browser-electron/profile-lease.ts +0 -115
- package/src/browser-electron/profile-residue.ts +0 -49
- package/src/browser-electron/provider.ts +0 -4571
- package/src/browser-electron/reference-route.ts +0 -608
- package/src/browser-electron/remote-host.ts +0 -1462
- package/src/browser-electron/rpc-input.ts +0 -13
- package/src/browser-electron/rpc-ops.ts +0 -41
- package/src/browser-electron/runtime-diagnostics.ts +0 -38
- package/src/browser-electron/runtime-route.ts +0 -105
- package/src/browser-electron/runtime-status.ts +0 -242
- package/src/browser-electron/settings-route.ts +0 -64
- package/src/browser-electron/settings-store.ts +0 -589
- package/src/browser-electron/shortcuts-route.ts +0 -112
- package/src/browser-electron/sidebar-only-host.ts +0 -298
- package/src/browser-electron/startpage-shortcuts.ts +0 -213
- package/src/browser-electron/system-browser.ts +0 -1497
- package/src/browser-electron/timing.ts +0 -16
- package/src/browser-electron/virtual-cursor.ts +0 -152
- package/src/browser-electron/windows-system.ts +0 -24
- package/src/browser-reference/delivery.ts +0 -384
- package/src/browser-reference/entry.ts +0 -631
- package/src/browser-reference/export.ts +0 -339
- package/src/browser-reference/import.ts +0 -303
- package/src/browser-reference/page-script.ts +0 -1537
- package/src/browser-reference/service.ts +0 -1315
- package/src/browser-reference/store.ts +0 -172
- package/src/browser-reference/submission-receipts.ts +0 -122
- package/src/browser-reference/text-quote.ts +0 -219
- package/src/browser-reference/types.ts +0 -195
- package/src/browser-reference/visible.ts +0 -367
- package/src/browser-reference/web-sources.ts +0 -103
- package/src/client/browser/BrowserController.ts +0 -693
- package/src/client/browser/BrowserFrame.ts +0 -78
- package/src/client/browser/BrowserNavigation.ts +0 -169
- package/src/client/browser/BrowserPage.ts +0 -23
- package/src/client/browser/BrowserPersistence.ts +0 -44
- package/src/client/browser/IframeImpl.ts +0 -176
- package/src/client/browser/child-tabs.ts +0 -14
- package/src/client/browser/iframe-reference.ts +0 -67
- package/src/client/browser/initialization.ts +0 -262
- package/src/client/browser/omnibox.ts +0 -243
- package/src/client/browser/store.ts +0 -38
- package/src/client/browser/takeover-channel.ts +0 -72
- package/src/client/browser/url.ts +0 -46
- package/src/client/browser/web-reference-source.ts +0 -52
- package/src/client/css-modules.d.ts +0 -4
- package/src/client/definition.tsx +0 -30
- package/src/client/electron/ElectronWebViewImpl.ts +0 -364
- package/src/client/electron/ElectronWebviewPresentation.ts +0 -138
- package/src/client/electron/NativeChildPresentation.ts +0 -45
- package/src/client/electron/NativeViewPage.ts +0 -251
- package/src/client/electron/pages.ts +0 -23
- package/src/client/electron/reference-overlay.ts +0 -53
- package/src/client/electron/workspace.ts +0 -33
- package/src/client/index.ts +0 -293
- package/src/client/locales.ts +0 -857
- package/src/client/pages.ts +0 -28
- package/src/client/reference/client/BrowserRefLink.tsx +0 -142
- package/src/client/reference/client/draft-reference.ts +0 -167
- package/src/client/reference/client/index.ts +0 -7
- package/src/client/reference/client/ordered-submission.ts +0 -108
- package/src/client/reference/client/pending-delivery.ts +0 -216
- package/src/client/reference/client/plugin.ts +0 -189
- package/src/client/reference/client/production/ReferenceCapsules.tsx +0 -345
- package/src/client/reference/client/production/ReferenceDock.module.css +0 -193
- package/src/client/reference/client/production/ReferenceDock.tsx +0 -6
- package/src/client/reference/client/production/ReferenceFeedback.tsx +0 -15
- package/src/client/reference/client/production/ReferenceMath.tsx +0 -44
- package/src/client/reference/client/production/ReferenceText.tsx +0 -36
- package/src/client/reference/client/production/assembly.ts +0 -471
- package/src/client/reference/client/production/asset-store.ts +0 -144
- package/src/client/reference/client/production/availability.ts +0 -74
- package/src/client/reference/client/production/bytes.ts +0 -36
- package/src/client/reference/client/production/delivery-client.ts +0 -211
- package/src/client/reference/client/production/draft-adapter.ts +0 -508
- package/src/client/reference/client/production/http-transport.ts +0 -217
- package/src/client/reference/client/production/production-submission.ts +0 -310
- package/src/client/reference/client/production/protocol.ts +0 -231
- package/src/client/reference/client/production/reference-card.ts +0 -240
- package/src/client/reference/client/production/reference-labels.ts +0 -29
- package/src/client/reference/client/production/reply-link-bridge.ts +0 -222
- package/src/client/reference/client/production/reveal.ts +0 -215
- package/src/client/reference/client/production/runtime.ts +0 -1101
- package/src/client/reference/client/production/snapshot-adapter.ts +0 -154
- package/src/client/reference/client/production/source-marker.ts +0 -63
- package/src/client/reference/client/production/source-opener.ts +0 -55
- package/src/client/reference/client/production/styles.ts +0 -104
- package/src/client/reference/client/production/user-text-rule.ts +0 -58
- package/src/client/reference/client/reveal.ts +0 -107
- package/src/client/reference/client/scheme.ts +0 -114
- package/src/client/reference/client/types.ts +0 -168
- package/src/client/reference/css-modules.d.ts +0 -4
- package/src/client/reference/index.ts +0 -11
- package/src/client/reference-capture-owner.ts +0 -162
- package/src/client/reference-intents.ts +0 -36
- package/src/client/settings/index.ts +0 -34
- package/src/client/settings/panel.ts +0 -2657
- package/src/client/shortcut-open.ts +0 -30
- package/src/client/startpage/binding.ts +0 -99
- package/src/client/startpage/controller.ts +0 -303
- package/src/client/startpage/model.ts +0 -279
- package/src/client/view/Browser.module.css +0 -751
- package/src/client/view/BrowserBody.tsx +0 -314
- package/src/client/view/BrowserPresentation.ts +0 -9
- package/src/client/view/BrowserTitle.tsx +0 -17
- package/src/client/view/IframePresentation.ts +0 -344
- package/src/client/view/StartPage.tsx +0 -597
- package/src/client/view/TakeoverBanner.tsx +0 -21
- package/src/index.ts +0 -110
- package/src/reference-owner.ts +0 -5
- package/src/reference-page.ts +0 -9
- package/src/reference-source.ts +0 -3
- package/src/reference-text.ts +0 -197
- package/src/startpage-settings.ts +0 -103
- package/src/startpage.ts +0 -71
- package/src/takeover-protocol.ts +0 -19
- package/src/tool-browser/code-tool.ts +0 -401
- package/src/tool-browser/code-worker.ts +0 -639
- package/src/tool-browser/element-fields.ts +0 -167
- package/src/tool-browser/index.ts +0 -3733
- package/src/tool-browser/page-probe.ts +0 -474
- package/src/tool-browser/panel-page.ts +0 -124
- package/src/tool-browser/screenshot-image.ts +0 -49
- package/src/tool-browser/takeover.ts +0 -198
- package/src/types/electron-shim.d.ts +0 -144
- package/src/types.ts +0 -85
- package/src/web-guest.ts +0 -34
- package/tools/accept-desktop.mjs +0 -148
|
@@ -25,8 +25,9 @@
|
|
|
25
25
|
* Idempotent by version: installing twice keeps the buffers that already exist.
|
|
26
26
|
* @module dsh-browser/tool-browser/page-probe
|
|
27
27
|
*/
|
|
28
|
+
import { DEEP_DOM_SOURCE } from '../browser/deep-dom.js';
|
|
28
29
|
/** Bumped when the probe's shape changes; an older probe is replaced rather than trusted. */
|
|
29
|
-
export const PROBE_VERSION =
|
|
30
|
+
export const PROBE_VERSION = 10;
|
|
30
31
|
/** Where the probe keeps itself, and the only global it adds. */
|
|
31
32
|
const PROBE_KEY = '__dshProbe';
|
|
32
33
|
/**
|
|
@@ -35,7 +36,19 @@ const PROBE_KEY = '__dshProbe';
|
|
|
35
36
|
* Written as a string because it runs in the page, not here. Keep it dependency-free and ES5-safe:
|
|
36
37
|
* a page may be older than the harness.
|
|
37
38
|
*/
|
|
38
|
-
export const PROBE_INSTALL_SCRIPT = `(() => {
|
|
39
|
+
export const PROBE_INSTALL_SCRIPT = `(() => {${DEEP_DOM_SOURCE}
|
|
40
|
+
const frameOffset = (node) => {
|
|
41
|
+
let x = 0, y = 0
|
|
42
|
+
let doc = node && node.ownerDocument
|
|
43
|
+
while (doc && doc.defaultView && doc.defaultView.frameElement) {
|
|
44
|
+
const frame = doc.defaultView.frameElement
|
|
45
|
+
const r = frame.getBoundingClientRect()
|
|
46
|
+
x += r.left + (Number(frame.clientLeft) || 0)
|
|
47
|
+
y += r.top + (Number(frame.clientTop) || 0)
|
|
48
|
+
doc = frame.ownerDocument
|
|
49
|
+
}
|
|
50
|
+
return { x: x, y: y }
|
|
51
|
+
}
|
|
39
52
|
const KEY = ${JSON.stringify(PROBE_KEY)}
|
|
40
53
|
const VERSION = ${PROBE_VERSION}
|
|
41
54
|
const previous = globalThis[KEY]
|
|
@@ -88,12 +101,12 @@ export const PROBE_INSTALL_SCRIPT = `(() => {
|
|
|
88
101
|
const method = String((init && init.method) || (input && input.method) || 'GET').toUpperCase()
|
|
89
102
|
const started = Date.now()
|
|
90
103
|
state.pending += 1
|
|
91
|
-
const settle = (status) => {
|
|
104
|
+
const settle = (status, type) => {
|
|
92
105
|
state.pending = Math.max(0, state.pending - 1)
|
|
93
|
-
note({ at: started, kind: 'fetch', method: method, url: short(url, 300), status: status, ms: Date.now() - started })
|
|
106
|
+
note({ at: started, kind: 'fetch', method: method, url: short(url, 300), status: status, type: short(type || '', 80), ms: Date.now() - started })
|
|
94
107
|
}
|
|
95
108
|
return nativeFetch.apply(this, arguments).then(
|
|
96
|
-
(response) => { settle(response.status); return response },
|
|
109
|
+
(response) => { let type = ''; try { type = response.headers.get('content-type') || '' } catch (error) { /* opaque */ } settle(response.status, type); return response },
|
|
97
110
|
(error) => { settle(0); throw error },
|
|
98
111
|
)
|
|
99
112
|
})
|
|
@@ -112,7 +125,9 @@ export const PROBE_INSTALL_SCRIPT = `(() => {
|
|
|
112
125
|
state.pending += 1
|
|
113
126
|
const done = () => {
|
|
114
127
|
state.pending = Math.max(0, state.pending - 1)
|
|
115
|
-
|
|
128
|
+
let type = ''
|
|
129
|
+
try { type = this.getResponseHeader('content-type') || '' } catch (error) { /* not readable */ }
|
|
130
|
+
note({ at: meta.at, kind: 'xhr', method: meta.method, url: short(meta.url, 300), status: this.status || 0, type: short(type, 80), ms: Date.now() - meta.at })
|
|
116
131
|
this.removeEventListener('loadend', done)
|
|
117
132
|
}
|
|
118
133
|
this.addEventListener('loadend', done)
|
|
@@ -176,11 +191,11 @@ export const PROBE_INSTALL_SCRIPT = `(() => {
|
|
|
176
191
|
if (!target) return null
|
|
177
192
|
let node = null
|
|
178
193
|
try {
|
|
179
|
-
if (target.css) node =
|
|
194
|
+
if (target.css) node = __dshQuery(String(target.css))
|
|
180
195
|
else if (target.xpath) node = document.evaluate(String(target.xpath), document, null, 9, null).singleNodeValue
|
|
181
196
|
else if (target.text) {
|
|
182
197
|
const wanted = String(target.text).trim().toLowerCase()
|
|
183
|
-
const nodes =
|
|
198
|
+
const nodes = __dshQueryAll('button, a, [role=button], input, label, [role=tab], [role=option], [role=link]')
|
|
184
199
|
for (let i = 0; i < nodes.length; i += 1) {
|
|
185
200
|
const value = ((nodes[i].innerText || nodes[i].getAttribute('aria-label') || nodes[i].value || '') + '').trim().toLowerCase()
|
|
186
201
|
if (value && value.indexOf(wanted) !== -1) { node = nodes[i]; break }
|
|
@@ -190,32 +205,91 @@ export const PROBE_INSTALL_SCRIPT = `(() => {
|
|
|
190
205
|
if (!node) return null
|
|
191
206
|
if (scroll === true && typeof node.scrollIntoView === 'function') node.scrollIntoView({ block: 'center', inline: 'center', behavior: 'instant' })
|
|
192
207
|
const rect = node.getBoundingClientRect()
|
|
193
|
-
|
|
208
|
+
const offset = frameOffset(node)
|
|
209
|
+
state.lastFound = node
|
|
210
|
+
return { x: Math.round(offset.x + rect.left + rect.width / 2), y: Math.round(offset.y + rect.top + rect.height / 2), w: Math.round(rect.width), h: Math.round(rect.height), described: describe(node) }
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const composedParent = (node) => {
|
|
214
|
+
if (node.parentElement) return node.parentElement
|
|
215
|
+
if (node.parentNode && node.parentNode.host) return node.parentNode.host
|
|
216
|
+
const doc = node.ownerDocument
|
|
217
|
+
if (doc && (node === doc.documentElement || node.parentNode === doc)) {
|
|
218
|
+
const frame = doc.defaultView && doc.defaultView.frameElement
|
|
219
|
+
if (frame && frame !== node) return frame
|
|
220
|
+
}
|
|
221
|
+
return null
|
|
222
|
+
}
|
|
223
|
+
const deepHit = (x, y) => {
|
|
224
|
+
let cx = x, cy = y
|
|
225
|
+
let node = document.elementFromPoint(cx, cy)
|
|
226
|
+
for (let i = 0; node && i < 16; i += 1) {
|
|
227
|
+
if (node.shadowRoot && typeof node.shadowRoot.elementFromPoint === 'function') {
|
|
228
|
+
const inner = node.shadowRoot.elementFromPoint(cx, cy)
|
|
229
|
+
if (!inner || inner === node) break
|
|
230
|
+
node = inner
|
|
231
|
+
continue
|
|
232
|
+
}
|
|
233
|
+
if (node.tagName === 'IFRAME' || node.tagName === 'FRAME') {
|
|
234
|
+
let doc = null
|
|
235
|
+
try { doc = node.contentDocument } catch (error) { doc = null }
|
|
236
|
+
if (!doc || typeof doc.elementFromPoint !== 'function') break
|
|
237
|
+
const r = node.getBoundingClientRect()
|
|
238
|
+
cx = cx - r.left - (Number(node.clientLeft) || 0)
|
|
239
|
+
cy = cy - r.top - (Number(node.clientTop) || 0)
|
|
240
|
+
const inner = doc.elementFromPoint(cx, cy)
|
|
241
|
+
if (!inner || inner === node) break
|
|
242
|
+
node = inner
|
|
243
|
+
continue
|
|
244
|
+
}
|
|
245
|
+
break
|
|
246
|
+
}
|
|
247
|
+
return node
|
|
248
|
+
}
|
|
249
|
+
const computedStyle = (node) => {
|
|
250
|
+
try {
|
|
251
|
+
const win = node && node.ownerDocument && node.ownerDocument.defaultView
|
|
252
|
+
return (win && typeof win.getComputedStyle === 'function' ? win.getComputedStyle : getComputedStyle)(node)
|
|
253
|
+
} catch (error) { return null }
|
|
254
|
+
}
|
|
255
|
+
const floats = (node) => {
|
|
256
|
+
const style = computedStyle(node)
|
|
257
|
+
return !!style && (style.position === 'fixed' || style.position === 'sticky' || Number(style.zIndex) >= 100)
|
|
258
|
+
}
|
|
259
|
+
// A click at the point lands on the target when what is there is the target or inside it (an icon or label in a
|
|
260
|
+
// button, including inside open shadow roots and same-origin iframes), unless a floating layer between them
|
|
261
|
+
// (a modal inside the target) is what takes the click.
|
|
262
|
+
const lands = (target, hit) => {
|
|
263
|
+
for (let node = hit, depth = 0; node && depth < 64; node = composedParent(node), depth += 1) {
|
|
264
|
+
if (node === target) return true
|
|
265
|
+
if (floats(node)) return false
|
|
266
|
+
}
|
|
267
|
+
return false
|
|
194
268
|
}
|
|
195
269
|
|
|
196
270
|
const DISMISS = /(accept|agree|allow|continue|close|got it|dismiss|ok|agree|同意|接受|允许|继续|关闭|知道了|我知道了|我同意)/i
|
|
197
271
|
|
|
198
272
|
state.overlayAt = function (x, y) {
|
|
199
|
-
const
|
|
273
|
+
const px = Number(x), py = Number(y)
|
|
274
|
+
const top = deepHit(px, py)
|
|
200
275
|
if (!top) return { covers: null, dismiss: null }
|
|
276
|
+
if (state.lastFound && lands(state.lastFound, top)) return { covers: null, dismiss: null }
|
|
201
277
|
let node = top
|
|
202
278
|
let depth = 0
|
|
203
|
-
while (node && depth <
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const floating = style && (style.position === 'fixed' || style.position === 'sticky' || Number(style.zIndex) >= 100)
|
|
207
|
-
if (floating) {
|
|
208
|
-
const buttons = node.querySelectorAll('button, [role=button], a')
|
|
279
|
+
while (node && depth < 16) {
|
|
280
|
+
if (floats(node)) {
|
|
281
|
+
const buttons = node.querySelectorAll ? node.querySelectorAll('button, [role=button], a') : []
|
|
209
282
|
for (let i = 0; i < buttons.length && i < 60; i += 1) {
|
|
210
283
|
const label = ((buttons[i].innerText || '') + ' ' + (buttons[i].getAttribute('aria-label') || '')).trim()
|
|
211
284
|
if (DISMISS.test(label)) {
|
|
212
285
|
const rect = buttons[i].getBoundingClientRect()
|
|
213
|
-
|
|
286
|
+
const offset = frameOffset(buttons[i])
|
|
287
|
+
return { covers: describe(top), dismiss: { label: short(label, 40), x: Math.round(offset.x + rect.left + rect.width / 2), y: Math.round(offset.y + rect.top + rect.height / 2) } }
|
|
214
288
|
}
|
|
215
289
|
}
|
|
216
290
|
return { covers: describe(top), dismiss: null }
|
|
217
291
|
}
|
|
218
|
-
node = node
|
|
292
|
+
node = composedParent(node)
|
|
219
293
|
depth += 1
|
|
220
294
|
}
|
|
221
295
|
return { covers: describe(top), dismiss: null }
|
|
@@ -263,22 +337,28 @@ export const PROBE_INSTALL_SCRIPT = `(() => {
|
|
|
263
337
|
const out = []
|
|
264
338
|
if (needle === '') return out
|
|
265
339
|
const wanted = needle.toLowerCase()
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
const
|
|
340
|
+
const roots = __dshRoots()
|
|
341
|
+
for (let r = 0; r < roots.length; r += 1) {
|
|
342
|
+
const scope = roots[r]
|
|
343
|
+
const owner = scope.ownerDocument || scope
|
|
344
|
+
const root = scope.nodeType === 9 ? (scope.body || scope.documentElement) : scope
|
|
345
|
+
if (!root || typeof owner.createTreeWalker !== 'function') continue
|
|
346
|
+
const walker = owner.createTreeWalker(root, 4, null) // 4 = SHOW_TEXT
|
|
269
347
|
let node = walker.nextNode()
|
|
270
348
|
while (node) {
|
|
271
|
-
const
|
|
349
|
+
const parent = node.parentElement
|
|
350
|
+
const value = parent && /^(SCRIPT|STYLE|NOSCRIPT|TEMPLATE)$/.test(parent.tagName) ? '' : node.nodeValue || ''
|
|
272
351
|
let at = value.toLowerCase().indexOf(wanted)
|
|
273
352
|
while (at !== -1) {
|
|
274
|
-
const range =
|
|
353
|
+
const range = owner.createRange()
|
|
275
354
|
range.setStart(node, at)
|
|
276
355
|
range.setEnd(node, at + needle.length)
|
|
277
356
|
const rect = range.getBoundingClientRect()
|
|
357
|
+
const offset = frameOffset(node)
|
|
278
358
|
out.push({
|
|
279
359
|
text: short(value.slice(Math.max(0, at - 20), at + needle.length + 20).replace(/\\s+/g, ' ').trim(), 80),
|
|
280
|
-
x: Math.round(rect.left + rect.width / 2),
|
|
281
|
-
y: Math.round(rect.top + rect.height / 2),
|
|
360
|
+
x: Math.round(offset.x + rect.left + rect.width / 2),
|
|
361
|
+
y: Math.round(offset.y + rect.top + rect.height / 2),
|
|
282
362
|
host: node.parentElement ? describe(node.parentElement) : 'text',
|
|
283
363
|
})
|
|
284
364
|
if (out.length >= (all ? 50 : 5)) return out
|
|
@@ -286,6 +366,7 @@ export const PROBE_INSTALL_SCRIPT = `(() => {
|
|
|
286
366
|
}
|
|
287
367
|
node = walker.nextNode()
|
|
288
368
|
}
|
|
369
|
+
}
|
|
289
370
|
return out
|
|
290
371
|
}
|
|
291
372
|
|
|
@@ -325,10 +406,98 @@ export const PROBE_INSTALL_SCRIPT = `(() => {
|
|
|
325
406
|
links: query('a[href]'),
|
|
326
407
|
scrollX: Math.round(globalThis.scrollX || 0),
|
|
327
408
|
scrollY: Math.round(globalThis.scrollY || 0),
|
|
409
|
+
// The page's own geometry (issue #140): a screenshot that disagrees with these numbers was
|
|
410
|
+
// captured from a different surface, which is a fact only the page can prove.
|
|
411
|
+
vpWidth: Math.round(globalThis.innerWidth || 0),
|
|
412
|
+
vpHeight: Math.round(globalThis.innerHeight || 0),
|
|
413
|
+
dpr: Number(globalThis.devicePixelRatio || 1),
|
|
414
|
+
winWidth: Math.round(globalThis.outerWidth || 0),
|
|
415
|
+
winHeight: Math.round(globalThis.outerHeight || 0),
|
|
328
416
|
selection: short(globalThis.getSelection ? String(globalThis.getSelection()) : '', 120),
|
|
329
417
|
text: short(String(body || '').replace(/\\s+/g, ' ').trim(), 400),
|
|
330
418
|
}
|
|
331
419
|
}
|
|
420
|
+
// Where a page keeps its data before it becomes DOM: embedded state, the JSON APIs it called,
|
|
421
|
+
// resources it fetched before the probe existed, and endpoints it declares. Shapes only, never
|
|
422
|
+
// bodies, so the answer stays around 1-2 KB.
|
|
423
|
+
state.dataSources = function () {
|
|
424
|
+
const DATA_URL = /[.]json([?#]|$)|[/]api[/]|graphql|[/](locations?|stores?|search|query|products?|items?|listings?)([/?#.]|$)/i
|
|
425
|
+
const bytes = (text) => { try { return new Blob([text]).size } catch (error) { return String(text).length } }
|
|
426
|
+
const shape = (value) => {
|
|
427
|
+
const keys = value && typeof value === 'object' && !Array.isArray(value) ? Object.keys(value).slice(0, 12) : []
|
|
428
|
+
const arrays = []
|
|
429
|
+
const seen = new Set()
|
|
430
|
+
const walk = (node, path, depth) => {
|
|
431
|
+
if (!node || typeof node !== 'object' || seen.has(node) || depth > 6 || seen.size > 2000) return
|
|
432
|
+
seen.add(node)
|
|
433
|
+
if (Array.isArray(node)) {
|
|
434
|
+
if (node.length >= 3) arrays.push({ path: path || '(root)', length: node.length })
|
|
435
|
+
walk(node[0], path + '[0]', depth + 1)
|
|
436
|
+
return
|
|
437
|
+
}
|
|
438
|
+
for (const key of Object.keys(node).slice(0, 60)) walk(node[key], path ? path + '.' + key : key, depth + 1)
|
|
439
|
+
}
|
|
440
|
+
walk(value, '', 0)
|
|
441
|
+
arrays.sort((a, b) => b.length - a.length)
|
|
442
|
+
return { keys: keys, arrays: arrays.slice(0, 5) }
|
|
443
|
+
}
|
|
444
|
+
const embedded = []
|
|
445
|
+
const counts = {}
|
|
446
|
+
const scripts = Array.from(document.querySelectorAll('script#__NEXT_DATA__, script#__NUXT_DATA__, script[type="application/json"], script[type="application/ld+json"]'))
|
|
447
|
+
for (const node of scripts) {
|
|
448
|
+
const type = node.type || 'text/javascript'
|
|
449
|
+
const index = counts[type] = (counts[type] === undefined ? 0 : counts[type] + 1)
|
|
450
|
+
const text = node.textContent || ''
|
|
451
|
+
if (text.trim().length < 2 || embedded.length >= 8) continue
|
|
452
|
+
let parsed
|
|
453
|
+
try { parsed = JSON.parse(text) } catch (error) { parsed = undefined }
|
|
454
|
+
const name = node.id ? '#' + node.id : 'script[type="' + type + '"][' + index + ']'
|
|
455
|
+
embedded.push(Object.assign({ name: short(name, 80), bytes: bytes(text) }, parsed === undefined ? { parsed: false } : shape(parsed)))
|
|
456
|
+
}
|
|
457
|
+
for (const key of ['__NEXT_DATA__', '__NUXT__', '__INITIAL_STATE__', '__PRELOADED_STATE__', '__APOLLO_STATE__', '__remixContext']) {
|
|
458
|
+
let value
|
|
459
|
+
try { value = globalThis[key] } catch (error) { value = undefined }
|
|
460
|
+
if (value === undefined || value === null || typeof value !== 'object' || embedded.length >= 10) continue
|
|
461
|
+
let size = 0
|
|
462
|
+
try { size = bytes(JSON.stringify(value)) } catch (error) { size = 0 }
|
|
463
|
+
embedded.push(Object.assign({ name: 'window.' + key, bytes: size }, shape(value)))
|
|
464
|
+
}
|
|
465
|
+
const apis = []
|
|
466
|
+
const called = new Map()
|
|
467
|
+
for (const row of state.network) {
|
|
468
|
+
if ((row.kind !== 'fetch' && row.kind !== 'xhr') || !(row.status > 0)) continue
|
|
469
|
+
const id = row.method + ' ' + String(row.url).split('?')[0]
|
|
470
|
+
const json = /json/i.test(String(row.type || ''))
|
|
471
|
+
const hit = called.get(id)
|
|
472
|
+
if (hit) { hit.calls += 1; hit.url = row.url; hit.status = row.status; continue }
|
|
473
|
+
const entry = { method: row.method, url: row.url, status: row.status, type: short(String(row.type || '').split(';')[0], 40), calls: 1, json: json }
|
|
474
|
+
called.set(id, entry)
|
|
475
|
+
apis.push(entry)
|
|
476
|
+
}
|
|
477
|
+
apis.sort((a, b) => Number(b.json) - Number(a.json) || Number(DATA_URL.test(b.url)) - Number(DATA_URL.test(a.url)))
|
|
478
|
+
const known = new Set(apis.map(entry => String(entry.url).split('?')[0]))
|
|
479
|
+
const resources = []
|
|
480
|
+
let timings = []
|
|
481
|
+
try { timings = performance.getEntriesByType('resource') } catch (error) { timings = [] }
|
|
482
|
+
for (const entry of timings) {
|
|
483
|
+
const url = String(entry.name || '')
|
|
484
|
+
const initiator = String(entry.initiatorType || '')
|
|
485
|
+
if (initiator !== 'fetch' && initiator !== 'xmlhttprequest' && !DATA_URL.test(url)) continue
|
|
486
|
+
if (/^(script|css|img|link|image)$/.test(initiator) && !/[.]json([?#]|$)/i.test(url)) continue
|
|
487
|
+
const base = url.split('?')[0]
|
|
488
|
+
if (url.length > 2048 || known.has(base)) continue
|
|
489
|
+
known.add(base)
|
|
490
|
+
resources.push({ url: url, initiator: initiator, bytes: entry.transferSize || entry.encodedBodySize || 0 })
|
|
491
|
+
if (resources.length >= 12) break
|
|
492
|
+
}
|
|
493
|
+
const declared = []
|
|
494
|
+
const declare = (from, url) => { if (url && url.length <= 2048 && declared.length < 10 && !declared.some(entry => entry.url === url)) declared.push({ from: from, url: url }) }
|
|
495
|
+
try {
|
|
496
|
+
for (const link of Array.from(document.querySelectorAll('link[rel~="preload"][as="fetch"], link[rel~="prefetch"][as="fetch"]'))) declare('link[rel=' + link.rel + ']', link.href)
|
|
497
|
+
for (const node of Array.from(document.querySelectorAll('[data-api], [data-endpoint]')).slice(0, 20)) declare(node.hasAttribute('data-api') ? 'data-api' : 'data-endpoint', String(node.getAttribute('data-api') || node.getAttribute('data-endpoint') || ''))
|
|
498
|
+
} catch (error) { /* a document without these still answers the rest */ }
|
|
499
|
+
return { url: String(location.href), embedded: embedded, apis: apis.slice(0, 12), resources: resources, declared: declared }
|
|
500
|
+
}
|
|
332
501
|
globalThis[KEY] = state
|
|
333
502
|
return VERSION
|
|
334
503
|
})()`;
|
|
@@ -411,13 +580,13 @@ export function dragScript(from, to, steps = 12) {
|
|
|
411
580
|
*/
|
|
412
581
|
export function uploadScript(target, file) {
|
|
413
582
|
const spec = JSON.stringify({ target, file });
|
|
414
|
-
return `(() => {
|
|
583
|
+
return `(() => {${DEEP_DOM_SOURCE}
|
|
415
584
|
const spec = ${spec}
|
|
416
585
|
const probe = globalThis[${JSON.stringify(PROBE_KEY)}]
|
|
417
586
|
const where = probe ? probe.find(spec.target) : null
|
|
418
587
|
let node = null
|
|
419
588
|
try {
|
|
420
|
-
if (spec.target.by === 'css') node =
|
|
589
|
+
if (spec.target.by === 'css') node = __dshQuery(spec.target.value)
|
|
421
590
|
else if (spec.target.by === 'xpath') node = document.evaluate(spec.target.value, document, null, 9, null).singleNodeValue
|
|
422
591
|
else if (where) node = document.elementFromPoint(where.x, where.y)
|
|
423
592
|
} catch (error) { node = null }
|
|
@@ -440,17 +609,47 @@ export function uploadScript(target, file) {
|
|
|
440
609
|
return JSON.stringify({ ok: true, name: blob.name, size: blob.size, files: node.files ? node.files.length : 0 })
|
|
441
610
|
})()`;
|
|
442
611
|
}
|
|
612
|
+
/**
|
|
613
|
+
* What an action changed on the page that the URL does not show: the title, visible alert regions
|
|
614
|
+
* and the dialogs the probe answered. Read before and after each action for the post-action line.
|
|
615
|
+
* It never installs the probe, so observing an action leaves the page as it was.
|
|
616
|
+
*/
|
|
617
|
+
const PULSE_SCRIPT = `(() => {
|
|
618
|
+
const probe = globalThis[${JSON.stringify(PROBE_KEY)}]
|
|
619
|
+
const alerts = []
|
|
620
|
+
try {
|
|
621
|
+
for (const node of Array.from(document.querySelectorAll('[role=alert], [role=alertdialog], [aria-live=assertive]')).slice(0, 20)) {
|
|
622
|
+
const text = String(node.innerText || '').replace(/\\s+/g, ' ').trim().slice(0, 160)
|
|
623
|
+
if (text !== '' && node.getClientRects().length > 0 && alerts.indexOf(text) === -1) alerts.push(text)
|
|
624
|
+
if (alerts.length >= 5) break
|
|
625
|
+
}
|
|
626
|
+
} catch (error) { /* a document without a body still has a title */ }
|
|
627
|
+
const dialogs = probe && Array.isArray(probe.dialogs)
|
|
628
|
+
? probe.dialogs.slice(-5).map(entry => ({ at: entry.at, kind: entry.kind, message: String(entry.message).slice(0, 160), answered: entry.answered }))
|
|
629
|
+
: []
|
|
630
|
+
return JSON.stringify({ title: String(document.title || ''), alerts: alerts, dialogs: dialogs, probe: probe ? Number(probe.startedAt) || 0 : 0 })
|
|
631
|
+
})()`;
|
|
632
|
+
/** A fetch from the page, so it carries the page's same-origin cookies. The body comes back as text. */
|
|
633
|
+
function fetchScript(url, init) {
|
|
634
|
+
return `(async () => {
|
|
635
|
+
const response = await fetch(new URL(${JSON.stringify(url)}, document.baseURI).href, Object.assign({ credentials: 'same-origin' }, ${JSON.stringify(init)}))
|
|
636
|
+
const body = await response.text()
|
|
637
|
+
return JSON.stringify({ ok: response.ok, status: response.status, statusText: response.statusText, url: response.url, type: response.headers.get('content-type') || '', body: body })
|
|
638
|
+
})()`;
|
|
639
|
+
}
|
|
443
640
|
/** Build a fixed page operation, rejecting unknown operations before any code runs. */
|
|
444
641
|
export function pageOperationScript(request) {
|
|
445
642
|
switch (request.operation) {
|
|
446
643
|
case 'install': return PROBE_INSTALL_SCRIPT;
|
|
447
644
|
case 'url': return 'JSON.stringify(location.href)';
|
|
645
|
+
case 'pulse': return PULSE_SCRIPT;
|
|
646
|
+
case 'fetch': return fetchScript(request.url, request.init);
|
|
448
647
|
case 'text': return 'JSON.stringify((document.body ? document.body.innerText : "").indexOf(' + JSON.stringify(request.text) + ') !== -1)';
|
|
449
648
|
case 'drag': return dragScript(request.from, request.to, request.steps);
|
|
450
649
|
case 'upload': return uploadScript(request.target, request.file);
|
|
451
650
|
case 'probe': {
|
|
452
651
|
const methods = ['read', 'clear', 'settle', 'find', 'overlayAt', 'summary',
|
|
453
|
-
'findText', 'hoverAt', 'setDialogPolicy', 'dialogStatus', 'networkCursor'];
|
|
652
|
+
'findText', 'hoverAt', 'setDialogPolicy', 'dialogStatus', 'networkCursor', 'dataSources'];
|
|
454
653
|
if (!methods.includes(request.method))
|
|
455
654
|
throw new Error('browser: unsupported fixed page operation');
|
|
456
655
|
return probeCallScript(request.method, request.args);
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @module dsh-builtin-browser/tool-browser/panel-page
|
|
15
15
|
*/
|
|
16
|
+
import { GUEST_ROUTE } from '../../assets/browser-policy.mjs';
|
|
16
17
|
/** Decode the handful of entities that matter for labels. */
|
|
17
18
|
function decodeEntities(raw) {
|
|
18
19
|
return raw
|
|
@@ -49,7 +50,7 @@ function attribute(tag, name) {
|
|
|
49
50
|
*/
|
|
50
51
|
export async function readPanelPage(pageUrl, origin, options = {}) {
|
|
51
52
|
const limit = options.limit ?? 120;
|
|
52
|
-
const proxied = `${origin}
|
|
53
|
+
const proxied = `${origin}${GUEST_ROUTE}?u=${encodeURIComponent(pageUrl)}`;
|
|
53
54
|
const response = await fetch(proxied, {
|
|
54
55
|
headers: {
|
|
55
56
|
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page-side probe client: fingerprints, observed effects, the installed probe, polling, and checks.
|
|
3
|
+
* @module dsh-browser/tool-browser/probe-client
|
|
4
|
+
*/
|
|
5
|
+
import { pageOperationScript } from './page-probe.js';
|
|
6
|
+
import { CURSOR_ID } from '../browser-electron/virtual-cursor.js';
|
|
7
|
+
export const effectProperties = {
|
|
8
|
+
verified: { type: 'boolean', description: 'Whether a visible change was observed. Absent when it could not be checked.' },
|
|
9
|
+
note: { type: 'string', description: 'Why the effect is uncertain.' },
|
|
10
|
+
};
|
|
11
|
+
export async function pageFingerprint(browser, session) {
|
|
12
|
+
try {
|
|
13
|
+
const result = await browser.execute(session, {
|
|
14
|
+
script: `(() => {
|
|
15
|
+
const a = document.activeElement
|
|
16
|
+
const b = document.body
|
|
17
|
+
const c = typeof document.getElementById === 'function' ? document.getElementById(${JSON.stringify(CURSOR_ID)}) : null
|
|
18
|
+
const own = b && c && c.parentNode === b ? c : null
|
|
19
|
+
return JSON.stringify([
|
|
20
|
+
location.href, document.title,
|
|
21
|
+
a ? [a.tagName, a.id || a.getAttribute('name') || a.className || '',
|
|
22
|
+
typeof a.value === 'string' ? a.value.length : null, a.checked, a.selectedIndex,
|
|
23
|
+
a.selectionStart, a.selectionEnd, a.scrollLeft, a.scrollTop] : null,
|
|
24
|
+
window.scrollX, window.scrollY,
|
|
25
|
+
b ? b.childElementCount - (own ? 1 : 0) : 0,
|
|
26
|
+
b ? b.innerHTML.length - (own ? own.outerHTML.length : 0) : 0,
|
|
27
|
+
])
|
|
28
|
+
})()`,
|
|
29
|
+
});
|
|
30
|
+
return result.ok && typeof result.value === 'string' ? result.value : undefined;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export async function observedEffect(browser, session, before) {
|
|
37
|
+
const after = await pageFingerprint(browser, session);
|
|
38
|
+
if (before === undefined || after === undefined)
|
|
39
|
+
return { note: 'The effect could not be checked.' };
|
|
40
|
+
return before !== after
|
|
41
|
+
? { verified: true }
|
|
42
|
+
: { verified: false, note: 'No visible change observed; the effect is uncertain.' };
|
|
43
|
+
}
|
|
44
|
+
export function effectText(value) {
|
|
45
|
+
return value.verified === true ? ' Visible change observed.' : ` ${value.note ?? 'The effect could not be checked.'}`;
|
|
46
|
+
}
|
|
47
|
+
/** Run a script in the page and return its value as text. */
|
|
48
|
+
export async function pageValue(browser, session, script, signal) {
|
|
49
|
+
const result = await browser.execute(session, { script }, signal);
|
|
50
|
+
if (!result.ok)
|
|
51
|
+
throw new Error(`page script failed: ${result.exception}`);
|
|
52
|
+
const raw = result.value;
|
|
53
|
+
return typeof raw === 'string' ? raw : JSON.stringify(raw ?? null);
|
|
54
|
+
}
|
|
55
|
+
/** Fixed operations keep their inputs as data and preserve arbitrary-script permissions. */
|
|
56
|
+
export async function pageOperationValue(browser, session, request, signal) {
|
|
57
|
+
const result = typeof browser.pageOperation === 'function'
|
|
58
|
+
? await browser.pageOperation(session, request, signal)
|
|
59
|
+
: await browser.execute(session, { script: pageOperationScript(request) }, signal);
|
|
60
|
+
if (!result.ok)
|
|
61
|
+
throw new Error('page operation failed: ' + result.exception);
|
|
62
|
+
return typeof result.value === 'string' ? result.value : JSON.stringify(result.value ?? null);
|
|
63
|
+
}
|
|
64
|
+
/** Install the fixed probe and report page failures immediately. */
|
|
65
|
+
export async function installProbe(browser, session, signal) {
|
|
66
|
+
await pageOperationValue(browser, session, { operation: 'install' }, signal);
|
|
67
|
+
}
|
|
68
|
+
/** One probe call, parsed. Throws when the probe is absent or the call failed. */
|
|
69
|
+
export async function probe(browser, session, method, args = [], signal) {
|
|
70
|
+
const text = await pageOperationValue(browser, session, { operation: 'probe', method, args }, signal);
|
|
71
|
+
let parsed;
|
|
72
|
+
try {
|
|
73
|
+
parsed = JSON.parse(text);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
throw new Error(`page probe returned unreadable JSON: ${text.slice(0, 120)}`);
|
|
77
|
+
}
|
|
78
|
+
if (parsed !== null && typeof parsed === 'object' && 'error' in parsed) {
|
|
79
|
+
throw new Error(`page probe: ${String(parsed.error)}`);
|
|
80
|
+
}
|
|
81
|
+
return parsed;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* A probe call that survives a navigation inside a batch.
|
|
85
|
+
*
|
|
86
|
+
* Submitting a form replaces the document, and the probe with it, so a later step in the same
|
|
87
|
+
* batch would fail with `probe-not-installed` — measured on the first real benchmark run. One
|
|
88
|
+
* reinstall and one retry is enough: a second failure is a real absence, not a stale context.
|
|
89
|
+
*/
|
|
90
|
+
export async function probeLive(browser, session, method, args = [], signal) {
|
|
91
|
+
try {
|
|
92
|
+
return await probe(browser, session, method, args, signal);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (!/probe-not-installed|probe-method-missing/.test(String(error)))
|
|
96
|
+
throw error;
|
|
97
|
+
await installProbe(browser, session, signal);
|
|
98
|
+
return await probe(browser, session, method, args, signal);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Sleep. Long waits are capped by the caller, and the tool timeout still applies. */
|
|
102
|
+
export async function pause(ms) {
|
|
103
|
+
await new Promise(resolve => { setTimeout(resolve, ms); });
|
|
104
|
+
}
|
|
105
|
+
/** Poll until the callback returns something, or the budget runs out. */
|
|
106
|
+
export async function poll(check, budgetMs, intervalMs = 200) {
|
|
107
|
+
const deadline = Date.now() + budgetMs;
|
|
108
|
+
for (;;) {
|
|
109
|
+
const value = await check();
|
|
110
|
+
if (value !== undefined)
|
|
111
|
+
return value;
|
|
112
|
+
const left = deadline - Date.now();
|
|
113
|
+
if (left <= 0)
|
|
114
|
+
return undefined;
|
|
115
|
+
// Timers may fire a millisecond before `Date.now()` reaches the deadline; the pause that
|
|
116
|
+
// reaches it is the last one, so it is followed by exactly one final check.
|
|
117
|
+
if (left <= intervalMs) {
|
|
118
|
+
await pause(left);
|
|
119
|
+
return await check();
|
|
120
|
+
}
|
|
121
|
+
await pause(intervalMs);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Run one `dsh_browser_check` specification against the page.
|
|
126
|
+
*
|
|
127
|
+
* Shared by the `check` tool and by the `{check: …}` step of `dsh_browser_do`, so a batch asserts
|
|
128
|
+
* exactly what a standalone call asserts.
|
|
129
|
+
*/
|
|
130
|
+
export async function runChecks(browser, session, spec, signal) {
|
|
131
|
+
const checks = [];
|
|
132
|
+
if (spec.selector !== undefined) {
|
|
133
|
+
const found = await probeLive(browser, session, 'find', [{ css: spec.selector }], signal);
|
|
134
|
+
checks.push({ kind: 'selector', expected: spec.selector, actual: found === null ? 'not found' : String(found.described ?? 'found'), pass: found !== null });
|
|
135
|
+
}
|
|
136
|
+
if (spec.text !== undefined) {
|
|
137
|
+
const present = await pageOperationValue(browser, session, { operation: 'text', text: spec.text }, signal);
|
|
138
|
+
const ok = present === 'true';
|
|
139
|
+
checks.push({ kind: 'text', expected: spec.text, actual: ok ? 'present' : 'absent', pass: ok });
|
|
140
|
+
}
|
|
141
|
+
if (spec.url !== undefined) {
|
|
142
|
+
const href = await pageOperationValue(browser, session, { operation: 'url' }, signal).then(text => text.replace(/^"|"$/g, ''));
|
|
143
|
+
const ok = href.includes(spec.url);
|
|
144
|
+
checks.push({ kind: 'url', expected: spec.url, actual: href, pass: ok });
|
|
145
|
+
}
|
|
146
|
+
if (spec.js !== undefined) {
|
|
147
|
+
try {
|
|
148
|
+
const value = await pageValue(browser, session, `(() => { try { return JSON.stringify({ ok: !!(${spec.js}) }) } catch (error) { return JSON.stringify({ ok: false, error: String(error) }) } })()`, signal);
|
|
149
|
+
const parsed = JSON.parse(value);
|
|
150
|
+
checks.push({ kind: 'js', expected: spec.js, actual: parsed.ok === true ? 'truthy' : (parsed.error ?? 'falsy'), pass: parsed.ok === true });
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
checks.push({ kind: 'js', expected: spec.js, actual: String(error), pass: false });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return { pass: checks.length > 0 && checks.every(check => check.pass), checks };
|
|
157
|
+
}
|