@zyro-sec/gui-plugins 0.0.0-stage → 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/AGENTS.md +116 -0
- package/README.md +874 -3
- package/bunfig.toml +3 -0
- package/happydom.ts +77 -0
- package/package.json +63 -4
- package/src/browser/activation-delay.ts +134 -0
- package/src/browser/address-machine.ts +468 -0
- package/src/browser/address.ts +111 -0
- package/src/browser/agent-rendering.ts +61 -0
- package/src/browser/analysis.ts +260 -0
- package/src/browser/artifact-link.ts +69 -0
- package/src/browser/artifact-links.ts +55 -0
- package/src/browser/artifact-preview.ts +61 -0
- package/src/browser/assets/viewport-device-chevron.svg +5 -0
- package/src/browser/assets/viewport-rotate.svg +7 -0
- package/src/browser/bar.css +562 -0
- package/src/browser/capture.ts +158 -0
- package/src/browser/cdp.ts +97 -0
- package/src/browser/child-targets.ts +30 -0
- package/src/browser/choices.tsx +42 -0
- package/src/browser/chromium.ts +3018 -0
- package/src/browser/comment.css +38 -0
- package/src/browser/comment.ts +98 -0
- package/src/browser/connection.ts +122 -0
- package/src/browser/default-browser.ts +59 -0
- package/src/browser/diagnostics-machine.ts +522 -0
- package/src/browser/diagnostics.ts +317 -0
- package/src/browser/dialog-machine.ts +268 -0
- package/src/browser/disk/contained-file.ts +43 -0
- package/src/browser/disk/handle-path.fixture.ts +99 -0
- package/src/browser/disk/handle-path.ts +122 -0
- package/src/browser/disk/index.ts +5 -0
- package/src/browser/disk/preview-scope.ts +90 -0
- package/src/browser/electron-address.fixture.ts +143 -0
- package/src/browser/electron-app-badge.fixture.ts +97 -0
- package/src/browser/electron-crash.fixture.ts +216 -0
- package/src/browser/electron-dialogs.fixture.ts +114 -0
- package/src/browser/electron-history.fixture.ts +61 -0
- package/src/browser/electron-icon.fixture.ts +145 -0
- package/src/browser/electron-import-choice.fixture.ts +58 -0
- package/src/browser/electron-links.fixture.ts +549 -0
- package/src/browser/electron-main.ts +85 -0
- package/src/browser/electron-media.fixture.ts +66 -0
- package/src/browser/electron-open.fixture.ts +351 -0
- package/src/browser/electron-page.fixture.ts +253 -0
- package/src/browser/electron-restore.fixture.ts +135 -0
- package/src/browser/electron-run.ts +184 -0
- package/src/browser/electron-sign-in-copy.fixture.ts +365 -0
- package/src/browser/electron-webauthn.fixture.ts +229 -0
- package/src/browser/electron-workers.fixture.ts +54 -0
- package/src/browser/errors.ts +175 -0
- package/src/browser/failure-view.tsx +92 -0
- package/src/browser/failure.ts +174 -0
- package/src/browser/field-value.ts +60 -0
- package/src/browser/file-choosers.ts +42 -0
- package/src/browser/file-verification.ts +18 -0
- package/src/browser/files.ts +134 -0
- package/src/browser/find-bar.tsx +80 -0
- package/src/browser/find-machine.ts +43 -0
- package/src/browser/history/earlier.ts +23 -0
- package/src/browser/history/index.ts +5 -0
- package/src/browser/history/ipc.ts +44 -0
- package/src/browser/history/match.ts +196 -0
- package/src/browser/history/page.ts +86 -0
- package/src/browser/history/search.ts +209 -0
- package/src/browser/history/store.ts +272 -0
- package/src/browser/history/suggest.ts +51 -0
- package/src/browser/history/visits.ts +59 -0
- package/src/browser/host-display.ts +32 -0
- package/src/browser/i18n/am.ts +42 -0
- package/src/browser/i18n/ar.ts +46 -0
- package/src/browser/i18n/az.ts +42 -0
- package/src/browser/i18n/bg.ts +42 -0
- package/src/browser/i18n/bn.ts +42 -0
- package/src/browser/i18n/br.ts +44 -0
- package/src/browser/i18n/bs.ts +43 -0
- package/src/browser/i18n/ca.ts +44 -0
- package/src/browser/i18n/cs.ts +44 -0
- package/src/browser/i18n/da.ts +42 -0
- package/src/browser/i18n/de.ts +43 -0
- package/src/browser/i18n/dv.ts +43 -0
- package/src/browser/i18n/dz.ts +42 -0
- package/src/browser/i18n/el.ts +44 -0
- package/src/browser/i18n/en.ts +455 -0
- package/src/browser/i18n/es.ts +44 -0
- package/src/browser/i18n/et.ts +42 -0
- package/src/browser/i18n/fa.ts +42 -0
- package/src/browser/i18n/fi.ts +42 -0
- package/src/browser/i18n/fo.ts +42 -0
- package/src/browser/i18n/fr.ts +45 -0
- package/src/browser/i18n/he.ts +43 -0
- package/src/browser/i18n/hi.ts +42 -0
- package/src/browser/i18n/hr.ts +43 -0
- package/src/browser/i18n/hu.ts +43 -0
- package/src/browser/i18n/hy.ts +42 -0
- package/src/browser/i18n/id.ts +42 -0
- package/src/browser/i18n/is.ts +42 -0
- package/src/browser/i18n/it.ts +44 -0
- package/src/browser/i18n/ja.ts +42 -0
- package/src/browser/i18n/ka.ts +42 -0
- package/src/browser/i18n/km.ts +42 -0
- package/src/browser/i18n/ko.ts +42 -0
- package/src/browser/i18n/lo.ts +42 -0
- package/src/browser/i18n/lt.ts +44 -0
- package/src/browser/i18n/lv.ts +43 -0
- package/src/browser/i18n/mk.ts +42 -0
- package/src/browser/i18n/mn.ts +42 -0
- package/src/browser/i18n/ms.ts +42 -0
- package/src/browser/i18n/my.ts +43 -0
- package/src/browser/i18n/ne.ts +42 -0
- package/src/browser/i18n/nl.ts +42 -0
- package/src/browser/i18n/no.ts +42 -0
- package/src/browser/i18n/pa.ts +42 -0
- package/src/browser/i18n/pl.ts +44 -0
- package/src/browser/i18n/ro.ts +43 -0
- package/src/browser/i18n/ru.ts +44 -0
- package/src/browser/i18n/si.ts +42 -0
- package/src/browser/i18n/sk.ts +44 -0
- package/src/browser/i18n/sl.ts +44 -0
- package/src/browser/i18n/sq.ts +43 -0
- package/src/browser/i18n/sr.ts +43 -0
- package/src/browser/i18n/sv.ts +42 -0
- package/src/browser/i18n/tg.ts +42 -0
- package/src/browser/i18n/th.ts +42 -0
- package/src/browser/i18n/tk.ts +42 -0
- package/src/browser/i18n/tr.ts +42 -0
- package/src/browser/i18n/uk.ts +44 -0
- package/src/browser/i18n/ur.ts +42 -0
- package/src/browser/i18n/uz.ts +42 -0
- package/src/browser/i18n/vi.ts +42 -0
- package/src/browser/i18n/zh.ts +42 -0
- package/src/browser/i18n/zht.ts +42 -0
- package/src/browser/icon-image.ts +110 -0
- package/src/browser/icon-samples.ts +110 -0
- package/src/browser/icon.ts +72 -0
- package/src/browser/import-prompt.tsx +265 -0
- package/src/browser/index.ts +97 -0
- package/src/browser/ipc.ts +304 -0
- package/src/browser/jobs-machine.ts +181 -0
- package/src/browser/jobs.ts +373 -0
- package/src/browser/keys.ts +109 -0
- package/src/browser/lighthouse.ts +103 -0
- package/src/browser/link.ts +19 -0
- package/src/browser/machine.ts +1522 -0
- package/src/browser/main-machine.ts +99 -0
- package/src/browser/main.ts +394 -0
- package/src/browser/media-gate.ts +131 -0
- package/src/browser/mobile-emulation.ts +121 -0
- package/src/browser/model-machine.ts +93 -0
- package/src/browser/model.ts +1173 -0
- package/src/browser/native-page-menu.ts +189 -0
- package/src/browser/navigation-deadline.ts +20 -0
- package/src/browser/navigation-turn.ts +118 -0
- package/src/browser/network.ts +140 -0
- package/src/browser/notice-actions.ts +52 -0
- package/src/browser/overlay-machine.ts +330 -0
- package/src/browser/page-find.ts +71 -0
- package/src/browser/page-icon.tsx +27 -0
- package/src/browser/page-log.ts +276 -0
- package/src/browser/page-machine.ts +329 -0
- package/src/browser/page-menu.ts +158 -0
- package/src/browser/page-prompts.ts +753 -0
- package/src/browser/pane-machine.ts +664 -0
- package/src/browser/pane.ts +1335 -0
- package/src/browser/panel.fixture.tsx +2046 -0
- package/src/browser/panel.stories.tsx +147 -0
- package/src/browser/panel.tsx +2029 -0
- package/src/browser/passkey-groups.ts +34 -0
- package/src/browser/picker-machine.ts +214 -0
- package/src/browser/plugin-tabs.ts +26 -0
- package/src/browser/policy.ts +439 -0
- package/src/browser/preview.ts +40 -0
- package/src/browser/profile/chromium.ts +198 -0
- package/src/browser/profile/compatibility.ts +177 -0
- package/src/browser/profile/cookie.ts +215 -0
- package/src/browser/profile/database.ts +116 -0
- package/src/browser/profile/electron-import.fixture.ts +43 -0
- package/src/browser/profile/electron-link.fixture.ts +137 -0
- package/src/browser/profile/extension-api/action.ts +276 -0
- package/src/browser/profile/extension-api/api.ts +112 -0
- package/src/browser/profile/extension-api/app-badge.js +19 -0
- package/src/browser/profile/extension-api/context-menus.ts +327 -0
- package/src/browser/profile/extension-api/cookies.ts +192 -0
- package/src/browser/profile/extension-api/event-page.ts +73 -0
- package/src/browser/profile/extension-api/frame-styles.js +46 -0
- package/src/browser/profile/extension-api/host.ts +291 -0
- package/src/browser/profile/extension-api/index.ts +119 -0
- package/src/browser/profile/extension-api/label.ts +4 -0
- package/src/browser/profile/extension-api/manifest.ts +76 -0
- package/src/browser/profile/extension-api/match-pattern.ts +98 -0
- package/src/browser/profile/extension-api/notifications.ts +100 -0
- package/src/browser/profile/extension-api/permissions.ts +51 -0
- package/src/browser/profile/extension-api/popup.ts +200 -0
- package/src/browser/profile/extension-api/preload.js +203 -0
- package/src/browser/profile/extension-api/resource.ts +36 -0
- package/src/browser/profile/extension-api/storage-sync.ts +167 -0
- package/src/browser/profile/extension-api/stubs.ts +152 -0
- package/src/browser/profile/extension-api/styles.ts +230 -0
- package/src/browser/profile/extension-api/tab-activity.ts +23 -0
- package/src/browser/profile/extension-api/tabs.ts +545 -0
- package/src/browser/profile/extension-api/web-navigation.ts +172 -0
- package/src/browser/profile/extension-api/worker-events.ts +114 -0
- package/src/browser/profile/extensions.ts +491 -0
- package/src/browser/profile/filter-startup.fixture.ts +111 -0
- package/src/browser/profile/filter-startup.ts +178 -0
- package/src/browser/profile/firefox.ts +119 -0
- package/src/browser/profile/history.ts +146 -0
- package/src/browser/profile/import.ts +37 -0
- package/src/browser/profile/index.ts +694 -0
- package/src/browser/profile/install.ts +131 -0
- package/src/browser/profile/integrity.ts +56 -0
- package/src/browser/profile/ipc.ts +306 -0
- package/src/browser/profile/link-machine.ts +183 -0
- package/src/browser/profile/link.ts +335 -0
- package/src/browser/profile/made-up-firefox.fixture.ts +67 -0
- package/src/browser/profile/previews.ts +70 -0
- package/src/browser/profile/probe.ts +43 -0
- package/src/browser/profile/range.ts +14 -0
- package/src/browser/profile/review.ts +38 -0
- package/src/browser/profile/safari.ts +77 -0
- package/src/browser/profile/serve.ts +117 -0
- package/src/browser/profile/sites.ts +74 -0
- package/src/browser/profile/sources.ts +682 -0
- package/src/browser/profiling-machine.ts +554 -0
- package/src/browser/profiling.ts +404 -0
- package/src/browser/prompt-gate.ts +41 -0
- package/src/browser/prompt-keys.ts +120 -0
- package/src/browser/prompt-machine.ts +242 -0
- package/src/browser/prompts.tsx +594 -0
- package/src/browser/refs.ts +65 -0
- package/src/browser/refusal-bar.tsx +163 -0
- package/src/browser/refusal-notice.ts +60 -0
- package/src/browser/remote-address.ts +1 -0
- package/src/browser/remote-preview.ts +56 -0
- package/src/browser/renderer.tsx +683 -0
- package/src/browser/restore.ts +77 -0
- package/src/browser/saved-tabs.ts +135 -0
- package/src/browser/scheme.ts +1 -0
- package/src/browser/session-guard.ts +94 -0
- package/src/browser/settings-view.ts +49 -0
- package/src/browser/settings.fixture.tsx +306 -0
- package/src/browser/settings.tsx +1036 -0
- package/src/browser/site-auth.ts +58 -0
- package/src/browser/site-chooser.fixture.tsx +222 -0
- package/src/browser/site-chooser.tsx +778 -0
- package/src/browser/site-keys.ts +35 -0
- package/src/browser/site-machine.ts +134 -0
- package/src/browser/site-permissions.ts +239 -0
- package/src/browser/site-search.ts +26 -0
- package/src/browser/snapshot.ts +440 -0
- package/src/browser/system-media.ts +80 -0
- package/src/browser/tab-openers.ts +65 -0
- package/src/browser/tabs.css +20 -0
- package/src/browser/viewport-controls-machine.ts +134 -0
- package/src/browser/viewport-controls.tsx +170 -0
- package/src/browser/viewport-handles.tsx +119 -0
- package/src/browser/viewport-layout.ts +24 -0
- package/src/browser/viewport-native.ts +99 -0
- package/src/browser/viewport-preset-menu.tsx +69 -0
- package/src/browser/viewport-presets.ts +28 -0
- package/src/browser/viewport-toolbar-machine.ts +94 -0
- package/src/browser/webauthn-gate.ts +222 -0
- package/src/browser/window-open.ts +143 -0
- package/src/browser/wire.ts +20 -0
- package/src/browser/workspace-file.ts +126 -0
- package/src/browser/workspace-pages.ts +156 -0
- package/src/btw/i18n/en.ts +12 -0
- package/src/btw/index.ts +31 -0
- package/src/btw/machine.ts +341 -0
- package/src/btw/model.ts +222 -0
- package/src/btw/panel.tsx +229 -0
- package/src/btw/renderer.tsx +125 -0
- package/src/context/catalog-machine.ts +153 -0
- package/src/context/catalog.ts +123 -0
- package/src/context/export.ts +57 -0
- package/src/context/format.ts +32 -0
- package/src/context/i18n/am.ts +31 -0
- package/src/context/i18n/ar.ts +31 -0
- package/src/context/i18n/az.ts +31 -0
- package/src/context/i18n/bg.ts +31 -0
- package/src/context/i18n/bn.ts +31 -0
- package/src/context/i18n/br.ts +31 -0
- package/src/context/i18n/bs.ts +31 -0
- package/src/context/i18n/ca.ts +31 -0
- package/src/context/i18n/cs.ts +31 -0
- package/src/context/i18n/da.ts +31 -0
- package/src/context/i18n/de.ts +31 -0
- package/src/context/i18n/dv.ts +31 -0
- package/src/context/i18n/dz.ts +31 -0
- package/src/context/i18n/el.ts +31 -0
- package/src/context/i18n/en.ts +31 -0
- package/src/context/i18n/es.ts +31 -0
- package/src/context/i18n/et.ts +31 -0
- package/src/context/i18n/fa.ts +31 -0
- package/src/context/i18n/fi.ts +31 -0
- package/src/context/i18n/fo.ts +31 -0
- package/src/context/i18n/fr.ts +31 -0
- package/src/context/i18n/he.ts +31 -0
- package/src/context/i18n/hi.ts +31 -0
- package/src/context/i18n/hr.ts +31 -0
- package/src/context/i18n/hu.ts +31 -0
- package/src/context/i18n/hy.ts +31 -0
- package/src/context/i18n/id.ts +31 -0
- package/src/context/i18n/is.ts +31 -0
- package/src/context/i18n/it.ts +31 -0
- package/src/context/i18n/ja.ts +31 -0
- package/src/context/i18n/ka.ts +31 -0
- package/src/context/i18n/km.ts +31 -0
- package/src/context/i18n/ko.ts +31 -0
- package/src/context/i18n/lo.ts +31 -0
- package/src/context/i18n/lt.ts +31 -0
- package/src/context/i18n/lv.ts +31 -0
- package/src/context/i18n/mk.ts +31 -0
- package/src/context/i18n/mn.ts +31 -0
- package/src/context/i18n/ms.ts +31 -0
- package/src/context/i18n/my.ts +31 -0
- package/src/context/i18n/ne.ts +31 -0
- package/src/context/i18n/nl.ts +31 -0
- package/src/context/i18n/no.ts +31 -0
- package/src/context/i18n/pa.ts +31 -0
- package/src/context/i18n/pl.ts +31 -0
- package/src/context/i18n/ro.ts +31 -0
- package/src/context/i18n/ru.ts +31 -0
- package/src/context/i18n/si.ts +31 -0
- package/src/context/i18n/sk.ts +31 -0
- package/src/context/i18n/sl.ts +31 -0
- package/src/context/i18n/sq.ts +31 -0
- package/src/context/i18n/sr.ts +31 -0
- package/src/context/i18n/sv.ts +31 -0
- package/src/context/i18n/tg.ts +31 -0
- package/src/context/i18n/th.ts +31 -0
- package/src/context/i18n/tk.ts +31 -0
- package/src/context/i18n/tr.ts +31 -0
- package/src/context/i18n/uk.ts +31 -0
- package/src/context/i18n/ur.ts +31 -0
- package/src/context/i18n/uz.ts +31 -0
- package/src/context/i18n/vi.ts +31 -0
- package/src/context/i18n/zh.ts +31 -0
- package/src/context/i18n/zht.ts +31 -0
- package/src/context/index.ts +71 -0
- package/src/context/indicator.tsx +199 -0
- package/src/context/machine.ts +271 -0
- package/src/context/renderer.tsx +72 -0
- package/src/context/tab.tsx +439 -0
- package/src/debug/bar.tsx +409 -0
- package/src/debug/contract.ts +45 -0
- package/src/debug/focus-machine.ts +84 -0
- package/src/debug/heap-machine.ts +229 -0
- package/src/debug/i18n/am.ts +50 -0
- package/src/debug/i18n/ar.ts +50 -0
- package/src/debug/i18n/az.ts +50 -0
- package/src/debug/i18n/bg.ts +53 -0
- package/src/debug/i18n/bn.ts +50 -0
- package/src/debug/i18n/br.ts +51 -0
- package/src/debug/i18n/bs.ts +52 -0
- package/src/debug/i18n/ca.ts +53 -0
- package/src/debug/i18n/cs.ts +52 -0
- package/src/debug/i18n/da.ts +51 -0
- package/src/debug/i18n/de.ts +50 -0
- package/src/debug/i18n/dv.ts +51 -0
- package/src/debug/i18n/dz.ts +52 -0
- package/src/debug/i18n/el.ts +54 -0
- package/src/debug/i18n/en.ts +50 -0
- package/src/debug/i18n/es.ts +52 -0
- package/src/debug/i18n/et.ts +50 -0
- package/src/debug/i18n/fa.ts +50 -0
- package/src/debug/i18n/fi.ts +50 -0
- package/src/debug/i18n/fo.ts +50 -0
- package/src/debug/i18n/fr.ts +52 -0
- package/src/debug/i18n/he.ts +50 -0
- package/src/debug/i18n/hi.ts +50 -0
- package/src/debug/i18n/hr.ts +52 -0
- package/src/debug/i18n/hu.ts +52 -0
- package/src/debug/i18n/hy.ts +52 -0
- package/src/debug/i18n/id.ts +51 -0
- package/src/debug/i18n/is.ts +50 -0
- package/src/debug/i18n/it.ts +52 -0
- package/src/debug/i18n/ja.ts +50 -0
- package/src/debug/i18n/ka.ts +50 -0
- package/src/debug/i18n/km.ts +50 -0
- package/src/debug/i18n/ko.ts +50 -0
- package/src/debug/i18n/lo.ts +50 -0
- package/src/debug/i18n/lt.ts +51 -0
- package/src/debug/i18n/lv.ts +50 -0
- package/src/debug/i18n/mk.ts +53 -0
- package/src/debug/i18n/mn.ts +52 -0
- package/src/debug/i18n/ms.ts +51 -0
- package/src/debug/i18n/my.ts +53 -0
- package/src/debug/i18n/ne.ts +50 -0
- package/src/debug/i18n/nl.ts +50 -0
- package/src/debug/i18n/no.ts +50 -0
- package/src/debug/i18n/pa.ts +50 -0
- package/src/debug/i18n/pl.ts +51 -0
- package/src/debug/i18n/ro.ts +52 -0
- package/src/debug/i18n/ru.ts +51 -0
- package/src/debug/i18n/si.ts +50 -0
- package/src/debug/i18n/sk.ts +52 -0
- package/src/debug/i18n/sl.ts +50 -0
- package/src/debug/i18n/sq.ts +52 -0
- package/src/debug/i18n/sr.ts +52 -0
- package/src/debug/i18n/sv.ts +51 -0
- package/src/debug/i18n/tg.ts +51 -0
- package/src/debug/i18n/th.ts +50 -0
- package/src/debug/i18n/tk.ts +51 -0
- package/src/debug/i18n/tr.ts +50 -0
- package/src/debug/i18n/uk.ts +50 -0
- package/src/debug/i18n/ur.ts +50 -0
- package/src/debug/i18n/uz.ts +51 -0
- package/src/debug/i18n/vi.ts +51 -0
- package/src/debug/i18n/zh.ts +49 -0
- package/src/debug/i18n/zht.ts +50 -0
- package/src/debug/index.ts +79 -0
- package/src/debug/main.ts +417 -0
- package/src/debug/memory-infra.ts +159 -0
- package/src/debug/memory-log.ts +65 -0
- package/src/debug/memory-machine.ts +151 -0
- package/src/debug/memory-record.ts +36 -0
- package/src/debug/motion-machine.ts +229 -0
- package/src/debug/motion.tsx +697 -0
- package/src/debug/options.ts +15 -0
- package/src/debug/renderer.tsx +185 -0
- package/src/debug/server-heap.ts +63 -0
- package/src/debug/signal.ts +13 -0
- package/src/details/config-action-machine.ts +107 -0
- package/src/details/config-file.ts +43 -0
- package/src/details/details.css +555 -0
- package/src/details/flyout-machine.ts +252 -0
- package/src/details/flyout-motion.ts +26 -0
- package/src/details/i18n/am.ts +68 -0
- package/src/details/i18n/ar.ts +71 -0
- package/src/details/i18n/az.ts +71 -0
- package/src/details/i18n/bg.ts +73 -0
- package/src/details/i18n/bn.ts +71 -0
- package/src/details/i18n/br.ts +71 -0
- package/src/details/i18n/bs.ts +72 -0
- package/src/details/i18n/ca.ts +72 -0
- package/src/details/i18n/cs.ts +71 -0
- package/src/details/i18n/da.ts +71 -0
- package/src/details/i18n/de.ts +73 -0
- package/src/details/i18n/dv.ts +73 -0
- package/src/details/i18n/dz.ts +72 -0
- package/src/details/i18n/el.ts +73 -0
- package/src/details/i18n/en.ts +71 -0
- package/src/details/i18n/es.ts +72 -0
- package/src/details/i18n/et.ts +72 -0
- package/src/details/i18n/fa.ts +71 -0
- package/src/details/i18n/fi.ts +71 -0
- package/src/details/i18n/fo.ts +72 -0
- package/src/details/i18n/fr.ts +73 -0
- package/src/details/i18n/he.ts +71 -0
- package/src/details/i18n/hi.ts +71 -0
- package/src/details/i18n/hr.ts +72 -0
- package/src/details/i18n/hu.ts +72 -0
- package/src/details/i18n/hy.ts +72 -0
- package/src/details/i18n/id.ts +71 -0
- package/src/details/i18n/is.ts +71 -0
- package/src/details/i18n/it.ts +73 -0
- package/src/details/i18n/ja.ts +71 -0
- package/src/details/i18n/ka.ts +72 -0
- package/src/details/i18n/km.ts +72 -0
- package/src/details/i18n/ko.ts +71 -0
- package/src/details/i18n/lo.ts +72 -0
- package/src/details/i18n/lt.ts +72 -0
- package/src/details/i18n/lv.ts +72 -0
- package/src/details/i18n/mk.ts +73 -0
- package/src/details/i18n/mn.ts +71 -0
- package/src/details/i18n/ms.ts +71 -0
- package/src/details/i18n/my.ts +72 -0
- package/src/details/i18n/ne.ts +71 -0
- package/src/details/i18n/nl.ts +71 -0
- package/src/details/i18n/no.ts +71 -0
- package/src/details/i18n/pa.ts +71 -0
- package/src/details/i18n/pl.ts +72 -0
- package/src/details/i18n/ro.ts +72 -0
- package/src/details/i18n/ru.ts +72 -0
- package/src/details/i18n/si.ts +71 -0
- package/src/details/i18n/sk.ts +71 -0
- package/src/details/i18n/sl.ts +73 -0
- package/src/details/i18n/sq.ts +71 -0
- package/src/details/i18n/sr.ts +72 -0
- package/src/details/i18n/sv.ts +72 -0
- package/src/details/i18n/tg.ts +71 -0
- package/src/details/i18n/th.ts +72 -0
- package/src/details/i18n/tk.ts +72 -0
- package/src/details/i18n/tr.ts +71 -0
- package/src/details/i18n/uk.ts +71 -0
- package/src/details/i18n/ur.ts +71 -0
- package/src/details/i18n/uz.ts +72 -0
- package/src/details/i18n/vi.ts +71 -0
- package/src/details/i18n/zh.ts +69 -0
- package/src/details/i18n/zht.ts +70 -0
- package/src/details/index.ts +71 -0
- package/src/details/location-menu.tsx +82 -0
- package/src/details/location-workspace.tsx +39 -0
- package/src/details/mcp-machine.ts +278 -0
- package/src/details/panel.tsx +27 -0
- package/src/details/paths.ts +17 -0
- package/src/details/popover-machine.ts +97 -0
- package/src/details/popover.tsx +179 -0
- package/src/details/renderer.tsx +99 -0
- package/src/details/server-panel.tsx +1632 -0
- package/src/details/service-load-machine.ts +246 -0
- package/src/details/workspace-menu.tsx +490 -0
- package/src/details/workspace-move-machine.ts +643 -0
- package/src/file/apps.ts +25 -0
- package/src/file/arrival-guard-machine.ts +59 -0
- package/src/file/artifact-toolbar.tsx +161 -0
- package/src/file/artifact-view-machine.ts +396 -0
- package/src/file/artifact-view.css +336 -0
- package/src/file/artifact-view.tsx +1031 -0
- package/src/file/artifact.ts +225 -0
- package/src/file/browser.stories.tsx +57 -0
- package/src/file/browser.tsx +502 -0
- package/src/file/context.ts +67 -0
- package/src/file/contract.ts +10 -0
- package/src/file/drag.ts +35 -0
- package/src/file/find.tsx +376 -0
- package/src/file/i18n/am.ts +56 -0
- package/src/file/i18n/ar.ts +64 -0
- package/src/file/i18n/az.ts +56 -0
- package/src/file/i18n/bg.ts +56 -0
- package/src/file/i18n/bn.ts +56 -0
- package/src/file/i18n/br.ts +58 -0
- package/src/file/i18n/bs.ts +58 -0
- package/src/file/i18n/ca.ts +58 -0
- package/src/file/i18n/cs.ts +60 -0
- package/src/file/i18n/da.ts +56 -0
- package/src/file/i18n/de.ts +56 -0
- package/src/file/i18n/dv.ts +56 -0
- package/src/file/i18n/dz.ts +56 -0
- package/src/file/i18n/el.ts +56 -0
- package/src/file/i18n/en.ts +63 -0
- package/src/file/i18n/es.ts +58 -0
- package/src/file/i18n/et.ts +56 -0
- package/src/file/i18n/fa.ts +56 -0
- package/src/file/i18n/fi.ts +56 -0
- package/src/file/i18n/fo.ts +56 -0
- package/src/file/i18n/fr.ts +58 -0
- package/src/file/i18n/he.ts +58 -0
- package/src/file/i18n/hi.ts +56 -0
- package/src/file/i18n/hr.ts +58 -0
- package/src/file/i18n/hu.ts +56 -0
- package/src/file/i18n/hy.ts +56 -0
- package/src/file/i18n/id.ts +56 -0
- package/src/file/i18n/is.ts +56 -0
- package/src/file/i18n/it.ts +58 -0
- package/src/file/i18n/ja.ts +56 -0
- package/src/file/i18n/ka.ts +56 -0
- package/src/file/i18n/km.ts +56 -0
- package/src/file/i18n/ko.ts +56 -0
- package/src/file/i18n/lo.ts +56 -0
- package/src/file/i18n/lt.ts +60 -0
- package/src/file/i18n/lv.ts +58 -0
- package/src/file/i18n/mk.ts +56 -0
- package/src/file/i18n/mn.ts +56 -0
- package/src/file/i18n/ms.ts +56 -0
- package/src/file/i18n/my.ts +56 -0
- package/src/file/i18n/ne.ts +56 -0
- package/src/file/i18n/nl.ts +56 -0
- package/src/file/i18n/no.ts +56 -0
- package/src/file/i18n/pa.ts +56 -0
- package/src/file/i18n/pl.ts +60 -0
- package/src/file/i18n/ro.ts +58 -0
- package/src/file/i18n/ru.ts +60 -0
- package/src/file/i18n/si.ts +56 -0
- package/src/file/i18n/sk.ts +60 -0
- package/src/file/i18n/sl.ts +60 -0
- package/src/file/i18n/sq.ts +56 -0
- package/src/file/i18n/sr.ts +58 -0
- package/src/file/i18n/sv.ts +56 -0
- package/src/file/i18n/tg.ts +56 -0
- package/src/file/i18n/th.ts +56 -0
- package/src/file/i18n/tk.ts +56 -0
- package/src/file/i18n/tr.ts +56 -0
- package/src/file/i18n/uk.ts +60 -0
- package/src/file/i18n/ur.ts +57 -0
- package/src/file/i18n/uz.ts +56 -0
- package/src/file/i18n/vi.ts +56 -0
- package/src/file/i18n/zh.ts +56 -0
- package/src/file/i18n/zht.ts +56 -0
- package/src/file/index.ts +76 -0
- package/src/file/label.tsx +22 -0
- package/src/file/link-exists-machine.ts +137 -0
- package/src/file/link-open-machine.ts +249 -0
- package/src/file/list.tsx +224 -0
- package/src/file/mobile.css +35 -0
- package/src/file/mobile.tsx +116 -0
- package/src/file/open-in-app-machine.ts +185 -0
- package/src/file/open-in-app.tsx +395 -0
- package/src/file/path.ts +43 -0
- package/src/file/picker-machine.ts +190 -0
- package/src/file/pierre-tree-machine.ts +679 -0
- package/src/file/pierre-tree.tsx +503 -0
- package/src/file/renderer.tsx +1030 -0
- package/src/file/resolve-link.ts +152 -0
- package/src/file/scroll-machine.ts +272 -0
- package/src/file/search-machine.ts +202 -0
- package/src/file/styles.ts +5 -0
- package/src/file/tabs.css +15 -0
- package/src/file/tree-focus.css +6 -0
- package/src/file/tree-model.ts +239 -0
- package/src/file/view.tsx +572 -0
- package/src/goal/goal.css +43 -0
- package/src/goal/i18n/en.ts +12 -0
- package/src/goal/icons/active.svg +13 -0
- package/src/goal/icons/complete.svg +4 -0
- package/src/goal/icons/paused.svg +4 -0
- package/src/goal/index.ts +9 -0
- package/src/goal/machine.ts +364 -0
- package/src/goal/renderer.tsx +287 -0
- package/src/icon-name.typecheck.ts +9 -0
- package/src/main.ts +35 -0
- package/src/microsoft-office/document.tsx +436 -0
- package/src/microsoft-office/document.worker.ts +360 -0
- package/src/microsoft-office/fonts-cjk.ts +3 -0
- package/src/microsoft-office/fonts.ts +75 -0
- package/src/microsoft-office/i18n/en.ts +22 -0
- package/src/microsoft-office/index.ts +7 -0
- package/src/microsoft-office/links.ts +22 -0
- package/src/microsoft-office/office-worker.ts +124 -0
- package/src/microsoft-office/pages-machine.ts +356 -0
- package/src/microsoft-office/pages.tsx +387 -0
- package/src/microsoft-office/paper.ts +2 -0
- package/src/microsoft-office/presentation.tsx +303 -0
- package/src/microsoft-office/presentation.worker.ts +373 -0
- package/src/microsoft-office/renderer.tsx +57 -0
- package/src/microsoft-office/sheet-activate.ts +35 -0
- package/src/microsoft-office/sheet-cells.ts +188 -0
- package/src/microsoft-office/sheet-frame-machine.ts +286 -0
- package/src/microsoft-office/sheet-frame.ts +158 -0
- package/src/microsoft-office/sheet-paint.ts +357 -0
- package/src/microsoft-office/sheet-pick-machine.ts +138 -0
- package/src/microsoft-office/sheet-pointer-machine.ts +169 -0
- package/src/microsoft-office/sheet-protocol.ts +88 -0
- package/src/microsoft-office/slide-fonts-machine.ts +290 -0
- package/src/microsoft-office/slide-fonts.ts +157 -0
- package/src/microsoft-office/slide-paint-machine.ts +322 -0
- package/src/microsoft-office/slide-protocol.ts +50 -0
- package/src/microsoft-office/slide-text.ts +334 -0
- package/src/microsoft-office/spreadsheet.tsx +1165 -0
- package/src/microsoft-office/spreadsheet.worker.ts +259 -0
- package/src/microsoft-office/word-images.ts +105 -0
- package/src/microsoft-office/word-layout-machine.ts +219 -0
- package/src/microsoft-office/word-paint-machine.ts +174 -0
- package/src/microsoft-office/word-protocol.ts +78 -0
- package/src/microsoft-office/word-text.ts +260 -0
- package/src/microsoft-office/worker-machine.ts +111 -0
- package/src/microsoft-office/worker-rpc-machine.ts +336 -0
- package/src/microsoft-office/worker-rpc.fixture.ts +90 -0
- package/src/microsoft-office/worker-rpc.ts +292 -0
- package/src/pairing/contract.ts +24 -0
- package/src/pairing/copy-machine.ts +107 -0
- package/src/pairing/dialog.stories.tsx +69 -0
- package/src/pairing/dispatch.ts +42 -0
- package/src/pairing/i18n/en.ts +28 -0
- package/src/pairing/icons/pair.svg +4 -0
- package/src/pairing/index.ts +5 -0
- package/src/pairing/machine.ts +869 -0
- package/src/pairing/main-machine.ts +239 -0
- package/src/pairing/main.ts +130 -0
- package/src/pairing/page.stories.tsx +108 -0
- package/src/pairing/page.tsx +486 -0
- package/src/pairing/remote.ts +7 -0
- package/src/pairing/renderer.tsx +66 -0
- package/src/renderer.ts +55 -0
- package/src/review/contract.ts +31 -0
- package/src/review/detail-machine.ts +250 -0
- package/src/review/folder-machine.ts +404 -0
- package/src/review/i18n/am.ts +23 -0
- package/src/review/i18n/ar.ts +35 -0
- package/src/review/i18n/az.ts +23 -0
- package/src/review/i18n/bg.ts +23 -0
- package/src/review/i18n/bn.ts +23 -0
- package/src/review/i18n/br.ts +27 -0
- package/src/review/i18n/bs.ts +26 -0
- package/src/review/i18n/ca.ts +27 -0
- package/src/review/i18n/cs.ts +29 -0
- package/src/review/i18n/da.ts +23 -0
- package/src/review/i18n/de.ts +23 -0
- package/src/review/i18n/dv.ts +24 -0
- package/src/review/i18n/dz.ts +24 -0
- package/src/review/i18n/el.ts +23 -0
- package/src/review/i18n/en.ts +28 -0
- package/src/review/i18n/es.ts +27 -0
- package/src/review/i18n/et.ts +23 -0
- package/src/review/i18n/fa.ts +23 -0
- package/src/review/i18n/fi.ts +23 -0
- package/src/review/i18n/fo.ts +23 -0
- package/src/review/i18n/fr.ts +27 -0
- package/src/review/i18n/he.ts +26 -0
- package/src/review/i18n/hi.ts +23 -0
- package/src/review/i18n/hr.ts +26 -0
- package/src/review/i18n/hu.ts +23 -0
- package/src/review/i18n/hy.ts +23 -0
- package/src/review/i18n/id.ts +24 -0
- package/src/review/i18n/is.ts +23 -0
- package/src/review/i18n/it.ts +27 -0
- package/src/review/i18n/ja.ts +23 -0
- package/src/review/i18n/ka.ts +23 -0
- package/src/review/i18n/km.ts +23 -0
- package/src/review/i18n/ko.ts +23 -0
- package/src/review/i18n/lo.ts +23 -0
- package/src/review/i18n/lt.ts +29 -0
- package/src/review/i18n/lv.ts +26 -0
- package/src/review/i18n/mk.ts +23 -0
- package/src/review/i18n/mn.ts +23 -0
- package/src/review/i18n/ms.ts +24 -0
- package/src/review/i18n/my.ts +24 -0
- package/src/review/i18n/ne.ts +23 -0
- package/src/review/i18n/nl.ts +23 -0
- package/src/review/i18n/no.ts +23 -0
- package/src/review/i18n/pa.ts +23 -0
- package/src/review/i18n/pl.ts +29 -0
- package/src/review/i18n/ro.ts +26 -0
- package/src/review/i18n/ru.ts +29 -0
- package/src/review/i18n/si.ts +23 -0
- package/src/review/i18n/sk.ts +29 -0
- package/src/review/i18n/sl.ts +29 -0
- package/src/review/i18n/sq.ts +24 -0
- package/src/review/i18n/sr.ts +27 -0
- package/src/review/i18n/sv.ts +23 -0
- package/src/review/i18n/tg.ts +23 -0
- package/src/review/i18n/th.ts +23 -0
- package/src/review/i18n/tk.ts +23 -0
- package/src/review/i18n/tr.ts +23 -0
- package/src/review/i18n/uk.ts +30 -0
- package/src/review/i18n/ur.ts +23 -0
- package/src/review/i18n/uz.ts +23 -0
- package/src/review/i18n/vi.ts +24 -0
- package/src/review/i18n/zh.ts +23 -0
- package/src/review/i18n/zht.ts +23 -0
- package/src/review/index.ts +138 -0
- package/src/review/init-git-machine.ts +152 -0
- package/src/review/kinds.ts +191 -0
- package/src/review/machine.ts +274 -0
- package/src/review/mobile.tsx +91 -0
- package/src/review/model.ts +1123 -0
- package/src/review/panel.stories.tsx +50 -0
- package/src/review/panel.tsx +516 -0
- package/src/review/parts.tsx +141 -0
- package/src/review/render-machine.ts +74 -0
- package/src/review/renderer.tsx +403 -0
- package/src/review/screen-machine.ts +199 -0
- package/src/review/scroll-machine.ts +265 -0
- package/src/review/settings.tsx +28 -0
- package/src/schemes.ts +9 -0
- package/src/sources/i18n/en.ts +3 -0
- package/src/sources/index.ts +4 -0
- package/src/sources/panel.tsx +36 -0
- package/src/sources/renderer.tsx +95 -0
- package/src/ssh/add-machine.ts +63 -0
- package/src/ssh/askpass.ts +94 -0
- package/src/ssh/bootstrap.ts +160 -0
- package/src/ssh/command.ts +243 -0
- package/src/ssh/contract.ts +89 -0
- package/src/ssh/controller.ts +345 -0
- package/src/ssh/cover.tsx +66 -0
- package/src/ssh/dialog-machine.ts +249 -0
- package/src/ssh/dialog.stories.tsx +348 -0
- package/src/ssh/dialog.tsx +236 -0
- package/src/ssh/i18n/am.ts +37 -0
- package/src/ssh/i18n/ar.ts +38 -0
- package/src/ssh/i18n/az.ts +43 -0
- package/src/ssh/i18n/bg.ts +42 -0
- package/src/ssh/i18n/bn.ts +41 -0
- package/src/ssh/i18n/br.ts +43 -0
- package/src/ssh/i18n/bs.ts +43 -0
- package/src/ssh/i18n/ca.ts +43 -0
- package/src/ssh/i18n/cs.ts +43 -0
- package/src/ssh/i18n/da.ts +43 -0
- package/src/ssh/i18n/de.ts +44 -0
- package/src/ssh/i18n/dv.ts +43 -0
- package/src/ssh/i18n/dz.ts +43 -0
- package/src/ssh/i18n/el.ts +45 -0
- package/src/ssh/i18n/en.ts +40 -0
- package/src/ssh/i18n/es.ts +43 -0
- package/src/ssh/i18n/et.ts +41 -0
- package/src/ssh/i18n/fa.ts +39 -0
- package/src/ssh/i18n/fi.ts +40 -0
- package/src/ssh/i18n/fo.ts +41 -0
- package/src/ssh/i18n/fr.ts +43 -0
- package/src/ssh/i18n/he.ts +37 -0
- package/src/ssh/i18n/hi.ts +40 -0
- package/src/ssh/i18n/hr.ts +43 -0
- package/src/ssh/i18n/hu.ts +43 -0
- package/src/ssh/i18n/hy.ts +41 -0
- package/src/ssh/i18n/id.ts +42 -0
- package/src/ssh/i18n/is.ts +40 -0
- package/src/ssh/i18n/it.ts +43 -0
- package/src/ssh/i18n/ja.ts +43 -0
- package/src/ssh/i18n/ka.ts +43 -0
- package/src/ssh/i18n/km.ts +41 -0
- package/src/ssh/i18n/ko.ts +40 -0
- package/src/ssh/i18n/lo.ts +39 -0
- package/src/ssh/i18n/lt.ts +41 -0
- package/src/ssh/i18n/lv.ts +42 -0
- package/src/ssh/i18n/mk.ts +43 -0
- package/src/ssh/i18n/mn.ts +41 -0
- package/src/ssh/i18n/ms.ts +40 -0
- package/src/ssh/i18n/my.ts +41 -0
- package/src/ssh/i18n/ne.ts +39 -0
- package/src/ssh/i18n/nl.ts +43 -0
- package/src/ssh/i18n/no.ts +42 -0
- package/src/ssh/i18n/pa.ts +40 -0
- package/src/ssh/i18n/pl.ts +42 -0
- package/src/ssh/i18n/ro.ts +44 -0
- package/src/ssh/i18n/ru.ts +42 -0
- package/src/ssh/i18n/si.ts +41 -0
- package/src/ssh/i18n/sk.ts +42 -0
- package/src/ssh/i18n/sl.ts +41 -0
- package/src/ssh/i18n/sq.ts +43 -0
- package/src/ssh/i18n/sr.ts +41 -0
- package/src/ssh/i18n/sv.ts +43 -0
- package/src/ssh/i18n/tg.ts +43 -0
- package/src/ssh/i18n/th.ts +38 -0
- package/src/ssh/i18n/tk.ts +41 -0
- package/src/ssh/i18n/tr.ts +42 -0
- package/src/ssh/i18n/uk.ts +40 -0
- package/src/ssh/i18n/ur.ts +40 -0
- package/src/ssh/i18n/uz.ts +43 -0
- package/src/ssh/i18n/vi.ts +42 -0
- package/src/ssh/i18n/zh.ts +36 -0
- package/src/ssh/i18n/zht.ts +36 -0
- package/src/ssh/index.ts +71 -0
- package/src/ssh/main-machine.ts +532 -0
- package/src/ssh/main.ts +75 -0
- package/src/ssh/name.ts +28 -0
- package/src/ssh/remote-cli.ts +137 -0
- package/src/ssh/renderer.tsx +254 -0
- package/src/ssh/row.tsx +97 -0
- package/src/ssh/ssh.css +35 -0
- package/src/ssh/state.ts +217 -0
- package/src/ssh/window-machine.ts +533 -0
- package/src/terminal/connection-machine.ts +285 -0
- package/src/terminal/connection.ts +112 -0
- package/src/terminal/dispatch.ts +44 -0
- package/src/terminal/focus-machine.ts +112 -0
- package/src/terminal/focus.ts +23 -0
- package/src/terminal/hover-label.ts +20 -0
- package/src/terminal/i18n/am.ts +28 -0
- package/src/terminal/i18n/ar.ts +28 -0
- package/src/terminal/i18n/az.ts +29 -0
- package/src/terminal/i18n/bg.ts +29 -0
- package/src/terminal/i18n/bn.ts +28 -0
- package/src/terminal/i18n/br.ts +29 -0
- package/src/terminal/i18n/bs.ts +29 -0
- package/src/terminal/i18n/ca.ts +28 -0
- package/src/terminal/i18n/cs.ts +28 -0
- package/src/terminal/i18n/da.ts +28 -0
- package/src/terminal/i18n/de.ts +29 -0
- package/src/terminal/i18n/dv.ts +28 -0
- package/src/terminal/i18n/dz.ts +28 -0
- package/src/terminal/i18n/el.ts +30 -0
- package/src/terminal/i18n/en.ts +30 -0
- package/src/terminal/i18n/es.ts +28 -0
- package/src/terminal/i18n/et.ts +28 -0
- package/src/terminal/i18n/fa.ts +28 -0
- package/src/terminal/i18n/fi.ts +29 -0
- package/src/terminal/i18n/fo.ts +28 -0
- package/src/terminal/i18n/fr.ts +29 -0
- package/src/terminal/i18n/he.ts +28 -0
- package/src/terminal/i18n/hi.ts +28 -0
- package/src/terminal/i18n/hr.ts +28 -0
- package/src/terminal/i18n/hu.ts +28 -0
- package/src/terminal/i18n/hy.ts +29 -0
- package/src/terminal/i18n/id.ts +28 -0
- package/src/terminal/i18n/is.ts +28 -0
- package/src/terminal/i18n/it.ts +28 -0
- package/src/terminal/i18n/ja.ts +29 -0
- package/src/terminal/i18n/ka.ts +29 -0
- package/src/terminal/i18n/km.ts +28 -0
- package/src/terminal/i18n/ko.ts +28 -0
- package/src/terminal/i18n/lo.ts +28 -0
- package/src/terminal/i18n/lt.ts +29 -0
- package/src/terminal/i18n/lv.ts +28 -0
- package/src/terminal/i18n/mk.ts +29 -0
- package/src/terminal/i18n/mn.ts +30 -0
- package/src/terminal/i18n/ms.ts +28 -0
- package/src/terminal/i18n/my.ts +29 -0
- package/src/terminal/i18n/ne.ts +28 -0
- package/src/terminal/i18n/nl.ts +28 -0
- package/src/terminal/i18n/no.ts +28 -0
- package/src/terminal/i18n/pa.ts +28 -0
- package/src/terminal/i18n/pl.ts +28 -0
- package/src/terminal/i18n/ro.ts +28 -0
- package/src/terminal/i18n/ru.ts +28 -0
- package/src/terminal/i18n/si.ts +28 -0
- package/src/terminal/i18n/sk.ts +28 -0
- package/src/terminal/i18n/sl.ts +28 -0
- package/src/terminal/i18n/sq.ts +29 -0
- package/src/terminal/i18n/sr.ts +28 -0
- package/src/terminal/i18n/sv.ts +28 -0
- package/src/terminal/i18n/tg.ts +29 -0
- package/src/terminal/i18n/th.ts +28 -0
- package/src/terminal/i18n/tk.ts +29 -0
- package/src/terminal/i18n/tr.ts +29 -0
- package/src/terminal/i18n/uk.ts +28 -0
- package/src/terminal/i18n/ur.ts +28 -0
- package/src/terminal/i18n/uz.ts +29 -0
- package/src/terminal/i18n/vi.ts +28 -0
- package/src/terminal/i18n/zh.ts +28 -0
- package/src/terminal/i18n/zht.ts +28 -0
- package/src/terminal/index.ts +74 -0
- package/src/terminal/inline-rename.ts +93 -0
- package/src/terminal/label.tsx +71 -0
- package/src/terminal/machine.ts +767 -0
- package/src/terminal/model.ts +661 -0
- package/src/terminal/pane-machine.ts +260 -0
- package/src/terminal/panel.tsx +280 -0
- package/src/terminal/props.ts +16 -0
- package/src/terminal/quote-machine.ts +381 -0
- package/src/terminal/quote.css +7 -0
- package/src/terminal/quote.tsx +218 -0
- package/src/terminal/rename-machine.ts +98 -0
- package/src/terminal/renderer.tsx +298 -0
- package/src/terminal/runtime-adapters.ts +34 -0
- package/src/terminal/surface-machine.ts +186 -0
- package/src/terminal/tab.tsx +112 -0
- package/src/terminal/terminal-key-event.ts +58 -0
- package/src/terminal/terminal.fixture.tsx +71 -0
- package/src/terminal/terminal.tsx +652 -0
- package/src/terminal/title.ts +41 -0
- package/src/terminal/writer.ts +87 -0
- package/src/updater/action.ts +37 -0
- package/src/updater/actions.tsx +110 -0
- package/src/updater/i18n/am.ts +40 -0
- package/src/updater/i18n/ar.ts +40 -0
- package/src/updater/i18n/az.ts +41 -0
- package/src/updater/i18n/bg.ts +40 -0
- package/src/updater/i18n/bn.ts +41 -0
- package/src/updater/i18n/br.ts +40 -0
- package/src/updater/i18n/bs.ts +41 -0
- package/src/updater/i18n/ca.ts +41 -0
- package/src/updater/i18n/cs.ts +41 -0
- package/src/updater/i18n/da.ts +40 -0
- package/src/updater/i18n/de.ts +41 -0
- package/src/updater/i18n/dv.ts +41 -0
- package/src/updater/i18n/dz.ts +42 -0
- package/src/updater/i18n/el.ts +42 -0
- package/src/updater/i18n/en.ts +42 -0
- package/src/updater/i18n/es.ts +40 -0
- package/src/updater/i18n/et.ts +40 -0
- package/src/updater/i18n/fa.ts +40 -0
- package/src/updater/i18n/fi.ts +41 -0
- package/src/updater/i18n/fo.ts +40 -0
- package/src/updater/i18n/fr.ts +41 -0
- package/src/updater/i18n/he.ts +40 -0
- package/src/updater/i18n/hi.ts +40 -0
- package/src/updater/i18n/hr.ts +41 -0
- package/src/updater/i18n/hu.ts +40 -0
- package/src/updater/i18n/hy.ts +41 -0
- package/src/updater/i18n/id.ts +41 -0
- package/src/updater/i18n/is.ts +40 -0
- package/src/updater/i18n/it.ts +40 -0
- package/src/updater/i18n/ja.ts +41 -0
- package/src/updater/i18n/ka.ts +40 -0
- package/src/updater/i18n/km.ts +40 -0
- package/src/updater/i18n/ko.ts +40 -0
- package/src/updater/i18n/lo.ts +40 -0
- package/src/updater/i18n/lt.ts +41 -0
- package/src/updater/i18n/lv.ts +40 -0
- package/src/updater/i18n/mk.ts +41 -0
- package/src/updater/i18n/mn.ts +40 -0
- package/src/updater/i18n/ms.ts +41 -0
- package/src/updater/i18n/my.ts +40 -0
- package/src/updater/i18n/ne.ts +40 -0
- package/src/updater/i18n/nl.ts +41 -0
- package/src/updater/i18n/no.ts +40 -0
- package/src/updater/i18n/pa.ts +40 -0
- package/src/updater/i18n/pl.ts +41 -0
- package/src/updater/i18n/ro.ts +41 -0
- package/src/updater/i18n/ru.ts +40 -0
- package/src/updater/i18n/si.ts +40 -0
- package/src/updater/i18n/sk.ts +41 -0
- package/src/updater/i18n/sl.ts +40 -0
- package/src/updater/i18n/sq.ts +40 -0
- package/src/updater/i18n/sr.ts +41 -0
- package/src/updater/i18n/sv.ts +40 -0
- package/src/updater/i18n/tg.ts +41 -0
- package/src/updater/i18n/th.ts +40 -0
- package/src/updater/i18n/tk.ts +40 -0
- package/src/updater/i18n/tr.ts +40 -0
- package/src/updater/i18n/uk.ts +40 -0
- package/src/updater/i18n/ur.ts +40 -0
- package/src/updater/i18n/uz.ts +41 -0
- package/src/updater/i18n/vi.ts +41 -0
- package/src/updater/i18n/zh.ts +40 -0
- package/src/updater/i18n/zht.ts +40 -0
- package/src/updater/index.ts +94 -0
- package/src/updater/log.ts +41 -0
- package/src/updater/machine.ts +919 -0
- package/src/updater/main.ts +138 -0
- package/src/updater/platform.ts +160 -0
- package/src/updater/renderer.tsx +203 -0
- package/src/updater/section.tsx +65 -0
- package/src/updater/web-driver.ts +200 -0
- package/src/updater/web-machine.ts +222 -0
- package/src/updater/web.tsx +103 -0
- package/src/updater/whats-new-machine.ts +97 -0
- package/src/updater/whats-new.stories.tsx +38 -0
- package/src/updater/whats-new.tsx +304 -0
- package/src/updater/window-machine.ts +73 -0
- package/src/wsl/add-machine.ts +56 -0
- package/src/wsl/contract.ts +104 -0
- package/src/wsl/dialog-machine.ts +322 -0
- package/src/wsl/dialog.css +372 -0
- package/src/wsl/dialog.tsx +492 -0
- package/src/wsl/i18n/am.ts +53 -0
- package/src/wsl/i18n/ar.ts +55 -0
- package/src/wsl/i18n/az.ts +57 -0
- package/src/wsl/i18n/bg.ts +58 -0
- package/src/wsl/i18n/bn.ts +56 -0
- package/src/wsl/i18n/br.ts +58 -0
- package/src/wsl/i18n/bs.ts +58 -0
- package/src/wsl/i18n/ca.ts +58 -0
- package/src/wsl/i18n/cs.ts +57 -0
- package/src/wsl/i18n/da.ts +57 -0
- package/src/wsl/i18n/de.ts +59 -0
- package/src/wsl/i18n/dv.ts +58 -0
- package/src/wsl/i18n/dz.ts +59 -0
- package/src/wsl/i18n/el.ts +57 -0
- package/src/wsl/i18n/en.ts +55 -0
- package/src/wsl/i18n/es.ts +58 -0
- package/src/wsl/i18n/et.ts +55 -0
- package/src/wsl/i18n/fa.ts +56 -0
- package/src/wsl/i18n/fi.ts +57 -0
- package/src/wsl/i18n/fo.ts +56 -0
- package/src/wsl/i18n/fr.ts +57 -0
- package/src/wsl/i18n/he.ts +54 -0
- package/src/wsl/i18n/hi.ts +57 -0
- package/src/wsl/i18n/hr.ts +58 -0
- package/src/wsl/i18n/hu.ts +58 -0
- package/src/wsl/i18n/hy.ts +57 -0
- package/src/wsl/i18n/id.ts +56 -0
- package/src/wsl/i18n/is.ts +55 -0
- package/src/wsl/i18n/it.ts +57 -0
- package/src/wsl/i18n/ja.ts +57 -0
- package/src/wsl/i18n/ka.ts +56 -0
- package/src/wsl/i18n/km.ts +57 -0
- package/src/wsl/i18n/ko.ts +56 -0
- package/src/wsl/i18n/lo.ts +54 -0
- package/src/wsl/i18n/lt.ts +57 -0
- package/src/wsl/i18n/lv.ts +57 -0
- package/src/wsl/i18n/mk.ts +57 -0
- package/src/wsl/i18n/mn.ts +58 -0
- package/src/wsl/i18n/ms.ts +57 -0
- package/src/wsl/i18n/my.ts +57 -0
- package/src/wsl/i18n/ne.ts +57 -0
- package/src/wsl/i18n/nl.ts +57 -0
- package/src/wsl/i18n/no.ts +57 -0
- package/src/wsl/i18n/pa.ts +57 -0
- package/src/wsl/i18n/pl.ts +58 -0
- package/src/wsl/i18n/ro.ts +56 -0
- package/src/wsl/i18n/ru.ts +57 -0
- package/src/wsl/i18n/si.ts +56 -0
- package/src/wsl/i18n/sk.ts +57 -0
- package/src/wsl/i18n/sl.ts +57 -0
- package/src/wsl/i18n/sq.ts +56 -0
- package/src/wsl/i18n/sr.ts +57 -0
- package/src/wsl/i18n/sv.ts +58 -0
- package/src/wsl/i18n/tg.ts +57 -0
- package/src/wsl/i18n/th.ts +57 -0
- package/src/wsl/i18n/tk.ts +56 -0
- package/src/wsl/i18n/tr.ts +57 -0
- package/src/wsl/i18n/uk.ts +57 -0
- package/src/wsl/i18n/ur.ts +57 -0
- package/src/wsl/i18n/uz.ts +57 -0
- package/src/wsl/i18n/vi.ts +56 -0
- package/src/wsl/i18n/zh.ts +53 -0
- package/src/wsl/i18n/zht.ts +53 -0
- package/src/wsl/index.ts +72 -0
- package/src/wsl/local.ts +41 -0
- package/src/wsl/machine.ts +652 -0
- package/src/wsl/main.ts +95 -0
- package/src/wsl/model.ts +369 -0
- package/src/wsl/probe-machine.ts +143 -0
- package/src/wsl/probes.ts +107 -0
- package/src/wsl/remote-cli.ts +49 -0
- package/src/wsl/renderer.tsx +164 -0
- package/src/wsl/row-view.ts +25 -0
- package/src/wsl/row.tsx +76 -0
- package/src/wsl/runtime.ts +441 -0
- package/src/wsl/servers.ts +330 -0
- package/src/wsl/sidecar.ts +186 -0
- package/tsconfig.json +21 -0
|
@@ -0,0 +1,3018 @@
|
|
|
1
|
+
import { homedir } from "node:os"
|
|
2
|
+
import { scheduler } from "node:timers/promises"
|
|
3
|
+
import { navigationTurn, replacementNavigation } from "./navigation-turn"
|
|
4
|
+
import { accessibilitySnapshot } from "./snapshot"
|
|
5
|
+
import { documentRefs } from "./refs"
|
|
6
|
+
import { describeField, Field, readableField } from "./field-value"
|
|
7
|
+
import { agentRendering, needsWakeFrame } from "./agent-rendering"
|
|
8
|
+
import { extensionResource } from "./profile/extension-api/resource"
|
|
9
|
+
import { Browser } from "@zyro-sec/plugin-browser/rpc"
|
|
10
|
+
import electron, { type BrowserWindow, type WebContents } from "electron"
|
|
11
|
+
import type { Protocol } from "devtools-protocol"
|
|
12
|
+
import { Schema } from "effect"
|
|
13
|
+
import type { Embeds } from "@zyro-sec/plugin/gui/main"
|
|
14
|
+
import { captureCoordinator, captureScale, cropPixels, FULL_PAGE_DEADLINE_MS, jpegFits, pngFits, undrawable, undrawableMessage } from "./capture"
|
|
15
|
+
import { createCdp, abortError, waitFor } from "./cdp"
|
|
16
|
+
import { navigationDeadline } from "./navigation-deadline"
|
|
17
|
+
import { attachChildren, releaseWorker } from "./child-targets"
|
|
18
|
+
import { CodedError, missingArtifact, pageReports } from "./errors"
|
|
19
|
+
import { createBrowserFiles } from "./files"
|
|
20
|
+
import { guardFileChoosers } from "./file-choosers"
|
|
21
|
+
import { guardMediaRequests } from "./media-gate"
|
|
22
|
+
import { afterRefusal, agentPasskeyRefusal, guardWebAuthn } from "./webauthn-gate"
|
|
23
|
+
import { cookieSite } from "./profile/sites"
|
|
24
|
+
import { createDiagnostics } from "./diagnostics"
|
|
25
|
+
import { loadIcon } from "./icon"
|
|
26
|
+
import { agentKeyRefusal, hardwareInput, pageLetter, pageReload, pageShortcut, type PageShortcut } from "./keys"
|
|
27
|
+
import {
|
|
28
|
+
createDocumentState,
|
|
29
|
+
documentGeneration,
|
|
30
|
+
documentIcon,
|
|
31
|
+
documentTab,
|
|
32
|
+
frameStillCurrent,
|
|
33
|
+
isDocumentClosed,
|
|
34
|
+
isNavigationPending,
|
|
35
|
+
retryOnly,
|
|
36
|
+
transitionDocument,
|
|
37
|
+
type DocumentEvent,
|
|
38
|
+
} from "./page-machine"
|
|
39
|
+
import {
|
|
40
|
+
initialPickerState,
|
|
41
|
+
isPickerActive,
|
|
42
|
+
pickerAttempt,
|
|
43
|
+
PICKER_TIMEOUT_MS,
|
|
44
|
+
transitionPicker,
|
|
45
|
+
type PickerEffect,
|
|
46
|
+
type PickerEvent,
|
|
47
|
+
} from "./picker-machine"
|
|
48
|
+
import { createPageLog, processMemory, setupFailure, type PageEnd, type PageLogWrite } from "./page-log"
|
|
49
|
+
import { createProfiling } from "./profiling"
|
|
50
|
+
import type { SharedTrace } from "./profiling-machine"
|
|
51
|
+
import {
|
|
52
|
+
createDialogGateState,
|
|
53
|
+
selectDialog,
|
|
54
|
+
selectDialogTarget,
|
|
55
|
+
selectOpenDialog,
|
|
56
|
+
selectSuppressed,
|
|
57
|
+
selectUserDialog,
|
|
58
|
+
transitionDialogGate,
|
|
59
|
+
type DialogGateEvent,
|
|
60
|
+
type RunStopReason,
|
|
61
|
+
} from "./dialog-machine"
|
|
62
|
+
import type { BrowserNetwork } from "./network"
|
|
63
|
+
import {
|
|
64
|
+
agentFrame,
|
|
65
|
+
agentFrames,
|
|
66
|
+
agentDriven,
|
|
67
|
+
childActivity,
|
|
68
|
+
agentRefusal,
|
|
69
|
+
activityOwner,
|
|
70
|
+
recordPageInput,
|
|
71
|
+
allowedDestination,
|
|
72
|
+
committedLoad,
|
|
73
|
+
destinationOrigin,
|
|
74
|
+
downloadOwner,
|
|
75
|
+
excludedFrames,
|
|
76
|
+
inputDocument,
|
|
77
|
+
localFileURL,
|
|
78
|
+
normalizeURL,
|
|
79
|
+
type Policy,
|
|
80
|
+
type TabActivity,
|
|
81
|
+
} from "./policy"
|
|
82
|
+
import type { PaneElement, PaneEvent, PromptView, RefusalNotice, Viewport } from "./ipc"
|
|
83
|
+
import { createViewportWriter } from "./viewport-native"
|
|
84
|
+
import { createDeviceEmulation } from "./mobile-emulation"
|
|
85
|
+
import { navigationNotice } from "./refusal-notice"
|
|
86
|
+
import { noticeActions } from "./notice-actions"
|
|
87
|
+
import { attachPageMenu, type PageMenuHost } from "./native-page-menu"
|
|
88
|
+
import { reloadAddress } from "./preview"
|
|
89
|
+
import { pageHandoff } from "./address"
|
|
90
|
+
import { defaultBrowser } from "./default-browser"
|
|
91
|
+
import { FileVerificationError } from "./file-verification"
|
|
92
|
+
import type { workspacePages } from "./workspace-pages"
|
|
93
|
+
import { clickDisposition, closesUnshown, windowOpening, type Press, type Unshown } from "./window-open"
|
|
94
|
+
import { artifactLinks } from "./artifact-links"
|
|
95
|
+
import { createPagePrompts, RESTORE_PROMPT, takeDialogs } from "./page-prompts"
|
|
96
|
+
import type { SitePermissions } from "./site-permissions"
|
|
97
|
+
import type { SystemMedia } from "./system-media"
|
|
98
|
+
import { previewScheme } from "./scheme"
|
|
99
|
+
import type { WorkspaceSource } from "./workspace-file"
|
|
100
|
+
import type { artifactPages } from "./artifact-preview"
|
|
101
|
+
|
|
102
|
+
type Element = { backendID: number; frameID: string; sessionID?: string }
|
|
103
|
+
|
|
104
|
+
// A page can retain a removed node. Check in the same renderer call that reads or acts on the ref.
|
|
105
|
+
function connectedFunction(fn: string) {
|
|
106
|
+
return `function(...args) { if (!this.isConnected) throw new Error('browser.detached_ref'); return (${fn}\n).apply(this,args) }`
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function detachedRef() {
|
|
110
|
+
return new CodedError(Browser.FailureCode.staleRef, "Element is no longer connected. Take a fresh snapshot and choose a current ref.")
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const noVisibleArea = "Element has no visible screenshot area. Take a fresh snapshot and choose a visible element, or omit ref to capture the viewport."
|
|
114
|
+
|
|
115
|
+
/** State every page of the pane shares: the element ref allocator and the owner of the app-wide trace. */
|
|
116
|
+
export type Shared = { ref: () => string; trace?: SharedTrace }
|
|
117
|
+
|
|
118
|
+
// Captures and downloads belong to the tab, not whichever document it now shows; navigate replaces it anyway. A wait
|
|
119
|
+
// reads whichever document is current, often the one a click just navigated to.
|
|
120
|
+
const retainedOperations: readonly Browser.Method[] = [
|
|
121
|
+
"navigate",
|
|
122
|
+
"wait",
|
|
123
|
+
"files.list",
|
|
124
|
+
"files.get",
|
|
125
|
+
"trace.stop",
|
|
126
|
+
"trace.analyze",
|
|
127
|
+
"cpu.stop",
|
|
128
|
+
"cpu.analyze",
|
|
129
|
+
"heap.summary",
|
|
130
|
+
"heap.query",
|
|
131
|
+
"heap.object",
|
|
132
|
+
"heap.compare",
|
|
133
|
+
]
|
|
134
|
+
|
|
135
|
+
// The user's commands that leave the document, which a page's beforeunload may hold back for "Leave site?".
|
|
136
|
+
const leavable: readonly Browser.Method[] = ["navigate", "back", "forward", "reload"]
|
|
137
|
+
|
|
138
|
+
// Input the page receives while the element picker is on would pick an element instead.
|
|
139
|
+
const pointerOperations: readonly Browser.Method[] = [
|
|
140
|
+
"click",
|
|
141
|
+
"hover",
|
|
142
|
+
"drag",
|
|
143
|
+
"fill",
|
|
144
|
+
"fill_form",
|
|
145
|
+
"select",
|
|
146
|
+
"check",
|
|
147
|
+
"scroll",
|
|
148
|
+
"files.drop",
|
|
149
|
+
]
|
|
150
|
+
|
|
151
|
+
/** Virtual key codes of the named keys `press` accepts. */
|
|
152
|
+
interface KeyCodes {
|
|
153
|
+
readonly [key: string]: number
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Chromium DevTools' element picker colors, so the overlay matches the Elements panel.
|
|
157
|
+
const inspectHighlight: Protocol.Overlay.HighlightConfig = {
|
|
158
|
+
showInfo: true,
|
|
159
|
+
showStyles: true,
|
|
160
|
+
showAccessibilityInfo: true,
|
|
161
|
+
colorFormat: "hex",
|
|
162
|
+
contrastAlgorithm: "aa",
|
|
163
|
+
contentColor: { r: 111, g: 168, b: 220, a: 0.66 },
|
|
164
|
+
paddingColor: { r: 147, g: 196, b: 125, a: 0.55 },
|
|
165
|
+
borderColor: { r: 255, g: 229, b: 153, a: 0.66 },
|
|
166
|
+
marginColor: { r: 246, g: 178, b: 107, a: 0.66 },
|
|
167
|
+
eventTargetColor: { r: 255, g: 196, b: 196, a: 0.66 },
|
|
168
|
+
// SAFETY: CDP's Overlay.HighlightConfig names these two fields; they are the protocol's, not ours to rename.
|
|
169
|
+
/* oxlint-disable anti-slop/no-shape-in-symbol-names -- see SAFETY above */
|
|
170
|
+
shapeColor: { r: 96, g: 82, b: 177, a: 0.8 },
|
|
171
|
+
shapeMarginColor: { r: 96, g: 82, b: 127, a: 0.6 },
|
|
172
|
+
/* oxlint-enable anti-slop/no-shape-in-symbol-names */
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const pickedHighlight = { ...inspectHighlight, showInfo: false, showStyles: false, showAccessibilityInfo: false }
|
|
176
|
+
|
|
177
|
+
// Chromium rejects mode "none" without a config. A rejected call leaves the picker armed, and the
|
|
178
|
+
// next hideHighlight would put its hover tool back.
|
|
179
|
+
const inspectOff = { mode: "none", highlightConfig: inspectHighlight }
|
|
180
|
+
|
|
181
|
+
// Chromium's zoom presets, so a step lands where it would in the system browser.
|
|
182
|
+
const zoomSteps = [0.25, 0.33, 0.5, 0.67, 0.75, 0.8, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5]
|
|
183
|
+
|
|
184
|
+
export type PageDetail = Omit<Extract<PaneEvent, { type: "page" }>, "type" | "tabID">
|
|
185
|
+
|
|
186
|
+
/** The zoom a key press asks for: the system browser's zoom keys, with the platform's modifier already checked. */
|
|
187
|
+
function zoomKey(input: Electron.Input) {
|
|
188
|
+
if (input.key === "=" || input.key === "+" || input.code === "NumpadAdd") return "in"
|
|
189
|
+
|
|
190
|
+
if (input.key === "-" || input.code === "NumpadSubtract") return "out"
|
|
191
|
+
|
|
192
|
+
if (input.key === "0") return "reset"
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The address a cookie is removed by: its domain without the leading dot, its path, and its scheme. An IPv6 host
|
|
197
|
+
* needs its brackets in a URL.
|
|
198
|
+
*/
|
|
199
|
+
function cookieURL(cookie: Electron.Cookie) {
|
|
200
|
+
const domain = (cookie.domain ?? "").replace(/^\./, "")
|
|
201
|
+
const host = domain.includes(":") && !domain.startsWith("[") ? `[${domain}]` : domain
|
|
202
|
+
|
|
203
|
+
return `${cookie.secure ? "https" : "http"}://${host}${cookie.path ?? "/"}`
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The next preset in the direction, or 100%; the current factor at either end. */
|
|
207
|
+
function zoomStep(current: number, direction: "in" | "out" | "reset") {
|
|
208
|
+
if (direction === "reset") return 1
|
|
209
|
+
|
|
210
|
+
if (direction === "in") return zoomSteps.find((step) => step > current + 0.001) ?? current
|
|
211
|
+
|
|
212
|
+
return zoomSteps.findLast((step) => step < current - 0.001) ?? current
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Ends a running command's wait when it is interrupted. */
|
|
216
|
+
type Interrupted = ReturnType<typeof Promise.withResolvers<never>>
|
|
217
|
+
|
|
218
|
+
/** What a command that stopped, or never started, tells the agent. */
|
|
219
|
+
function runStopError(reason: RunStopReason) {
|
|
220
|
+
switch (reason) {
|
|
221
|
+
case "dialog-open":
|
|
222
|
+
return new Error(
|
|
223
|
+
'A JavaScript dialog is open. Inspect it with browser.dialog({tabID,action:"get"}), then explicitly accept or dismiss it before continuing.',
|
|
224
|
+
)
|
|
225
|
+
case "dialog-interrupted":
|
|
226
|
+
return new Error(
|
|
227
|
+
'A JavaScript dialog opened while the action was running. Inspect it with browser.dialog({tabID,action:"get"}) and accept or dismiss it. Do not repeat the original action just to close the dialog.',
|
|
228
|
+
)
|
|
229
|
+
case "cancelled":
|
|
230
|
+
return new Error(
|
|
231
|
+
"Browser operation was cancelled. Inspect the tab before deciding to repeat an action; cancellation does not undo changes already made.",
|
|
232
|
+
)
|
|
233
|
+
case "closed":
|
|
234
|
+
return new Error(
|
|
235
|
+
"Browser tab was closed. Call browser.tabs.list({}) and choose an existing tabID; do not reuse the closed tab's refs.",
|
|
236
|
+
)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export type BrowserPage = ReturnType<typeof createBrowserPage>
|
|
241
|
+
|
|
242
|
+
export function createBrowserPage(
|
|
243
|
+
win: BrowserWindow,
|
|
244
|
+
options: {
|
|
245
|
+
id: Browser.TabID
|
|
246
|
+
partition: string
|
|
247
|
+
network: BrowserNetwork | null
|
|
248
|
+
publish: (error?: string) => void
|
|
249
|
+
refused: (notice: RefusalNotice, token: string, site?: string) => void
|
|
250
|
+
/** Reports the element picker starting, stopping, or picking an element. */
|
|
251
|
+
inspect?: (event: { active: boolean; element?: PaneElement }) => void
|
|
252
|
+
/** Reports changes to the page's icon, zoom, or layout viewport. */
|
|
253
|
+
detail?: (detail: PageDetail) => void
|
|
254
|
+
/** The page's zoom changed, which Chromium applies to every page of the same origin in the partition. */
|
|
255
|
+
zoomed?: () => void
|
|
256
|
+
/** Whether the build offers the device toolbar, which owns ⇧⌘M. */
|
|
257
|
+
toolbar: boolean
|
|
258
|
+
/**
|
|
259
|
+
* How long a `navigate` command waits for its page to load before it stops waiting, while the page goes on
|
|
260
|
+
* loading. Defaults to `NAVIGATION_DEADLINE_MS`.
|
|
261
|
+
*/
|
|
262
|
+
navigationDeadlineMs?: number
|
|
263
|
+
/** Hands a browser or shell shortcut to the app window. */
|
|
264
|
+
shortcut?: (shortcut: PageShortcut) => void
|
|
265
|
+
/** The page took keyboard focus. */
|
|
266
|
+
focused?: () => void
|
|
267
|
+
/** The page left the screen: another tab or a preview took its place, or the pane closed. */
|
|
268
|
+
hidden?: () => void
|
|
269
|
+
/** The page stopped, for the reason given (page-log.ts); the window shows it as `page_crashed`. */
|
|
270
|
+
fail: (end: PageEnd) => void
|
|
271
|
+
/** Writes to the desktop log when the page ends, stalls or fails to load; without it nothing is logged. */
|
|
272
|
+
log?: PageLogWrite
|
|
273
|
+
/**
|
|
274
|
+
* Adopts a page the document opened; a background one leaves the current tab selected. `refused` shows this tab
|
|
275
|
+
* why an address could not open, for a link the new tab was opened for and hands back (`opened`).
|
|
276
|
+
*/
|
|
277
|
+
popup: (options: Electron.BrowserWindowConstructorOptions, background: boolean, activity: TabActivity, refused: (url: string) => void) => WebContents
|
|
278
|
+
activity: TabActivity
|
|
279
|
+
userInput: () => void
|
|
280
|
+
initialize?: boolean
|
|
281
|
+
restore?: Browser.Tab
|
|
282
|
+
popupOptions?: Electron.BrowserWindowConstructorOptions
|
|
283
|
+
/**
|
|
284
|
+
* A page opened this tab (`popup`). While it has shown no document, a first navigation that leaves it none ends it:
|
|
285
|
+
* `close` closes the tab, and `refused` shows the tab that opened it why the address could not open.
|
|
286
|
+
*/
|
|
287
|
+
opened?: { readonly close: () => void; readonly refused: (url: string) => void }
|
|
288
|
+
/** Directories whose files may load as file:// documents; empty when the server is remote. */
|
|
289
|
+
fileRoots?: () => ReadonlyArray<string>
|
|
290
|
+
/** This binding's isolated origin for workspace previews. */
|
|
291
|
+
workspace?: ReturnType<typeof workspacePages>
|
|
292
|
+
/** Failure retained by the protocol handler; Chromium only reports ERR_FAILED for a rejected request. */
|
|
293
|
+
previewFailure?: (url: string) => typeof FileVerificationError.code | undefined
|
|
294
|
+
artifacts?: ReturnType<typeof artifactPages>
|
|
295
|
+
remote?: Extract<WorkspaceSource, { type: "remote" }>
|
|
296
|
+
/**
|
|
297
|
+
* The tab's pop-up group must refuse passkeys too: the agent drives this tab, and a page of the group can script
|
|
298
|
+
* another through `window.opener` or the window it opened. Windows only.
|
|
299
|
+
*/
|
|
300
|
+
restrictPasskeys?: () => void
|
|
301
|
+
/** The tab's pop-up group refuses passkeys already, so this tab does from its first document. */
|
|
302
|
+
passkeysRestricted?: () => boolean
|
|
303
|
+
/** The server runs on this machine, so its loopback addresses are this machine's and the system browser reaches them. */
|
|
304
|
+
local: boolean
|
|
305
|
+
signal: AbortSignal
|
|
306
|
+
/** Extensions whose `chrome-extension://` pages may open, such as their popups and options. */
|
|
307
|
+
extensions?: () => ReadonlyArray<string>
|
|
308
|
+
shared: Shared
|
|
309
|
+
menu: PageMenuHost
|
|
310
|
+
embeds: Embeds
|
|
311
|
+
/** The permission decisions the user kept for sites. */
|
|
312
|
+
sites: SitePermissions
|
|
313
|
+
/** The page browses in a remote server's partition, not the profile. */
|
|
314
|
+
serverPartition?: boolean
|
|
315
|
+
/**
|
|
316
|
+
* What a load waits for before it is issued, if anything: in the profile its content filters, in a remote
|
|
317
|
+
* server's partition the first copy of the sign-ins.
|
|
318
|
+
*/
|
|
319
|
+
waitForFilters?: (url: string, signal: AbortSignal) => Promise<void> | undefined
|
|
320
|
+
/** Reports what the tab waits on the user for, to the window only. */
|
|
321
|
+
prompt?: (view: PromptView | null) => void
|
|
322
|
+
/** Closes the tab, after the user chose to leave a page that asked to stay. */
|
|
323
|
+
closeTab?: () => void
|
|
324
|
+
/** Gives the page keyboard focus back after a prompt, when its tab is in front. */
|
|
325
|
+
focusPage?: () => void
|
|
326
|
+
/** The tab is the one in front of its pane and the app window has the keyboard. */
|
|
327
|
+
front?: () => boolean
|
|
328
|
+
/** The system's camera and microphone setting, and its prompt (system-media.ts). */
|
|
329
|
+
system: SystemMedia
|
|
330
|
+
/** Logs that an Electron internal is not what the page expects; the pane logs each message once. */
|
|
331
|
+
warn?: (message: string) => void
|
|
332
|
+
},
|
|
333
|
+
) {
|
|
334
|
+
const policy: Policy = {
|
|
335
|
+
home: homedir(),
|
|
336
|
+
remote: options.remote?.prefix,
|
|
337
|
+
artifacts: !!options.artifacts,
|
|
338
|
+
get fileRoots() {
|
|
339
|
+
return options.fileRoots?.() ?? []
|
|
340
|
+
},
|
|
341
|
+
get extensions() {
|
|
342
|
+
return options.extensions?.() ?? []
|
|
343
|
+
},
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
const initial = options.initialize === false ? undefined : normalizeURL(options.restore?.url || "about:blank", policy)
|
|
347
|
+
// Until this constructor hands back a BrowserPage there is no tab which could dispose these resources.
|
|
348
|
+
using constructing = new DisposableStack()
|
|
349
|
+
|
|
350
|
+
const view = new electron.WebContentsView({
|
|
351
|
+
...options.popupOptions,
|
|
352
|
+
webPreferences: {
|
|
353
|
+
partition: options.partition,
|
|
354
|
+
nodeIntegration: false,
|
|
355
|
+
// Deliver the profile's CSS receiver to child frames. It runs in the isolated sandbox, not the web world.
|
|
356
|
+
nodeIntegrationInSubFrames: options.local === true,
|
|
357
|
+
contextIsolation: true,
|
|
358
|
+
sandbox: true,
|
|
359
|
+
webSecurity: true,
|
|
360
|
+
webviewTag: false,
|
|
361
|
+
devTools: false,
|
|
362
|
+
// Agent navigation, including in hidden tabs, must not take the user's keyboard focus.
|
|
363
|
+
focusOnNavigation: false,
|
|
364
|
+
},
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
const contents = view.webContents
|
|
368
|
+
const pageLifetime = new AbortController()
|
|
369
|
+
contents.once("destroyed", () => pageLifetime.abort())
|
|
370
|
+
constructing.defer(() => pageLifetime.abort())
|
|
371
|
+
constructing.defer(() => { if (!contents.isDestroyed()) contents.close({ waitForBeforeUnload: false }) })
|
|
372
|
+
|
|
373
|
+
const rendering = agentRendering(pageLifetime.signal, enabled => contents.setBackgroundThrottling(enabled))
|
|
374
|
+
const opening = agentDriven(options.activity) ? rendering.hold() : undefined
|
|
375
|
+
constructing.defer(() => options.workspace?.dispose())
|
|
376
|
+
constructing.defer(() => options.artifacts?.dispose())
|
|
377
|
+
const preview = (url: string) => options.artifacts?.display(url) ?? options.workspace?.display(url)
|
|
378
|
+
// Keep the fence across transient blank/error documents. Page JS cannot clear it by navigating itself.
|
|
379
|
+
let artifactHost: string | undefined
|
|
380
|
+
const displayURL = (url: string) => preview(url) ?? (/^(?:oc-preview|file):/i.test(url) ? "about:blank" : url)
|
|
381
|
+
const detachNetwork = options.network?.attach(contents)
|
|
382
|
+
|
|
383
|
+
if (detachNetwork) constructing.defer(detachNetwork)
|
|
384
|
+
let nativeMenu = true
|
|
385
|
+
// Tab focus and browser chrome commands also reclaim the tab for the person. Neither is input to this document.
|
|
386
|
+
let documentInput = false
|
|
387
|
+
// The person's latest press of a button that opens links, or Enter, until a request for a tab uses it or other input
|
|
388
|
+
// follows. It stands for a link Chromium routes to a new tab by its click, which has no gesture report
|
|
389
|
+
// (window-open.ts).
|
|
390
|
+
let press: Press | undefined
|
|
391
|
+
// The link under the pointer, as Chromium reports it.
|
|
392
|
+
let hovered = ""
|
|
393
|
+
contents.on("update-target-url", (_event, url) => { hovered = url })
|
|
394
|
+
// Presses the agent sent through the debugger that the page has not reported yet.
|
|
395
|
+
let agentPresses = 0
|
|
396
|
+
contents.on("before-mouse-event", (_event, mouse) => {
|
|
397
|
+
if (mouse.type !== "mouseDown") return
|
|
398
|
+
// Whoever presses now, the press before opens nothing more.
|
|
399
|
+
press = undefined
|
|
400
|
+
|
|
401
|
+
// Unlike keyboard events, Electron 44 does not expose the Blink modifiers on mouse events, so a press carries no
|
|
402
|
+
// debugger provenance. Each press the agent sent is counted out here, even one reported after its command ended;
|
|
403
|
+
// any other press while the agent acts stays the agent's. A press during the agent's `wait`, which sends no
|
|
404
|
+
// input and is not counted as acting, is the person's.
|
|
405
|
+
if (agentPresses > 0) return void agentPresses--
|
|
406
|
+
|
|
407
|
+
if (activity.agentRuns > 0) return
|
|
408
|
+
documentInput = true
|
|
409
|
+
|
|
410
|
+
if (mouse.button === "left" || mouse.button === "middle") press = { type: "mouse", button: mouse.button, at: performance.now() }
|
|
411
|
+
nativeMenu = true
|
|
412
|
+
recordPageInput(activity, "user")
|
|
413
|
+
options.userInput()
|
|
414
|
+
void choosers.update().catch(() => undefined)
|
|
415
|
+
})
|
|
416
|
+
|
|
417
|
+
// A cropped page can own focus in its child window. Only that child may raise the host.
|
|
418
|
+
function focusHost() {
|
|
419
|
+
if (win.isDestroyed()) return
|
|
420
|
+
const focused = electron.BaseWindow.getFocusedWindow()
|
|
421
|
+
|
|
422
|
+
if (focused?.getParentWindow() === win && focused.contentView.children.includes(view)) win.focus()
|
|
423
|
+
|
|
424
|
+
if (win.isFocused()) win.webContents.focus()
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
contents.on("before-input-event", (event, input) => {
|
|
428
|
+
const hardware = hardwareInput(input)
|
|
429
|
+
contents.setIgnoreMenuShortcuts(!hardware)
|
|
430
|
+
|
|
431
|
+
if (!hardware || input.type !== "keyDown") return
|
|
432
|
+
|
|
433
|
+
documentInput = true
|
|
434
|
+
// Chromium opens a link for Enter as for a click with the same modifiers; any other key opens none.
|
|
435
|
+
press =
|
|
436
|
+
input.key === "Enter"
|
|
437
|
+
? { type: "key", disposition: clickDisposition({ ...input, middle: false }, process.platform === "darwin"), at: performance.now() }
|
|
438
|
+
: undefined
|
|
439
|
+
nativeMenu = true
|
|
440
|
+
recordPageInput(activity, "user")
|
|
441
|
+
options.userInput()
|
|
442
|
+
void choosers.update().catch(() => undefined)
|
|
443
|
+
|
|
444
|
+
if (pageReload(input, process.platform === "darwin")) {
|
|
445
|
+
event.preventDefault()
|
|
446
|
+
void options.menu.navigate("reload").catch((error: Error) => { if (!pageReports(error)) publish(error.message) })
|
|
447
|
+
|
|
448
|
+
return
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if (input.key === "Escape" && isPickerActive(pickerState)) {
|
|
452
|
+
event.preventDefault()
|
|
453
|
+
void dispatchPicker({ type: "escape.pressed" })
|
|
454
|
+
|
|
455
|
+
return
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const shortcut = pageShortcut(input, process.platform === "darwin", options.toolbar)
|
|
459
|
+
|
|
460
|
+
if (shortcut) {
|
|
461
|
+
event.preventDefault()
|
|
462
|
+
|
|
463
|
+
options.shortcut?.(shortcut)
|
|
464
|
+
|
|
465
|
+
return
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if (input.alt || !(process.platform === "darwin" ? input.meta : input.control)) return
|
|
469
|
+
|
|
470
|
+
// The same chord as Chromium DevTools' element picker.
|
|
471
|
+
if (input.shift && pageLetter(input) === "c") {
|
|
472
|
+
event.preventDefault()
|
|
473
|
+
void dispatchPicker({ type: "inspect.toggled" })
|
|
474
|
+
|
|
475
|
+
return
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const direction = zoomKey(input)
|
|
479
|
+
|
|
480
|
+
if (!direction) return
|
|
481
|
+
event.preventDefault()
|
|
482
|
+
zoom(direction)
|
|
483
|
+
})
|
|
484
|
+
// Ctrl or Cmd with the mouse wheel; Electron leaves applying it to the app.
|
|
485
|
+
contents.on("zoom-changed", (_event, direction) => zoom(direction))
|
|
486
|
+
|
|
487
|
+
const zoom = (direction: "in" | "out" | "reset") => {
|
|
488
|
+
const current = contents.getZoomFactor()
|
|
489
|
+
const next = zoomStep(current, direction)
|
|
490
|
+
|
|
491
|
+
if (next === current) return
|
|
492
|
+
contents.setZoomFactor(next)
|
|
493
|
+
detail()
|
|
494
|
+
options.zoomed?.()
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
let documentState = createDocumentState(options.restore)
|
|
498
|
+
const closed = () => isDocumentClosed(documentState)
|
|
499
|
+
|
|
500
|
+
const withFrames = captureCoordinator(
|
|
501
|
+
() => contents.beginFrameSubscription(true, () => {}),
|
|
502
|
+
() => { if (!contents.isDestroyed()) contents.endFrameSubscription() },
|
|
503
|
+
)
|
|
504
|
+
|
|
505
|
+
let reported: PageDetail | undefined
|
|
506
|
+
const cdp = createCdp(contents)
|
|
507
|
+
|
|
508
|
+
const sessions = new Map<string, string>()
|
|
509
|
+
const device = createDeviceEmulation(cdp, sessions)
|
|
510
|
+
const metrics = createViewportWriter(device.apply, report, closed)
|
|
511
|
+
|
|
512
|
+
function report() {
|
|
513
|
+
if (closed()) return
|
|
514
|
+
// Chromium's factor for the outermost presets can land a rounding error outside them.
|
|
515
|
+
const zoom = Math.min(5, Math.max(0.25, contents.getZoomFactor()))
|
|
516
|
+
const icon = documentIcon(documentState)
|
|
517
|
+
const retry = retryOnly(documentState)
|
|
518
|
+
const { viewport, viewportNotice } = metrics.applied()
|
|
519
|
+
|
|
520
|
+
if (
|
|
521
|
+
reported?.zoom === zoom &&
|
|
522
|
+
reported.icon === icon &&
|
|
523
|
+
!!reported.retryOnly === retry &&
|
|
524
|
+
reported.viewport === viewport &&
|
|
525
|
+
reported.viewportNotice === viewportNotice
|
|
526
|
+
)
|
|
527
|
+
return
|
|
528
|
+
reported = { zoom, viewport, ...(icon && { icon }), ...(retry && { retryOnly: true }), ...(viewportNotice && { viewportNotice }) }
|
|
529
|
+
options.detail?.(reported)
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
async function setViewport(viewport: Viewport) {
|
|
533
|
+
if (closed() || contents.isDestroyed()) throw new Error("browser.pane.unavailable")
|
|
534
|
+
const zoom = contents.getZoomFactor()
|
|
535
|
+
await metrics.set(viewport, view.getBounds(), zoom)
|
|
536
|
+
|
|
537
|
+
if (closed() || contents.isDestroyed()) throw new Error("browser.pane.unavailable")
|
|
538
|
+
|
|
539
|
+
if (viewport.mode === "fixed" && zoom !== 1) throw new Error("viewport.zoomPrompt")
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const resize = () => {
|
|
543
|
+
const viewport = metrics.requested()
|
|
544
|
+
|
|
545
|
+
if (viewport.mode === "fixed") void setViewport(viewport).catch(() => undefined)
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const detail = () => {
|
|
549
|
+
if (closed()) return
|
|
550
|
+
// Navigation and another tab of the same origin can both change this page's zoom.
|
|
551
|
+
const viewport = metrics.requested()
|
|
552
|
+
|
|
553
|
+
if (viewport.mode === "fixed" && contents.getZoomFactor() !== 1) resize()
|
|
554
|
+
void metrics.settled().then(report)
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
view.on("bounds-changed", resize)
|
|
558
|
+
cdp.on("Page.frameResized", () => {
|
|
559
|
+
if (!closed() && contents.getZoomFactor() !== reported?.zoom) detail()
|
|
560
|
+
})
|
|
561
|
+
const documents = new Map<string, string>()
|
|
562
|
+
const sourceURLs = () => [...new Set([state().url, ...documents.values()])].sort()
|
|
563
|
+
const files = createBrowserFiles(sourceURLs)
|
|
564
|
+
constructing.defer(() => void files.dispose().catch(() => undefined))
|
|
565
|
+
|
|
566
|
+
const diagnostics = createDiagnostics(cdp, displayURL, (id, sessionID) =>
|
|
567
|
+
Array.from(contexts.values()).some((context) => context.id === id && context.sessionID === sessionID))
|
|
568
|
+
|
|
569
|
+
const profiling = createProfiling(contents, cdp, files, sourceURLs, options.shared)
|
|
570
|
+
const refs = documentRefs()
|
|
571
|
+
// Elements the user picked. Their refs outlive later snapshots, so a comment keeps pointing at
|
|
572
|
+
// the element until the document changes.
|
|
573
|
+
const picked = new Map<string, Element>()
|
|
574
|
+
let pickerState = initialPickerState
|
|
575
|
+
let pickerTimer: ReturnType<typeof setTimeout> | undefined
|
|
576
|
+
const parents = new Map<string, string>()
|
|
577
|
+
const contexts = new Map<string, { id: number; sessionID?: string }>()
|
|
578
|
+
// Frames that show an extension's document, which no agent frameID may reach: an extension's out-of-process frame by
|
|
579
|
+
// the session it attached with (a web frame's own session may detach after its replacement attached), and a frame
|
|
580
|
+
// whose document has an extension's origin.
|
|
581
|
+
const extensionTargets = new Map<string, string>()
|
|
582
|
+
const extensionContexts = new Set<string>()
|
|
583
|
+
const extensionFrames = () => new Set([...extensionTargets.values(), ...extensionContexts])
|
|
584
|
+
|
|
585
|
+
const attachFrames = (sessionID?: string) => attachChildren(cdp, sessionID)
|
|
586
|
+
|
|
587
|
+
const activity = options.activity
|
|
588
|
+
|
|
589
|
+
const notices = noticeActions((notice, token) => options.refused(notice, token, destinationOrigin(contents.getURL())), {
|
|
590
|
+
tab: options.menu.open,
|
|
591
|
+
app: (url) => electron.shell.openExternal(url),
|
|
592
|
+
copy: (url) => electron.clipboard.writeText(url),
|
|
593
|
+
})
|
|
594
|
+
|
|
595
|
+
constructing.defer(notices.clear)
|
|
596
|
+
const registerArtifactLinks = artifactLinks(cdp, () => artifactHost, target => notices.show({reason:"popup",target,action:"tab"}))
|
|
597
|
+
const refused = (url: string) => notices.show(navigationNotice(url, policy, activityOwner(activity), documentInput))
|
|
598
|
+
|
|
599
|
+
// Whether this tab ends with a first navigation that left it nothing to show (window-open.ts).
|
|
600
|
+
const leaves = (outcome: Unshown) =>
|
|
601
|
+
closesUnshown(
|
|
602
|
+
{ opened: !!options.opened, committed: documentGeneration(documentState) > 0, owner: activityOwner(activity) },
|
|
603
|
+
outcome,
|
|
604
|
+
)
|
|
605
|
+
|
|
606
|
+
let popupReport: Protocol.Page.WindowOpenEvent | undefined
|
|
607
|
+
cdp.on("Page.windowOpen", (event) => { popupReport = event })
|
|
608
|
+
// Chromium's report that a clicked link's navigation goes to a new tab or window, sent just before that request.
|
|
609
|
+
let linkReport: Protocol.Page.FrameRequestedNavigationEvent | undefined
|
|
610
|
+
cdp.on("Page.frameRequestedNavigation", (event) => {
|
|
611
|
+
if (event.reason === "anchorClick" && (event.disposition === "newTab" || event.disposition === "newWindow")) linkReport = event
|
|
612
|
+
})
|
|
613
|
+
let dialogGate = createDialogGateState()
|
|
614
|
+
// Running commands by run id: the controller that stops their remaining steps, and the wait an interruption ends.
|
|
615
|
+
const runs = new Map<number, { controller: AbortController; interrupted: Interrupted; origin: "user" | "agent" }>()
|
|
616
|
+
|
|
617
|
+
const choosers = guardFileChoosers(cdp, activity, message => {
|
|
618
|
+
for (const run of runs.values()) {
|
|
619
|
+
if (run.origin !== "agent") continue
|
|
620
|
+
run.interrupted.reject(new Error(message))
|
|
621
|
+
run.controller.abort()
|
|
622
|
+
}
|
|
623
|
+
})
|
|
624
|
+
|
|
625
|
+
// Set the nested auto-attach policy before the new renderer can create its own children.
|
|
626
|
+
const prepareFrame = async (sessionID: string) => {
|
|
627
|
+
try {
|
|
628
|
+
await Promise.all([attachFrames(sessionID), choosers.attach(sessionID), media.attach(sessionID), passkeys.attach(sessionID)])
|
|
629
|
+
await cdp.send("Runtime.runIfWaitingForDebugger", {}, sessionID)
|
|
630
|
+
} catch {
|
|
631
|
+
// A detached target needs no resumption. A live one must not run unguarded or remain invisibly paused.
|
|
632
|
+
if (!closed() && (extensionTargets.has(sessionID) || Array.from(sessions.values()).includes(sessionID))) end({ cause: "frame-unprepared" })
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
let revision = 0
|
|
637
|
+
cdp.on("Page.frameNavigated", ({ frame }) => {
|
|
638
|
+
documents.set(frame.id, displayURL(frame.url))
|
|
639
|
+
revision++
|
|
640
|
+
})
|
|
641
|
+
cdp.on("Page.frameDetached", ({ frameId, reason }) => {
|
|
642
|
+
documents.delete(frameId)
|
|
643
|
+
revision++
|
|
644
|
+
|
|
645
|
+
// A swap moves the frame to another process, where it may now show an extension's document; keep what is known.
|
|
646
|
+
if (reason === "remove") extensionContexts.delete(frameId)
|
|
647
|
+
})
|
|
648
|
+
|
|
649
|
+
const state = (display = false) =>
|
|
650
|
+
documentTab(documentState, {
|
|
651
|
+
id: options.id,
|
|
652
|
+
canGoBack: contents.navigationHistory.canGoBack(),
|
|
653
|
+
canGoForward: contents.navigationHistory.canGoForward(),
|
|
654
|
+
}, display)
|
|
655
|
+
|
|
656
|
+
// The desktop log's account of this page ending or stalling: its origin, never its address or title.
|
|
657
|
+
const journal = createPageLog({
|
|
658
|
+
tab: options.id,
|
|
659
|
+
write: options.log ?? (() => undefined),
|
|
660
|
+
page: () => {
|
|
661
|
+
const tab = documentTab(documentState, { id: options.id, canGoBack: false, canGoForward: false })
|
|
662
|
+
|
|
663
|
+
return { address: tab.url, agentDriven: agentDriven(activity), loading: tab.loading }
|
|
664
|
+
},
|
|
665
|
+
memory: () => (contents.isDestroyed() ? undefined : processMemory(electron.app.getAppMetrics(), contents.getOSProcessId())),
|
|
666
|
+
})
|
|
667
|
+
|
|
668
|
+
// Every signal that stops the page comes through here: the log hears each one, the pane the first.
|
|
669
|
+
const end = (cause: PageEnd) => {
|
|
670
|
+
// A page the pane closed did not end. One that ended may still hear its process's own account.
|
|
671
|
+
if (closed() && !journal.ended()) return
|
|
672
|
+
const account = journal.end(cause)
|
|
673
|
+
|
|
674
|
+
// The debugger also leaves a process that is gone, and may say so before Electron says why. Nothing runs in the
|
|
675
|
+
// page then, so the pane waits with the log, for the same bounded moment, and hears the process's own account.
|
|
676
|
+
if (cause.cause === "debugger-detached" && !contents.isDestroyed() && contents.isCrashed())
|
|
677
|
+
return void account.then((recorded) => {
|
|
678
|
+
if (!closed()) options.fail(recorded)
|
|
679
|
+
})
|
|
680
|
+
|
|
681
|
+
if (!closed()) options.fail(cause)
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// Every state report goes through here, so a page that was disposed publishes nothing.
|
|
685
|
+
// While a user's close asks the page's beforeunload on a blank load, the tab reports nothing: the blank page is not
|
|
686
|
+
// where it is, and a close or a window that goes meanwhile keeps its real address for restore.
|
|
687
|
+
let quiet = false
|
|
688
|
+
|
|
689
|
+
const publish = (error?: string) => {
|
|
690
|
+
if (!closed() && !quiet) options.publish(error)
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
let startingBlank = false
|
|
694
|
+
|
|
695
|
+
const dispatch = (event: DocumentEvent) => {
|
|
696
|
+
if (startingBlank && event.type !== "disposed") return
|
|
697
|
+
const next = transitionDocument(documentState, event)
|
|
698
|
+
documentState = next.state
|
|
699
|
+
next.effects.forEach((effect) => {
|
|
700
|
+
switch (effect.type) {
|
|
701
|
+
case "reset-document":
|
|
702
|
+
documents.clear()
|
|
703
|
+
refs.clear()
|
|
704
|
+
picked.clear()
|
|
705
|
+
void dispatchPicker({ type: "document.changed" })
|
|
706
|
+
break
|
|
707
|
+
case "clear-diagnostics":
|
|
708
|
+
diagnostics.clear()
|
|
709
|
+
break
|
|
710
|
+
case "show":
|
|
711
|
+
// The renderer's layout requests may lag behind navigation; the page decides
|
|
712
|
+
// whether there is a document worth exposing over the themed background.
|
|
713
|
+
embed.show(effect.visible)
|
|
714
|
+
break
|
|
715
|
+
case "publish":
|
|
716
|
+
publish()
|
|
717
|
+
break
|
|
718
|
+
case "detail":
|
|
719
|
+
detail()
|
|
720
|
+
break
|
|
721
|
+
case "load-icon":
|
|
722
|
+
// Never rejects: an icon that does not load is none.
|
|
723
|
+
// Main's icon fetch is outside the page's network policy. Never proxy an artifact's candidates for it.
|
|
724
|
+
void loadIcon(effect.favicons, artifactHost ? null : options.network).then((icon) =>
|
|
725
|
+
dispatch({ type: "icon.loaded", attempt: effect.attempt, icon }),
|
|
726
|
+
)
|
|
727
|
+
}
|
|
728
|
+
})
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
const dispatchDialog = (event: DialogGateEvent) => {
|
|
732
|
+
const next = transitionDialogGate(dialogGate, event)
|
|
733
|
+
dialogGate = next.state
|
|
734
|
+
next.effects.forEach((effect) => {
|
|
735
|
+
if (effect.type === "publish") {
|
|
736
|
+
prompts.publish()
|
|
737
|
+
|
|
738
|
+
return publish()
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
if (effect.type === "dismiss")
|
|
742
|
+
return void cdp.send("Page.handleJavaScriptDialog", { accept: false }).catch(() => undefined)
|
|
743
|
+
const run = runs.get(effect.runID)
|
|
744
|
+
|
|
745
|
+
if (!run) return
|
|
746
|
+
runs.delete(effect.runID)
|
|
747
|
+
|
|
748
|
+
if (effect.abort) run.controller.abort()
|
|
749
|
+
run.interrupted.reject(runStopError(effect.reason))
|
|
750
|
+
})
|
|
751
|
+
|
|
752
|
+
return next
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// The user's answer to a page dialog, unless the agent answers it first.
|
|
756
|
+
const answerDialog = async (revision: number, accept: boolean, text: string, stop: boolean) => {
|
|
757
|
+
if (dispatchDialog({ type: "dialog.answering", revision, by: "user" }).answer !== "accepted") return
|
|
758
|
+
|
|
759
|
+
if (stop) dispatchDialog({ type: "dialog.suppressed" })
|
|
760
|
+
await cdp.send("Page.handleJavaScriptDialog", { accept, promptText: text }).then(
|
|
761
|
+
() => void dispatchDialog({ type: "dialog.handled", revision, at: Date.now() }),
|
|
762
|
+
() => void dispatchDialog({ type: "dialog.answer-failed", revision }),
|
|
763
|
+
)
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// Page dialogs, permission requests, sign-ins and "Leave site?" wait for the user in the pane; see page-prompts.ts.
|
|
767
|
+
const dialogs = takeDialogs(contents, {
|
|
768
|
+
suppressed: () => selectSuppressed(dialogGate),
|
|
769
|
+
opened: () => !!selectOpenDialog(dialogGate),
|
|
770
|
+
// The dialog shows at once; its frame's origin names it once Electron reports it.
|
|
771
|
+
framed: () => prompts.publish(),
|
|
772
|
+
warn: (message) => options.warn?.(message),
|
|
773
|
+
})
|
|
774
|
+
|
|
775
|
+
// Set while a prompt hides the page's view and the page should get the keyboard back once the view shows.
|
|
776
|
+
let refocus = false
|
|
777
|
+
|
|
778
|
+
const prompts = createPagePrompts({
|
|
779
|
+
contents,
|
|
780
|
+
scope: options.serverPartition ? { kind: "server", partition: options.partition } : { kind: "profile" },
|
|
781
|
+
sites: options.sites,
|
|
782
|
+
// Sticky: site permissions, clipboard writes and where a prompt puts focus.
|
|
783
|
+
agentDriven: () => agentDriven(activity),
|
|
784
|
+
top: () => state().url,
|
|
785
|
+
dialog: () => selectUserDialog(dialogGate),
|
|
786
|
+
dialogFrame: () => dialogs.frame(),
|
|
787
|
+
answerDialog: (revision, answer) => answerDialog(revision, answer.accept, answer.text, answer.stop),
|
|
788
|
+
redo: (action) => execute(action, [], new AbortController().signal, "user").then(() => undefined, () => undefined),
|
|
789
|
+
close: () => options.closeTab?.(),
|
|
790
|
+
// A page that held the keyboard before a prompt gets it back once its view shows again: a dialog's still hides the
|
|
791
|
+
// view until the page draws, and a hidden view cannot take focus.
|
|
792
|
+
focusPage: () => {
|
|
793
|
+
refocus = !view.getVisible()
|
|
794
|
+
|
|
795
|
+
if (!refocus) options.focusPage?.()
|
|
796
|
+
},
|
|
797
|
+
front: () => !!options.front?.(),
|
|
798
|
+
returning: () => refocus,
|
|
799
|
+
system: options.system,
|
|
800
|
+
quiet: (value) => {
|
|
801
|
+
quiet = value
|
|
802
|
+
|
|
803
|
+
if (!value) publish()
|
|
804
|
+
},
|
|
805
|
+
report: (view) => {
|
|
806
|
+
if (!closed()) options.prompt?.(view)
|
|
807
|
+
},
|
|
808
|
+
})
|
|
809
|
+
|
|
810
|
+
// A page's getUserMedia waits for the pane before Blink opens a device, so macOS asks only after the user's Allow.
|
|
811
|
+
const media = guardMediaRequests(cdp, (ask) => prompts.gate(ask))
|
|
812
|
+
// A site's passkey or security-key request fails where nothing here could answer it: always on macOS and Linux, and on
|
|
813
|
+
// Windows, whose own dialog would answer, in tabs the agent drives or could script. Once per page, the notice says
|
|
814
|
+
// why and a running agent command stops with the reason.
|
|
815
|
+
const native = process.platform === "win32"
|
|
816
|
+
const passkeyPage = { noticed: false, interrupted: false }
|
|
817
|
+
|
|
818
|
+
const passkeys = guardWebAuthn(cdp, {
|
|
819
|
+
native,
|
|
820
|
+
refused: (asker) => {
|
|
821
|
+
// Another site's frame does not speak for the page: its request is refused without a word.
|
|
822
|
+
if (!asker.mainFrame && (!asker.origin || asker.origin !== contents.mainFrame.origin)) return
|
|
823
|
+
const address = URL.parse(displayURL(contents.getURL()))
|
|
824
|
+
|
|
825
|
+
// Any agent command in flight stops, a `wait` included, which `agentRuns` leaves out.
|
|
826
|
+
if (!passkeyPage.interrupted && Array.from(runs.values()).some((run) => run.origin === "agent")) {
|
|
827
|
+
passkeyPage.interrupted = true
|
|
828
|
+
prompts.interruptAgent(new CodedError(Browser.FailureCode.signInRequired, agentPasskeyRefusal(address?.host)))
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
if (passkeyPage.noticed) return
|
|
832
|
+
passkeyPage.noticed = true
|
|
833
|
+
const site = address?.hostname ? cookieSite(address.hostname) : undefined
|
|
834
|
+
// On Windows only an enforced tab refuses, and a new tab of the person's would reach the system's dialog.
|
|
835
|
+
const reason = native ? "browser.passkey.off" : agentDriven(activity) ? "browser.passkey.agent" : "browser.passkey"
|
|
836
|
+
notices.show(site && site.length <= 255 ? { reason, site } : { reason })
|
|
837
|
+
},
|
|
838
|
+
})
|
|
839
|
+
|
|
840
|
+
// A page that can never reach the system's dialog, or one the agent drove or could script, refuses in the browser
|
|
841
|
+
// process before its first document loads. On Windows a failure to do so, whenever it happens, leaves it with the
|
|
842
|
+
// system's dialog, so the tab fails.
|
|
843
|
+
const restrictPasskeys = () => {
|
|
844
|
+
if (native) options.restrictPasskeys?.()
|
|
845
|
+
|
|
846
|
+
const enforcing = passkeys.enforce()
|
|
847
|
+
|
|
848
|
+
if (native) void enforcing.catch(() => end({ cause: "passkeys-unrestricted" }))
|
|
849
|
+
|
|
850
|
+
return enforcing
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
if (!native || agentDriven(options.activity) || options.passkeysRestricted?.())
|
|
854
|
+
void restrictPasskeys().catch(() => undefined)
|
|
855
|
+
|
|
856
|
+
constructing.defer(() => prompts.dispose())
|
|
857
|
+
constructing.defer(() => dialogs.dispose())
|
|
858
|
+
|
|
859
|
+
// Chromium uses the document URL as the title of untitled files; don't persist its internal origin as a title.
|
|
860
|
+
const pageTitle = (address = state().url) => {
|
|
861
|
+
const title = contents.getTitle()
|
|
862
|
+
|
|
863
|
+
if (documentState.status !== "closed" && documentState.retry && (!title || title === "about:blank"))
|
|
864
|
+
return documentState.title || documentState.retry
|
|
865
|
+
|
|
866
|
+
return /^oc-preview:/i.test(title) ? address : title
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
contents.on("did-start-loading", () => dispatch({ type: "loading.started" }))
|
|
870
|
+
contents.on("did-stop-loading", () => {
|
|
871
|
+
dispatch({ type: "loading.stopped", title: pageTitle() })
|
|
872
|
+
detail()
|
|
873
|
+
|
|
874
|
+
// A page that ends before the pane's next sample still has its memory as it was once loaded.
|
|
875
|
+
if (!closed()) journal.sample(processMemory(electron.app.getAppMetrics(), contents.getOSProcessId()))
|
|
876
|
+
})
|
|
877
|
+
contents.on("did-start-navigation", (event) => {
|
|
878
|
+
// A load no frame started (the address bar, a link from the conversation, history) may redirect before it commits.
|
|
879
|
+
// Input in the page it leaves is not input in the page that redirects.
|
|
880
|
+
if (event.isMainFrame && !event.isSameDocument && !event.initiator) documentInput = false
|
|
881
|
+
|
|
882
|
+
if (event.isMainFrame && !event.isSameDocument) journal.navigationStarted()
|
|
883
|
+
navigation.nativeStart(event)
|
|
884
|
+
dispatch({
|
|
885
|
+
type: "navigation.started",
|
|
886
|
+
url: displayURL(event.url),
|
|
887
|
+
isMainFrame: event.isMainFrame,
|
|
888
|
+
isSameDocument: event.isSameDocument,
|
|
889
|
+
})
|
|
890
|
+
})
|
|
891
|
+
// The status line's reason phrase is the site's own text: only the number is kept.
|
|
892
|
+
contents.on("did-navigate", (_event, url, status) =>
|
|
893
|
+
dispatch({ type: "navigation.committed", url: displayURL(url), status, title: pageTitle(displayURL(url)) }),
|
|
894
|
+
)
|
|
895
|
+
contents.on("did-navigate", () => {
|
|
896
|
+
documentInput = false
|
|
897
|
+
const url = contents.getURL()
|
|
898
|
+
|
|
899
|
+
if (options.artifacts?.display(url)) artifactHost = new URL(url).host
|
|
900
|
+
notices.clear()
|
|
901
|
+
passkeyPage.noticed = false
|
|
902
|
+
passkeyPage.interrupted = false
|
|
903
|
+
popupReport = undefined
|
|
904
|
+
linkReport = undefined
|
|
905
|
+
press = undefined
|
|
906
|
+
|
|
907
|
+
rendering.committed()
|
|
908
|
+
})
|
|
909
|
+
contents.on("did-fail-load", (_event, code, description, url, isMainFrame) => {
|
|
910
|
+
// ERR_ABORTED is a load that was stopped, replaced or became a download, not one that failed.
|
|
911
|
+
if (isMainFrame && code !== -3 && !closed()) journal.loadFailed(code, description, displayURL(url))
|
|
912
|
+
dispatch({ type: "navigation.failed", code, description: options.previewFailure?.(url) ?? (options.artifacts?.display(url) ? "browser.artifact.missing" : description), url, preview: preview(url), isMainFrame })
|
|
913
|
+
})
|
|
914
|
+
contents.on("did-navigate-in-page", (_event, url, isMainFrame) => {
|
|
915
|
+
if (!isMainFrame) return
|
|
916
|
+
documentInput = false
|
|
917
|
+
const report = (address: string) => dispatch({ type: "navigation.in-page", url: address, title: pageTitle(address), isMainFrame })
|
|
918
|
+
|
|
919
|
+
if (!/^(?:oc-preview|file):/i.test(url)) return report(url)
|
|
920
|
+
const file = preview(url)
|
|
921
|
+
|
|
922
|
+
if (!file) return
|
|
923
|
+
// History API routes never pass the protocol handler. Keep the last validated address for virtual routes.
|
|
924
|
+
const exists = file.startsWith("artifact:") ? options.artifacts?.exists(file) : options.workspace?.exists(url, options.signal)
|
|
925
|
+
|
|
926
|
+
void Promise.resolve(exists).catch(() => false).then((target) => {
|
|
927
|
+
if (target && !closed() && !contents.isDestroyed() && contents.getURL() === url) report(file)
|
|
928
|
+
})
|
|
929
|
+
})
|
|
930
|
+
contents.on("dom-ready", () => dispatch({ type: "document.ready" }))
|
|
931
|
+
contents.on("page-title-updated", () => dispatch({ type: "title.updated", title: pageTitle() }))
|
|
932
|
+
contents.on("page-favicon-updated", (_event, favicons) => dispatch({ type: "icon.updated", favicons }))
|
|
933
|
+
contents.on("focus", () => {
|
|
934
|
+
if (!closed()) options.focused?.()
|
|
935
|
+
})
|
|
936
|
+
contents.on("render-process-gone", (_event, details) => end({ cause: "renderer-gone", reason: details.reason, exitCode: details.exitCode }))
|
|
937
|
+
contents.debugger.on("detach", (_event, reason) => end({ cause: "debugger-detached", reason }))
|
|
938
|
+
// The debugger's own report of a crash carries no reason; it is logged only when the process's report did not come first.
|
|
939
|
+
cdp.on("Inspector.targetCrashed", (_event, sessionID) => {
|
|
940
|
+
if (!sessionID && !closed()) void journal.end({ cause: "target-crashed" })
|
|
941
|
+
})
|
|
942
|
+
contents.on("unresponsive", () => {
|
|
943
|
+
if (!closed()) journal.unresponsive()
|
|
944
|
+
})
|
|
945
|
+
contents.on("responsive", () => {
|
|
946
|
+
if (!closed()) journal.responsive()
|
|
947
|
+
})
|
|
948
|
+
contents.on("content-bounds-updated", (event) => event.preventDefault())
|
|
949
|
+
|
|
950
|
+
// Sub-frames keep Chromium's own rules so blob:/data: viewers and sandboxed previews still load,
|
|
951
|
+
// except file: documents, which must stay inside the allowed roots at every depth.
|
|
952
|
+
const resource = (url: string, origin: string) => extensionResource(url, origin, (id) => contents.session.extensions.getExtension(id))
|
|
953
|
+
|
|
954
|
+
const guard = (event: Electron.Event<Electron.WebContentsWillNavigateEventParams>) => {
|
|
955
|
+
if (artifactHost && !event.url.startsWith(`oc-preview://${artifactHost}/`)) {
|
|
956
|
+
event.preventDefault()
|
|
957
|
+
|
|
958
|
+
if (event.isMainFrame && destinationOrigin(event.url)) notices.show({reason:"popup", target:event.url.slice(0,16384), action:event.url.length <= 16384 ? "tab" : undefined})
|
|
959
|
+
|
|
960
|
+
return
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
if (URL.parse(event.url)?.protocol === "chrome-extension:" && !resource(event.url, event.initiator?.origin ?? "")) {
|
|
964
|
+
event.preventDefault()
|
|
965
|
+
|
|
966
|
+
return refused(event.url)
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
if (event.url === "about:blank") return
|
|
970
|
+
|
|
971
|
+
const local = /^file:/i.test(event.url) || event.url.toLowerCase().startsWith(`${previewScheme}:`)
|
|
972
|
+
|
|
973
|
+
if (local && preview(event.url)) return
|
|
974
|
+
|
|
975
|
+
if (!local && (allowedDestination(event.url, policy) || (!event.isMainFrame && /^(?:blob:|data:|about:srcdoc$)/i.test(event.url)))) return
|
|
976
|
+
event.preventDefault()
|
|
977
|
+
// The same reason a typed address gets, so a blocked link and a blocked address read alike.
|
|
978
|
+
const notice = navigationNotice(event.url, policy, activityOwner(activity), documentInput)
|
|
979
|
+
|
|
980
|
+
// Another app's link that a new tab was opened for is offered in the tab the person opened it from, as a click on
|
|
981
|
+
// that link is, and the empty tab goes.
|
|
982
|
+
if (event.isMainFrame && leaves(notice.reason === "external" ? "app" : "refused")) {
|
|
983
|
+
options.opened?.refused(event.url)
|
|
984
|
+
|
|
985
|
+
return options.opened?.close()
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
notices.show(notice)
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
contents.on("will-frame-navigate", guard)
|
|
992
|
+
contents.on("will-redirect", guard)
|
|
993
|
+
// A middle-click, Ctrl+click (Cmd on macOS) or Shift+click on a link, a `target="_blank"` link and `window.open` all
|
|
994
|
+
// arrive here. A link opened with Cmd or Ctrl or the middle button stays behind the current tab, as in Chrome.
|
|
995
|
+
contents.setWindowOpenHandler(({ url, disposition, postBody, referrer }) => {
|
|
996
|
+
const opening = windowOpening({
|
|
997
|
+
artifact: !!artifactHost,
|
|
998
|
+
openable: url === "about:blank" || !!destinationOrigin(url) || resource(url, referrer.url) || !!preview(url),
|
|
999
|
+
url,
|
|
1000
|
+
disposition,
|
|
1001
|
+
report: popupReport,
|
|
1002
|
+
link: linkReport,
|
|
1003
|
+
hovered,
|
|
1004
|
+
owner: activityOwner(activity),
|
|
1005
|
+
press,
|
|
1006
|
+
at: performance.now(),
|
|
1007
|
+
})
|
|
1008
|
+
|
|
1009
|
+
// Each report stands for one request, and a press for at most one tab, as Chromium's activation is used up by the
|
|
1010
|
+
// tab it opens.
|
|
1011
|
+
popupReport = undefined
|
|
1012
|
+
linkReport = undefined
|
|
1013
|
+
press = undefined
|
|
1014
|
+
|
|
1015
|
+
if (opening.type === "ask") {
|
|
1016
|
+
if (!postBody && destinationOrigin(url) && url.length <= 16384) notices.show({reason:"popup",target:url,action:"tab"})
|
|
1017
|
+
|
|
1018
|
+
return { action: "deny" }
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
if (opening.type === "refuse") {
|
|
1022
|
+
refused(url)
|
|
1023
|
+
|
|
1024
|
+
return { action: "deny" }
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
if (opening.type === "block") {
|
|
1028
|
+
const target = displayURL(url)
|
|
1029
|
+
const replay = !postBody && target.length <= 16384 && (!!destinationOrigin(target) || !!preview(url))
|
|
1030
|
+
notices.show(replay ? { reason: "popup", target, action: "tab" } : { reason: "popup", target: target.slice(0, 16384) })
|
|
1031
|
+
|
|
1032
|
+
return { action: "deny" }
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
const workspace = options.workspace?.display(url)
|
|
1036
|
+
|
|
1037
|
+
if (workspace && !postBody) {
|
|
1038
|
+
void options.menu.open(workspace, opening.background).catch(() => publish("browser.menu.failed"))
|
|
1039
|
+
|
|
1040
|
+
return { action: "deny" }
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
return {
|
|
1044
|
+
action: "allow",
|
|
1045
|
+
outlivesOpener: true,
|
|
1046
|
+
overrideBrowserWindowOptions: {
|
|
1047
|
+
webPreferences: {
|
|
1048
|
+
nodeIntegration: false,
|
|
1049
|
+
nodeIntegrationInSubFrames: options.local === true,
|
|
1050
|
+
contextIsolation: true,
|
|
1051
|
+
sandbox: true,
|
|
1052
|
+
webSecurity: true,
|
|
1053
|
+
webviewTag: false,
|
|
1054
|
+
devTools: false,
|
|
1055
|
+
// Electron applies these preferences before the popup is adopted by our view.
|
|
1056
|
+
focusOnNavigation: false,
|
|
1057
|
+
partition: options.partition,
|
|
1058
|
+
},
|
|
1059
|
+
},
|
|
1060
|
+
createWindow: (popupOptions) => options.popup(popupOptions, opening.background, childActivity(activity), refused),
|
|
1061
|
+
}
|
|
1062
|
+
})
|
|
1063
|
+
|
|
1064
|
+
// Called from the session's one download listener (`guardSession`) for a download this page started. One the user
|
|
1065
|
+
// started is left to the system's save flow, so it goes where they save it and the agent never reads it.
|
|
1066
|
+
const download = (item: Electron.DownloadItem) => {
|
|
1067
|
+
const owner = downloadOwner({
|
|
1068
|
+
...activity,
|
|
1069
|
+
page: [contents.mainFrame.url, contents.mainFrame.origin],
|
|
1070
|
+
chain: item.getURLChain(),
|
|
1071
|
+
})
|
|
1072
|
+
|
|
1073
|
+
if (owner === "user") {
|
|
1074
|
+
if (!leaves("download")) return
|
|
1075
|
+
|
|
1076
|
+
// A new tab whose first navigation became a download has nothing to show. It closes once the download has its
|
|
1077
|
+
// place: while the person is still choosing in the save dialog, the item has no save path.
|
|
1078
|
+
const placed = () => {
|
|
1079
|
+
if (!leaves(item.getSavePath() || item.getState() !== "progressing" ? "download" : "download.choosing")) return
|
|
1080
|
+
item.off("updated", placed)
|
|
1081
|
+
item.off("done", placed)
|
|
1082
|
+
options.opened?.close()
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
item.on("updated", placed)
|
|
1086
|
+
item.on("done", placed)
|
|
1087
|
+
|
|
1088
|
+
return
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
if (owner === "block") return item.cancel()
|
|
1092
|
+
|
|
1093
|
+
try {
|
|
1094
|
+
const file = files.add(item.getFilename(), item.getMimeType() || "application/octet-stream", [
|
|
1095
|
+
...sourceURLs(),
|
|
1096
|
+
...item.getURLChain(),
|
|
1097
|
+
])
|
|
1098
|
+
|
|
1099
|
+
item.setSavePath(file.path)
|
|
1100
|
+
item.on("updated", () => {
|
|
1101
|
+
file.bytes = item.getReceivedBytes()
|
|
1102
|
+
|
|
1103
|
+
if (file.bytes > Browser.MAX_FILE_BYTES) item.cancel()
|
|
1104
|
+
})
|
|
1105
|
+
item.once("done", (_event, status) => {
|
|
1106
|
+
file.bytes = item.getReceivedBytes()
|
|
1107
|
+
file.state = status === "completed" ? "completed" : "failed"
|
|
1108
|
+
})
|
|
1109
|
+
} catch {
|
|
1110
|
+
item.cancel()
|
|
1111
|
+
publish("download_failed")
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
cdp.on("Runtime.executionContextCreated", ({ context }, sessionID) => {
|
|
1116
|
+
// SAFETY: CDP documents a page execution context's auxData as `{ frameId, isDefault, type }`.
|
|
1117
|
+
const aux = context.auxData as { frameId?: string; isDefault?: boolean } | undefined
|
|
1118
|
+
|
|
1119
|
+
if (!aux?.frameId || !aux.isDefault) return
|
|
1120
|
+
|
|
1121
|
+
// A frame that becomes an extension's document, as about:blank opened by one does, is no target for the agent.
|
|
1122
|
+
if (Browser.extensionOrigin(context.origin)) {
|
|
1123
|
+
contexts.delete(aux.frameId)
|
|
1124
|
+
extensionContexts.add(aux.frameId)
|
|
1125
|
+
const own = sessions.get(aux.frameId)
|
|
1126
|
+
|
|
1127
|
+
// An out-of-process web frame that turned into one in place leaves the frame list and stops reporting its console
|
|
1128
|
+
// and network. It stays refused until the page removes it, even if it shows a web page again.
|
|
1129
|
+
if (own) {
|
|
1130
|
+
sessions.delete(aux.frameId)
|
|
1131
|
+
parents.delete(aux.frameId)
|
|
1132
|
+
void cdp.send("Target.detachFromTarget", { sessionId: own }).catch(() => undefined)
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
return
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
contexts.set(aux.frameId, { id: context.id, sessionID })
|
|
1139
|
+
extensionContexts.delete(aux.frameId)
|
|
1140
|
+
})
|
|
1141
|
+
cdp.on("Runtime.executionContextDestroyed", ({ executionContextId }, sessionID) => {
|
|
1142
|
+
contexts.forEach((context, key) => {
|
|
1143
|
+
if (context.id === executionContextId && context.sessionID === sessionID) contexts.delete(key)
|
|
1144
|
+
})
|
|
1145
|
+
})
|
|
1146
|
+
cdp.on("Runtime.executionContextsCleared", (_event, sessionID) => {
|
|
1147
|
+
contexts.forEach((context, key) => { if (context.sessionID === sessionID) contexts.delete(key) })
|
|
1148
|
+
})
|
|
1149
|
+
cdp.on("Target.attachedToTarget", ({ sessionId, targetInfo }, parentSessionID) => {
|
|
1150
|
+
// Paused at start by the auto-attach above; it must run, as it did before the tab guarded its children.
|
|
1151
|
+
if (targetInfo.type === "worker") return void releaseWorker(cdp, sessionId)
|
|
1152
|
+
|
|
1153
|
+
if (targetInfo.type !== "iframe") return
|
|
1154
|
+
|
|
1155
|
+
// An extension's frame, such as an autofill overlay, stays out of `sessions`: no frame list, snapshot, picker or
|
|
1156
|
+
// diagnostics reaches it. Site isolation gives it a process, and so a target, of its own. The context its first
|
|
1157
|
+
// document had in the embedding page's process is dropped, so its frameID cannot reach that page instead.
|
|
1158
|
+
if (Browser.extensionOrigin(targetInfo.url) || (parentSessionID && extensionTargets.has(parentSessionID)) ||
|
|
1159
|
+
(targetInfo.parentFrameId && extensionContexts.has(targetInfo.parentFrameId))) {
|
|
1160
|
+
extensionTargets.set(sessionId, targetInfo.targetId)
|
|
1161
|
+
contexts.delete(targetInfo.targetId)
|
|
1162
|
+
// Descendant iframe targets are excluded even if their own document is a web page. Do not enable diagnostics.
|
|
1163
|
+
void prepareFrame(sessionId)
|
|
1164
|
+
|
|
1165
|
+
return
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
const parentID = targetInfo.parentFrameId ?? Array.from(sessions).find(([, id]) => id === parentSessionID)?.[0]
|
|
1169
|
+
|
|
1170
|
+
if (parentID) parents.set(targetInfo.targetId, parentID)
|
|
1171
|
+
sessions.set(targetInfo.targetId, sessionId)
|
|
1172
|
+
// An isolated frame has its own renderer and needs its own UA and touch overrides.
|
|
1173
|
+
void Promise.all([
|
|
1174
|
+
device.frame(sessionId),
|
|
1175
|
+
diagnostics.enable(sessionId),
|
|
1176
|
+
cdp.send("Page.enable", {}, sessionId),
|
|
1177
|
+
prepareFrame(sessionId),
|
|
1178
|
+
]).catch(() => undefined)
|
|
1179
|
+
void dispatchPicker({ type: "frame.attached", sessionID: sessionId })
|
|
1180
|
+
})
|
|
1181
|
+
// Each out-of-process frame runs its own picker; the frame under the pointer reports the click.
|
|
1182
|
+
cdp.on(
|
|
1183
|
+
"Overlay.inspectNodeRequested",
|
|
1184
|
+
({ backendNodeId }, sessionID) => void dispatchPicker({ type: "node.picked", backendID: backendNodeId, sessionID }),
|
|
1185
|
+
)
|
|
1186
|
+
cdp.on("Target.detachedFromTarget", ({ sessionId }) => {
|
|
1187
|
+
choosers.detach(sessionId)
|
|
1188
|
+
// Only the session that showed the extension's document clears it: the frame keeps its target ID across a swap, and
|
|
1189
|
+
// the web session it replaced may detach after the extension's attached.
|
|
1190
|
+
extensionTargets.delete(sessionId)
|
|
1191
|
+
sessions.forEach((id, frameID) => {
|
|
1192
|
+
if (id === sessionId) {
|
|
1193
|
+
sessions.delete(frameID)
|
|
1194
|
+
parents.delete(frameID)
|
|
1195
|
+
}
|
|
1196
|
+
})
|
|
1197
|
+
})
|
|
1198
|
+
cdp.on("Page.javascriptDialogOpening", (event) =>
|
|
1199
|
+
dispatchDialog({
|
|
1200
|
+
type: "dialog.opened",
|
|
1201
|
+
url: displayURL(event.url),
|
|
1202
|
+
dialogType: event.type,
|
|
1203
|
+
message: event.message.slice(0, Browser.MAX_TEXT),
|
|
1204
|
+
defaultPrompt: event.defaultPrompt ?? "",
|
|
1205
|
+
at: Date.now(),
|
|
1206
|
+
}),
|
|
1207
|
+
)
|
|
1208
|
+
cdp.on("Page.javascriptDialogClosed", () => {
|
|
1209
|
+
dialogs.closed()
|
|
1210
|
+
dispatchDialog({ type: "dialog.closed", at: Date.now() })
|
|
1211
|
+
})
|
|
1212
|
+
contents.on("did-navigate", () => dispatchDialog({ type: "document.committed" }))
|
|
1213
|
+
// Hidden tabs keep a desktop-sized viewport until the renderer lays the embed out.
|
|
1214
|
+
view.setBounds({ x: 0, y: 0, width: 1000, height: 700 })
|
|
1215
|
+
const embed = options.embeds.create(view, win)
|
|
1216
|
+
constructing.defer(() => embed.dispose())
|
|
1217
|
+
|
|
1218
|
+
const handoff = () => {
|
|
1219
|
+
if (closed() || contents.isDestroyed()) return
|
|
1220
|
+
const tab = state()
|
|
1221
|
+
const actual = contents.getURL()
|
|
1222
|
+
|
|
1223
|
+
return pageHandoff(actual, displayURL(actual), tab.url, !!tab.loadError, options.local)
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
const openPage = async (expected: string) => {
|
|
1227
|
+
const target = handoff()
|
|
1228
|
+
|
|
1229
|
+
if (!target || target.url !== expected) throw new Error("browser.menu.failed")
|
|
1230
|
+
|
|
1231
|
+
if (target.kind === "web") return electron.shell.openExternal(target.url)
|
|
1232
|
+
|
|
1233
|
+
const actual = contents.getURL()
|
|
1234
|
+
const launch = await defaultBrowser()
|
|
1235
|
+
|
|
1236
|
+
const opened = await options.workspace?.external(actual, async (file) => {
|
|
1237
|
+
if (handoff()?.url !== expected || contents.getURL() !== actual) throw new Error("browser.menu.failed")
|
|
1238
|
+
await launch(file)
|
|
1239
|
+
})
|
|
1240
|
+
|
|
1241
|
+
if (!opened) throw new Error("browser.menu.failed")
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
const personCommand = () => {
|
|
1245
|
+
recordPageInput(activity, "user")
|
|
1246
|
+
options.userInput()
|
|
1247
|
+
void choosers.update().catch(() => undefined)
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
const menu = attachPageMenu(win, contents, {
|
|
1251
|
+
...options.menu,
|
|
1252
|
+
personCommand,
|
|
1253
|
+
canOpenPage: () => !!handoff(),
|
|
1254
|
+
openPage: () => openPage(state().url),
|
|
1255
|
+
open: (url) => {
|
|
1256
|
+
const current = contents.getURL()
|
|
1257
|
+
|
|
1258
|
+
if (options.workspace?.host(current) && /^(?:file|workspace):/.test(url) && !options.workspace.permits(current, url)) {
|
|
1259
|
+
notices.show({reason:"browser.preview.restricted"})
|
|
1260
|
+
|
|
1261
|
+
return Promise.resolve()
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
return options.menu.open(url)
|
|
1265
|
+
},
|
|
1266
|
+
policy: {
|
|
1267
|
+
get fileRoots() { return policy.fileRoots },
|
|
1268
|
+
get extensions() { return policy.extensions },
|
|
1269
|
+
remote: policy.remote,
|
|
1270
|
+
get previewHost() { return options.workspace?.host(contents.getURL()) },
|
|
1271
|
+
local: options.local,
|
|
1272
|
+
},
|
|
1273
|
+
cdp,
|
|
1274
|
+
sessions: () => sessions.values(),
|
|
1275
|
+
available: () => nativeMenu && !closed() && view.getVisible() && activity.agentRuns === 0,
|
|
1276
|
+
failed: () => publish("browser.menu.failed"),
|
|
1277
|
+
})
|
|
1278
|
+
|
|
1279
|
+
constructing.defer(() => menu.dispose())
|
|
1280
|
+
|
|
1281
|
+
// A hidden page cannot be picked from, and a comment's frozen still already shows the
|
|
1282
|
+
// picked element, so hiding ends the picker, any pick in progress, and the highlight.
|
|
1283
|
+
embed.on("visible", (visible) => {
|
|
1284
|
+
if (visible) {
|
|
1285
|
+
// Not while a prompt still shows: the view shows between two dialogs, and the next one takes the keyboard.
|
|
1286
|
+
if (refocus && !prompts.showing()) {
|
|
1287
|
+
refocus = false
|
|
1288
|
+
options.focusPage?.()
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
return
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
menu.close()
|
|
1295
|
+
void dispatchPicker({ type: "embed.hidden" })
|
|
1296
|
+
|
|
1297
|
+
if (!closed()) options.hidden?.()
|
|
1298
|
+
})
|
|
1299
|
+
|
|
1300
|
+
const navigation = navigationTurn(options.waitForFilters, url => {
|
|
1301
|
+
dispatch({ type: "navigation.started", url, isMainFrame: true, isSameDocument: false })
|
|
1302
|
+
dispatch({ type: "loading.started" })
|
|
1303
|
+
}, () => { if (!closed()) dispatch({ type: "loading.stopped", title: pageTitle() }) }, address => {
|
|
1304
|
+
dispatch({ type: "navigation.held-stopped", address })
|
|
1305
|
+
})
|
|
1306
|
+
|
|
1307
|
+
const begin = (signal = options.signal, keepAddress = false) => navigation.begin(AbortSignal.any([pageLifetime.signal, signal, options.signal]), keepAddress)
|
|
1308
|
+
|
|
1309
|
+
const load = async (url: string, retry = false, commandSignal = options.signal, keepAddress = true, deadlineMs?: number) => {
|
|
1310
|
+
const visit = begin(commandSignal, keepAddress)
|
|
1311
|
+
const destination = url.startsWith("artifact:") ? options.artifacts?.load(url) : localFileURL(url) || url.startsWith("workspace:") ? await options.workspace?.load(url, () => notices.show({ reason: "browser.preview.restricted" }), retry ? contents.getURL() : undefined) : url
|
|
1312
|
+
|
|
1313
|
+
if (!destination) return Promise.reject(new Error("Workspace preview is unavailable."))
|
|
1314
|
+
|
|
1315
|
+
return visit(destination, () => loadDestination(destination, url, deadlineMs))
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
const loadDestination = (destination: string, url: string, deadlineMs?: number) => {
|
|
1319
|
+
if (options.artifacts?.display(destination)) {
|
|
1320
|
+
artifactHost = new URL(destination).host
|
|
1321
|
+
contents.setWebRTCIPHandlingPolicy("disable_non_proxied_udp")
|
|
1322
|
+
// On first restore Chromium has no renderer yet. Its binding cannot answer until loadURL starts it.
|
|
1323
|
+
// The script only offers links; the native navigation and network fences above apply before the load.
|
|
1324
|
+
void registerArtifactLinks(artifactHost).catch(() => options.warn?.("Artifact link offers are unavailable"))
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
let committed = false
|
|
1328
|
+
|
|
1329
|
+
const commit = () => {
|
|
1330
|
+
committed = true
|
|
1331
|
+
|
|
1332
|
+
// Only a successful navigation directed by browser chrome (this loadURL), not a renderer callback, may leave.
|
|
1333
|
+
if (!options.artifacts?.display(destination)) artifactHost = undefined
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
contents.once("did-navigate", commit)
|
|
1337
|
+
const next = replacementNavigation()
|
|
1338
|
+
contents.on("did-start-navigation", next.start)
|
|
1339
|
+
contents.on("did-navigate", next.commit)
|
|
1340
|
+
contents.on("did-stop-loading", next.stop)
|
|
1341
|
+
contents.once("destroyed", next.stop)
|
|
1342
|
+
|
|
1343
|
+
return navigationDeadline(contents.loadURL(destination).catch(async (error: Error) => {
|
|
1344
|
+
if (committedLoad(error, committed)) return
|
|
1345
|
+
|
|
1346
|
+
if (destinationOrigin(destination) && await next.after(error)) return
|
|
1347
|
+
|
|
1348
|
+
if (options.previewFailure?.(destination)) throw new FileVerificationError()
|
|
1349
|
+
|
|
1350
|
+
if (destination.startsWith(`${previewScheme}://`))
|
|
1351
|
+
throw new CodedError(Browser.FailureCode.previewUnavailable, `The preview could not be loaded: ${url}`)
|
|
1352
|
+
|
|
1353
|
+
if (!committed && "errno" in error && (error.errno === -2 || error.errno === -3))
|
|
1354
|
+
throw new CodedError("navigation_failed", "No page committed. The navigation was cancelled, failed, or became a download. Check the tab and its downloads before navigating again.")
|
|
1355
|
+
throw error
|
|
1356
|
+
}), deadlineMs).finally(() => {
|
|
1357
|
+
next.stop()
|
|
1358
|
+
contents.off("destroyed", next.stop)
|
|
1359
|
+
contents.off("did-stop-loading", next.stop)
|
|
1360
|
+
contents.off("did-navigate", next.commit)
|
|
1361
|
+
contents.off("did-start-navigation", next.start)
|
|
1362
|
+
contents.off("did-navigate", commit)
|
|
1363
|
+
})
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
const reload = async (signal = options.signal, ignoreCache = false) => {
|
|
1367
|
+
const tab = state()
|
|
1368
|
+
|
|
1369
|
+
if (documentState.status !== "closed" && documentState.retry) return load(documentState.retry, true, signal)
|
|
1370
|
+
|
|
1371
|
+
if (tab.loadError && /^(?:file|workspace|artifact):/.test(tab.url)) return void await load(tab.url, true, signal)
|
|
1372
|
+
const actual = contents.getURL()
|
|
1373
|
+
|
|
1374
|
+
if (options.workspace?.host(actual) && options.workspace.display(actual) === tab.url) return void await load(tab.url, true, signal)
|
|
1375
|
+
const address = reloadAddress(actual, tab.url, options.workspace?.host(actual), policy.fileRoots ?? [], policy.remote)
|
|
1376
|
+
|
|
1377
|
+
if (address) return void await load(address, true, signal)
|
|
1378
|
+
|
|
1379
|
+
return begin(signal)(actual, () => ignoreCache ? contents.reloadIgnoringCache() : contents.reload())
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
const ready = navigationDeadline(Promise.all([
|
|
1383
|
+
files.ready,
|
|
1384
|
+
...(initial === undefined
|
|
1385
|
+
? []
|
|
1386
|
+
: [
|
|
1387
|
+
load(initial).then(async () => {
|
|
1388
|
+
// Stop before the first load leaves no renderer to finish CDP setup. Start only the inert document;
|
|
1389
|
+
// its native events are not a navigation of the saved tab.
|
|
1390
|
+
if (documentState.status !== "restoring" || !documentState.retry || contents.getURL() || closed()) return
|
|
1391
|
+
startingBlank = true
|
|
1392
|
+
await contents.loadURL("about:blank").finally(() => { startingBlank = false })
|
|
1393
|
+
}).catch((error: Error) => {
|
|
1394
|
+
if (!options.restore) throw error
|
|
1395
|
+
// A dev server may have stopped while this page was unloaded. Keep its tab available to retry. The tab
|
|
1396
|
+
// itself reports a load that failed or is still under way; anything else is said beside it.
|
|
1397
|
+
publish(pageReports(error) ? undefined : error.message)
|
|
1398
|
+
}),
|
|
1399
|
+
]),
|
|
1400
|
+
diagnostics.enable(),
|
|
1401
|
+
choosers.attach(),
|
|
1402
|
+
media.attach(),
|
|
1403
|
+
passkeys.attach(),
|
|
1404
|
+
cdp.send("Page.enable"),
|
|
1405
|
+
cdp.send("Page.addScriptToEvaluateOnNewDocument", { source: RESTORE_PROMPT, runImmediately: true }),
|
|
1406
|
+
cdp.send("DOM.enable"),
|
|
1407
|
+
attachFrames(),
|
|
1408
|
+
])).then(() => undefined).finally(() => opening?.[Symbol.dispose]())
|
|
1409
|
+
|
|
1410
|
+
// A page that never became ready stopped too, and says what failed.
|
|
1411
|
+
void ready.catch((cause: unknown) => end(setupFailure(cause)))
|
|
1412
|
+
|
|
1413
|
+
constructing.move()
|
|
1414
|
+
|
|
1415
|
+
return {
|
|
1416
|
+
view,
|
|
1417
|
+
contents,
|
|
1418
|
+
nativeID: contents.id,
|
|
1419
|
+
/**
|
|
1420
|
+
* The top edge of the page's view in the window's content, once it has been placed, while the page fills the
|
|
1421
|
+
* pane's page area. Undefined with a device viewport, whose page sits inside that area, lower than its top.
|
|
1422
|
+
*/
|
|
1423
|
+
areaTop: () => (metrics.applied().viewport.mode === "auto" && view.getBounds().height > 0 ? view.getBounds().y : undefined),
|
|
1424
|
+
state: () => state(true),
|
|
1425
|
+
childActivity: () => childActivity(activity),
|
|
1426
|
+
answerNotice: notices.answer,
|
|
1427
|
+
personCommand,
|
|
1428
|
+
openPage,
|
|
1429
|
+
reviewLink: (url: string) => notices.show(navigationNotice(url, policy, "conversation")),
|
|
1430
|
+
/** Refuses passkeys in the browser process from now on, for a tab the agent drives or a tab that can script one. */
|
|
1431
|
+
restrictPasskeys,
|
|
1432
|
+
ready,
|
|
1433
|
+
/** Keeps the page's process memory from `app.getAppMetrics()`, which lists a process only while it runs. */
|
|
1434
|
+
sampleMemory: (metrics: readonly Electron.ProcessMetric[]) => {
|
|
1435
|
+
if (!closed() && !contents.isDestroyed()) journal.sample(processMemory(metrics, contents.getOSProcessId()))
|
|
1436
|
+
},
|
|
1437
|
+
focusHost,
|
|
1438
|
+
setViewport,
|
|
1439
|
+
/** The host embed the renderer lays this page out with. */
|
|
1440
|
+
embed: embed.id,
|
|
1441
|
+
async inspect(enabled: boolean) {
|
|
1442
|
+
if (closed()) return
|
|
1443
|
+
await ready
|
|
1444
|
+
await dispatchPicker({ type: "inspect.set", enabled })
|
|
1445
|
+
},
|
|
1446
|
+
async highlight(ref?: Browser.Ref) {
|
|
1447
|
+
if (closed()) return
|
|
1448
|
+
await dispatchPicker({ type: "highlight.requested", target: ref ? picked.get(ref.replace(/^@/, "")) : undefined })
|
|
1449
|
+
},
|
|
1450
|
+
zoom(direction: "in" | "out" | "reset") {
|
|
1451
|
+
if (!closed()) zoom(direction)
|
|
1452
|
+
},
|
|
1453
|
+
async site() {
|
|
1454
|
+
if (closed() || retryOnly(documentState)) return { cookies: 0 }
|
|
1455
|
+
const url = contents.getURL()
|
|
1456
|
+
|
|
1457
|
+
if (!destinationOrigin(url)) return { cookies: 0 }
|
|
1458
|
+
|
|
1459
|
+
return { cookies: (await contents.session.cookies.get({ url })).length }
|
|
1460
|
+
},
|
|
1461
|
+
/**
|
|
1462
|
+
* Deletes what the page's site stored: the cookies its address can read, and its origin's storage. Resolves once
|
|
1463
|
+
* the page reloaded without them, so a count read next includes what the reload set again.
|
|
1464
|
+
*/
|
|
1465
|
+
async clearSite() {
|
|
1466
|
+
if (closed() || retryOnly(documentState)) return
|
|
1467
|
+
const url = contents.getURL()
|
|
1468
|
+
const origin = destinationOrigin(url)
|
|
1469
|
+
|
|
1470
|
+
if (!origin) return
|
|
1471
|
+
const cookies = await contents.session.cookies.get({ url })
|
|
1472
|
+
await Promise.all(cookies.map((cookie) => contents.session.cookies.remove(cookieURL(cookie), cookie.name)))
|
|
1473
|
+
await contents.session.clearStorageData({
|
|
1474
|
+
origin,
|
|
1475
|
+
storages: ["localstorage", "indexdb", "serviceworkers", "cachestorage", "filesystem", "shadercache"],
|
|
1476
|
+
})
|
|
1477
|
+
// The site's HTTP sign-in too. Chromium clears its auth cache only whole, so other sites ask again as well.
|
|
1478
|
+
await contents.session.clearAuthCache()
|
|
1479
|
+
|
|
1480
|
+
if (closed()) return
|
|
1481
|
+
await options.menu.navigate("reload")
|
|
1482
|
+
// A slow page still cleared; the count then reads what it set so far.
|
|
1483
|
+
await waitFor(() => closed() || !contents.isLoading(), new AbortController().signal, 30_000).catch(
|
|
1484
|
+
() => undefined,
|
|
1485
|
+
)
|
|
1486
|
+
},
|
|
1487
|
+
/** Refreshes the page presentation, including Chromium's per-origin zoom. */
|
|
1488
|
+
detail,
|
|
1489
|
+
/** Takes a download this page started; see `guardSession`. */
|
|
1490
|
+
download,
|
|
1491
|
+
/** Answers this page's permission requests and checks; see `guardSession`. */
|
|
1492
|
+
permissions: prompts.permissions,
|
|
1493
|
+
/** The user's answer to what the tab waits for; only the window calls it. */
|
|
1494
|
+
answer: prompts.answer,
|
|
1495
|
+
/** Whether the user's close may go ahead, or the page asked "Leave site?". */
|
|
1496
|
+
leave: prompts.leave,
|
|
1497
|
+
/**
|
|
1498
|
+
* Runs one command, the agent's or the user's. The agent's never opens, reads or acts on an extension page, which
|
|
1499
|
+
* would run with that extension's privileges; every agent operation reaches the page through here.
|
|
1500
|
+
*/
|
|
1501
|
+
async execute(command: Browser.Command, signal: AbortSignal, origin: "agent" | "user"): Promise<Browser.Result> {
|
|
1502
|
+
using active = new DisposableStack()
|
|
1503
|
+
active.defer(journal.operation(command.action.type, origin))
|
|
1504
|
+
|
|
1505
|
+
const hidden = !view.getVisible() && win.isVisible() && !win.isMinimized() && !(process.platform === "darwin" && electron.app.isHidden())
|
|
1506
|
+
const shouldPaint = () => needsWakeFrame(command.action.type, documentState.status === "loaded" && !documentState.busy && !documentState.pending, !!selectOpenDialog(dialogGate))
|
|
1507
|
+
|
|
1508
|
+
const hold = origin === "agent" ? active.use(rendering.hold(hidden && shouldPaint() ? async () => {
|
|
1509
|
+
await ready
|
|
1510
|
+
|
|
1511
|
+
if (!shouldPaint() || agentRefusal({ type: "snapshot" }, mainDocument())) return
|
|
1512
|
+
await withFrames(false, pageLifetime.signal, async stop => {
|
|
1513
|
+
const frame = (await cdp.send("Page.getFrameTree")).frameTree.frame.id
|
|
1514
|
+
const world = await cdp.send("Page.createIsolatedWorld", { frameId: frame, worldName: "opencode-browser-paint" })
|
|
1515
|
+
abortError(stop)
|
|
1516
|
+
await cdp.send("Runtime.evaluate", { contextId: world.executionContextId, expression: "new Promise(done => requestAnimationFrame(() => requestAnimationFrame(() => done())))", awaitPromise: true })
|
|
1517
|
+
})
|
|
1518
|
+
} : undefined)) : undefined
|
|
1519
|
+
|
|
1520
|
+
const saved = navigation.interrupt(command.action.type, documentState.status === "restoring" ? documentState.url : undefined, origin)
|
|
1521
|
+
await Promise.all([ready, hold?.painted])
|
|
1522
|
+
const open = origin === "user" && leavable.includes(command.action.type) ? selectOpenDialog(dialogGate) : undefined
|
|
1523
|
+
|
|
1524
|
+
// The user leaving the page dismisses its dialog, as a browser's address bar does.
|
|
1525
|
+
if (open) await answerDialog(open.revision, false, "", false)
|
|
1526
|
+
|
|
1527
|
+
// Registers the run before any further await, and listens for its abort in the same turn, so a dialog or a
|
|
1528
|
+
// cancellation that arrives while it still inspects its target interrupts it.
|
|
1529
|
+
const reply = dispatchDialog({ type: "run.started", actionType: command.action.type, aborted: signal.aborted }).reply
|
|
1530
|
+
|
|
1531
|
+
if (reply?.status !== "accepted") throw runStopError(reply?.reason ?? "closed")
|
|
1532
|
+
const runID = reply.runID
|
|
1533
|
+
// The action underneath the race keeps running after an interruption wins it; it checks this
|
|
1534
|
+
// signal before each further step.
|
|
1535
|
+
const run = { controller: new AbortController(), interrupted: Promise.withResolvers<never>(), origin }
|
|
1536
|
+
runs.set(runID, run)
|
|
1537
|
+
const cancel = () => dispatchDialog({ type: "run.cancelled", runID })
|
|
1538
|
+
signal.addEventListener("abort", cancel, { once: true })
|
|
1539
|
+
|
|
1540
|
+
// A `wait` is the agent's command but only observes: the page gets no input from it, for up to 30 s. It is not
|
|
1541
|
+
// counted as the agent acting, so the person's own press, download or app link during it stays theirs.
|
|
1542
|
+
const acting = origin === "agent" && command.action.type !== "wait"
|
|
1543
|
+
|
|
1544
|
+
if (origin === "agent") recordPageInput(activity, origin)
|
|
1545
|
+
|
|
1546
|
+
if (acting) activity.agentRuns++
|
|
1547
|
+
|
|
1548
|
+
// The user's navigation may stop for "Leave site?"; the agent's stops when the site asks the user to sign in.
|
|
1549
|
+
if (origin === "user" && leavable.includes(command.action.type)) prompts.intend(command.action)
|
|
1550
|
+
|
|
1551
|
+
if (origin === "agent") prompts.agentStarted()
|
|
1552
|
+
const signIn = origin === "agent" ? prompts.agentWait(leavable.includes(command.action.type)) : undefined
|
|
1553
|
+
|
|
1554
|
+
try {
|
|
1555
|
+
const intercepting = choosers.update()
|
|
1556
|
+
|
|
1557
|
+
// Updating the file chooser intercept is a renderer call, which an open dialog blocks until it is answered.
|
|
1558
|
+
if (command.action.type === "dialog") void intercepting.catch(() => undefined)
|
|
1559
|
+
|
|
1560
|
+
return await Promise.race([
|
|
1561
|
+
// The agent drives the tab from here on: refuse passkeys in the browser process before its action runs. The
|
|
1562
|
+
// refusal is the browser process's own command, which an open dialog does not block.
|
|
1563
|
+
afterRefusal(origin === "agent" ? restrictPasskeys : undefined, command.action.type === "dialog" ? Promise.resolve() : intercepting, () => {
|
|
1564
|
+
abortError(run.controller.signal)
|
|
1565
|
+
const act = () => perform(command, run.controller.signal, origin, saved)
|
|
1566
|
+
|
|
1567
|
+
// A resize or screenshot between measuring a ref and clicking it would hit a different point.
|
|
1568
|
+
return pointerOperations.includes(command.action.type) ? metrics.exclusive(() => device.mouse(act)) : act()
|
|
1569
|
+
}),
|
|
1570
|
+
run.interrupted.promise,
|
|
1571
|
+
...(signIn ? [signIn.promise] : []),
|
|
1572
|
+
])
|
|
1573
|
+
} finally {
|
|
1574
|
+
signIn?.stop()
|
|
1575
|
+
signal.removeEventListener("abort", cancel)
|
|
1576
|
+
runs.delete(runID)
|
|
1577
|
+
dispatchDialog({ type: "run.finished", runID })
|
|
1578
|
+
|
|
1579
|
+
if (acting) activity.agentRuns--
|
|
1580
|
+
|
|
1581
|
+
if (origin === "agent") void choosers.update().catch(() => undefined)
|
|
1582
|
+
}
|
|
1583
|
+
},
|
|
1584
|
+
async dispose() {
|
|
1585
|
+
if (closed()) return
|
|
1586
|
+
pageLifetime.abort()
|
|
1587
|
+
notices.clear()
|
|
1588
|
+
// Even a failed cleanup of an embed, recorder or already detached debugger must not orphan its native page.
|
|
1589
|
+
using closing = new DisposableStack()
|
|
1590
|
+
closing.defer(() => { if (!contents.isDestroyed()) contents.close({ waitForBeforeUnload: false }) })
|
|
1591
|
+
dispatch({ type: "disposed" })
|
|
1592
|
+
menu.dispose()
|
|
1593
|
+
choosers.dispose()
|
|
1594
|
+
media.dispose()
|
|
1595
|
+
passkeys.dispose()
|
|
1596
|
+
options.artifacts?.dispose()
|
|
1597
|
+
options.workspace?.dispose()
|
|
1598
|
+
dispatchDialog({ type: "disposed" })
|
|
1599
|
+
prompts.dispose()
|
|
1600
|
+
dialogs.dispose()
|
|
1601
|
+
void dispatchPicker({ type: "disposed" })
|
|
1602
|
+
clearTimeout(pickerTimer)
|
|
1603
|
+
view.off("bounds-changed", resize)
|
|
1604
|
+
detachNetwork?.()
|
|
1605
|
+
await profiling.dispose()
|
|
1606
|
+
cdp.dispose()
|
|
1607
|
+
refs.clear()
|
|
1608
|
+
picked.clear()
|
|
1609
|
+
embed.dispose()
|
|
1610
|
+
|
|
1611
|
+
await files.dispose()
|
|
1612
|
+
},
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
async function perform(command: Browser.Command, signal: AbortSignal, origin: "agent" | "user", saved?: string) {
|
|
1616
|
+
if (origin === "user") return attempt(command, signal, origin, saved)
|
|
1617
|
+
|
|
1618
|
+
// An error document has no inspectable frame. Report the artifact failure before querying Chromium.
|
|
1619
|
+
if (state().loadError === FileVerificationError.code && !leavable.includes(command.action.type)) throw new FileVerificationError()
|
|
1620
|
+
|
|
1621
|
+
if (state().loadError === "browser.artifact.missing" && !leavable.includes(command.action.type)) throw missingArtifact()
|
|
1622
|
+
const refused = agentRefusal(command.action, mainDocument())
|
|
1623
|
+
|
|
1624
|
+
if (refused) throw new Error(refused)
|
|
1625
|
+
const used = actionFrames(command.action)
|
|
1626
|
+
const framed = await extensionFrameRefusal(used)
|
|
1627
|
+
|
|
1628
|
+
if (framed) throw new Error(framed)
|
|
1629
|
+
const result = await attempt(command, signal, origin, saved)
|
|
1630
|
+
// A redirect, or a navigation while it ran, may have brought an extension page in, in the tab or in a frame the
|
|
1631
|
+
// action used; its result stays here.
|
|
1632
|
+
const moved = agentRefusal({ type: "snapshot" }, mainDocument()) ?? (await extensionFrameRefusal(used))
|
|
1633
|
+
|
|
1634
|
+
if (moved) throw new Error(moved)
|
|
1635
|
+
|
|
1636
|
+
return result
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
function mainDocument() {
|
|
1640
|
+
return { url: contents.mainFrame.url, origin: contents.mainFrame.origin }
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
async function mainContext() {
|
|
1644
|
+
const context = contexts.get((await cdp.send("Page.getFrameTree")).frameTree.frame.id)
|
|
1645
|
+
|
|
1646
|
+
if (!context)
|
|
1647
|
+
throw new CodedError(
|
|
1648
|
+
Browser.FailureCode.documentChanged,
|
|
1649
|
+
"The page's JavaScript context is unavailable; it may be loading. Wait for it with browser.wait({tabID}), then retry.",
|
|
1650
|
+
)
|
|
1651
|
+
|
|
1652
|
+
return context
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
async function attempt(command: Browser.Command, signal: AbortSignal, origin: "agent" | "user", saved?: string): Promise<Browser.Result> {
|
|
1656
|
+
abortError(signal)
|
|
1657
|
+
|
|
1658
|
+
if (isPickerActive(pickerState) && pointerOperations.includes(command.action.type))
|
|
1659
|
+
await dispatchPicker({ type: "pointer.command" })
|
|
1660
|
+
|
|
1661
|
+
if (command.inspect) return { value: await inspect(command.action), files: [] }
|
|
1662
|
+
|
|
1663
|
+
if (command.target && JSON.stringify(await inspect(command.action)) !== JSON.stringify(command.target))
|
|
1664
|
+
throw new Error(
|
|
1665
|
+
"Browser target changed while permission was pending. Take a fresh snapshot or listing and request the action again; it was not executed.",
|
|
1666
|
+
)
|
|
1667
|
+
|
|
1668
|
+
if (
|
|
1669
|
+
command.generation !== undefined &&
|
|
1670
|
+
command.generation !== documentGeneration(documentState) &&
|
|
1671
|
+
!retainedOperations.includes(command.action.type)
|
|
1672
|
+
)
|
|
1673
|
+
throw new CodedError(
|
|
1674
|
+
Browser.FailureCode.documentChanged,
|
|
1675
|
+
"The document changed before this operation ran. Call browser.tabs.list({}) to check its current URL, then browser.snapshot({tabID}) for fresh refs. Reconsider the action before retrying on the new page.",
|
|
1676
|
+
)
|
|
1677
|
+
abortError(signal)
|
|
1678
|
+
|
|
1679
|
+
return execute(command.action, command.files, signal, origin, command.target, saved)
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
async function execute(
|
|
1683
|
+
action: Browser.Action,
|
|
1684
|
+
transfers: readonly Browser.File[],
|
|
1685
|
+
signal: AbortSignal,
|
|
1686
|
+
origin: "agent" | "user",
|
|
1687
|
+
approved?: Browser.Target,
|
|
1688
|
+
saved?: string,
|
|
1689
|
+
): Promise<Browser.Result> {
|
|
1690
|
+
const captureSources = sourceURLs()
|
|
1691
|
+
const transfer = (id: Browser.FileID) => files.transfer(id, approved?.resources)
|
|
1692
|
+
const input = dispatchInput(origin, signal)
|
|
1693
|
+
|
|
1694
|
+
const result = <T>(value: T, attached: Browser.File[] = []): Browser.Result => {
|
|
1695
|
+
const json = Schema.decodeUnknownSync(Schema.Json)(value)
|
|
1696
|
+
|
|
1697
|
+
if (JSON.stringify(json).length > 512_000)
|
|
1698
|
+
throw new Error(
|
|
1699
|
+
"Browser result exceeds 512000 JSON characters. Request fewer entries, reduce snapshot depth, or return only selected fields from the evaluation script. Repeating the same request will not reduce its output.",
|
|
1700
|
+
)
|
|
1701
|
+
|
|
1702
|
+
return { value: json, files: attached }
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
switch (action.type) {
|
|
1706
|
+
case "navigate": {
|
|
1707
|
+
const url = normalizeURL(action.url, policy)
|
|
1708
|
+
const cancel = () => contents.stop()
|
|
1709
|
+
signal.addEventListener("abort", cancel, { once: true })
|
|
1710
|
+
|
|
1711
|
+
try {
|
|
1712
|
+
await load(url, false, signal, origin === "user", options.navigationDeadlineMs)
|
|
1713
|
+
} finally {
|
|
1714
|
+
signal.removeEventListener("abort", cancel)
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
// The load event comes just before Chromium says the tab stopped loading; report the tab after that. A frame that
|
|
1718
|
+
// still loads after a moment is reported as loading, which it is.
|
|
1719
|
+
await waitFor(() => !contents.isLoading(), signal, 2_000).catch(() => abortError(signal))
|
|
1720
|
+
|
|
1721
|
+
return result(state())
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
case "back":
|
|
1725
|
+
case "forward":
|
|
1726
|
+
case "reload":
|
|
1727
|
+
case "stop": {
|
|
1728
|
+
if (action.type === "back" || action.type === "forward") {
|
|
1729
|
+
const history = contents.navigationHistory
|
|
1730
|
+
const index = history.getActiveIndex() + (action.type === "back" ? -1 : 1)
|
|
1731
|
+
const entry = index >= 0 && index < history.length() && history.getEntryAtIndex(index)
|
|
1732
|
+
|
|
1733
|
+
if (entry) await begin(signal)(entry.url, () => history.goToIndex(index), () => !closed() && contents.isLoading())
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
if (action.type === "reload" && (!saved || action.ignoreCache)) await reload(signal, action.ignoreCache)
|
|
1737
|
+
|
|
1738
|
+
if (action.type === "stop") {
|
|
1739
|
+
navigation.cancel()
|
|
1740
|
+
contents.stop()
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
if (action.type !== "stop") await waitFor(() => !contents.isLoading(), signal, 30_000)
|
|
1744
|
+
|
|
1745
|
+
// As the inventory reports the tab: an address kept for a load that was never issued stays its address.
|
|
1746
|
+
return result(state(true))
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
case "frames":
|
|
1750
|
+
return result({ tab: state(), frames: await frames() })
|
|
1751
|
+
case "snapshot":
|
|
1752
|
+
case "find":
|
|
1753
|
+
return result({ tab: state(), ...(await snapshot(action, signal)) })
|
|
1754
|
+
case "evaluate": {
|
|
1755
|
+
if (action.ref && action.frameID)
|
|
1756
|
+
throw new Error(
|
|
1757
|
+
"Pass either ref or frameID to browser.evaluate, not both. A ref already runs in its element's frame.",
|
|
1758
|
+
)
|
|
1759
|
+
const context = action.frameID ? await frameContext(action.frameID) : undefined
|
|
1760
|
+
// Pinned to the main frame's current document, so a navigation to an extension page meanwhile fails the call
|
|
1761
|
+
// instead of running the script there.
|
|
1762
|
+
const main = action.frameID || action.ref ? undefined : await mainContext()
|
|
1763
|
+
const element = action.ref ? target(action.ref) : undefined
|
|
1764
|
+
const objectId = element ? await resolve(element) : undefined
|
|
1765
|
+
|
|
1766
|
+
// With a ref, the script is a function that receives the element as its argument and as `this`.
|
|
1767
|
+
const value = await (element && objectId
|
|
1768
|
+
? cdp
|
|
1769
|
+
.send(
|
|
1770
|
+
"Runtime.callFunctionOn",
|
|
1771
|
+
{
|
|
1772
|
+
objectId,
|
|
1773
|
+
functionDeclaration: connectedFunction(action.script),
|
|
1774
|
+
arguments: [{ objectId }],
|
|
1775
|
+
awaitPromise: true,
|
|
1776
|
+
returnByValue: true,
|
|
1777
|
+
},
|
|
1778
|
+
element.sessionID,
|
|
1779
|
+
)
|
|
1780
|
+
.finally(() => cdp.send("Runtime.releaseObject", { objectId }, element.sessionID).catch(() => undefined))
|
|
1781
|
+
: cdp.send(
|
|
1782
|
+
"Runtime.evaluate",
|
|
1783
|
+
{
|
|
1784
|
+
expression: action.script,
|
|
1785
|
+
contextId: (context ?? main)?.id,
|
|
1786
|
+
awaitPromise: true,
|
|
1787
|
+
returnByValue: true,
|
|
1788
|
+
},
|
|
1789
|
+
context?.sessionID,
|
|
1790
|
+
))
|
|
1791
|
+
|
|
1792
|
+
if (element && value.exceptionDetails?.exception?.description?.startsWith("Error: browser.detached_ref\n")) throw detachedRef()
|
|
1793
|
+
|
|
1794
|
+
if (value.exceptionDetails)
|
|
1795
|
+
throw new Error(
|
|
1796
|
+
`Page JavaScript threw an exception. Check the script and ${action.ref ? "ref" : "frameID"}; inspect the page before repeating code with side effects. Details: ${(value.exceptionDetails.exception?.description ?? value.exceptionDetails.text).slice(0, 800)}`,
|
|
1797
|
+
)
|
|
1798
|
+
abortError(signal)
|
|
1799
|
+
|
|
1800
|
+
return result({ tab: state(), value: value.result.value ?? null })
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
case "click":
|
|
1804
|
+
await click(input, target(action.ref), action.button ?? "left", action.count ?? 1, action.modifiers)
|
|
1805
|
+
break
|
|
1806
|
+
case "hover":
|
|
1807
|
+
await input("Input.dispatchMouseEvent", { type: "mouseMoved", ...(await point(target(action.ref))) })
|
|
1808
|
+
break
|
|
1809
|
+
case "drag": {
|
|
1810
|
+
const source = target(action.from)
|
|
1811
|
+
const destination = target(action.to)
|
|
1812
|
+
await point(destination)
|
|
1813
|
+
const from = await point(source)
|
|
1814
|
+
const box = await rect(destination)
|
|
1815
|
+
const to = await elementCenter(box)
|
|
1816
|
+
const html5 = await call(source, "function() { return this.draggable; }")
|
|
1817
|
+
let data: Protocol.Input.DragData | undefined
|
|
1818
|
+
|
|
1819
|
+
const off = cdp.on("Input.dragIntercepted", (event) => {
|
|
1820
|
+
data = event.data
|
|
1821
|
+
})
|
|
1822
|
+
|
|
1823
|
+
await cdp.send("Input.setInterceptDrags", { enabled: true })
|
|
1824
|
+
|
|
1825
|
+
try {
|
|
1826
|
+
await input("Input.dispatchMouseEvent", { type: "mouseMoved", ...from })
|
|
1827
|
+
await input("Input.dispatchMouseEvent", {
|
|
1828
|
+
type: "mousePressed",
|
|
1829
|
+
...from,
|
|
1830
|
+
button: "left",
|
|
1831
|
+
buttons: 1,
|
|
1832
|
+
clickCount: 1,
|
|
1833
|
+
})
|
|
1834
|
+
|
|
1835
|
+
for (let i = 1; i <= 10; i++) {
|
|
1836
|
+
abortError(signal)
|
|
1837
|
+
await input("Input.dispatchMouseEvent", {
|
|
1838
|
+
type: "mouseMoved",
|
|
1839
|
+
x: from.x + ((to.x - from.x) * i) / 10,
|
|
1840
|
+
y: from.y + ((to.y - from.y) * i) / 10,
|
|
1841
|
+
button: "left",
|
|
1842
|
+
buttons: 1,
|
|
1843
|
+
})
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
if (html5) await waitFor(() => data !== undefined, signal, 2_000)
|
|
1847
|
+
|
|
1848
|
+
if (data) {
|
|
1849
|
+
for (const type of ["dragEnter", "dragOver", "drop"] as const)
|
|
1850
|
+
await input("Input.dispatchDragEvent", { type, ...to, data })
|
|
1851
|
+
}
|
|
1852
|
+
} finally {
|
|
1853
|
+
off()
|
|
1854
|
+
await cdp.send("Input.setInterceptDrags", { enabled: false })
|
|
1855
|
+
await input("Input.dispatchMouseEvent", { type: "mouseReleased", ...to, button: "left", clickCount: 1 })
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
break
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
case "fill":
|
|
1862
|
+
await fill(input, target(action.ref), action.text, signal)
|
|
1863
|
+
break
|
|
1864
|
+
case "fill_form":
|
|
1865
|
+
for (const field of action.fields) {
|
|
1866
|
+
abortError(signal)
|
|
1867
|
+
|
|
1868
|
+
if (field.type === "text") await fill(input, target(field.ref), field.value, signal)
|
|
1869
|
+
|
|
1870
|
+
if (field.type === "select") await select(target(field.ref), field.values)
|
|
1871
|
+
|
|
1872
|
+
if (field.type === "check") await check(input, target(field.ref), field.checked)
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
break
|
|
1876
|
+
case "select":
|
|
1877
|
+
await select(target(action.ref), action.values)
|
|
1878
|
+
break
|
|
1879
|
+
case "check":
|
|
1880
|
+
await check(input, target(action.ref), action.checked)
|
|
1881
|
+
break
|
|
1882
|
+
case "press":
|
|
1883
|
+
await key(input, action.key)
|
|
1884
|
+
break
|
|
1885
|
+
case "scroll": {
|
|
1886
|
+
const { cssVisualViewport } = await cdp.send("Page.getLayoutMetrics")
|
|
1887
|
+
await input("Input.dispatchMouseEvent", {
|
|
1888
|
+
type: "mouseWheel",
|
|
1889
|
+
...inputCenter({ x: 0, y: 0, width: cssVisualViewport.clientWidth, height: cssVisualViewport.clientHeight }),
|
|
1890
|
+
deltaX: action.deltaX ?? 0,
|
|
1891
|
+
deltaY: action.deltaY,
|
|
1892
|
+
})
|
|
1893
|
+
break
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
case "wait": {
|
|
1897
|
+
if (action.condition === "delay") {
|
|
1898
|
+
await scheduler.wait(action.timeoutMs ?? 0, { signal })
|
|
1899
|
+
break
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
if (action.condition === "url" && action.url === undefined) throw new Error("A URL wait requires a URL pattern.")
|
|
1903
|
+
|
|
1904
|
+
if ((action.condition === "text" || action.condition === "textGone") && !action.text)
|
|
1905
|
+
throw new Error(
|
|
1906
|
+
'browser.wait requires non-empty text for condition "text" or "textGone". Use condition "load" without text to wait for loading.',
|
|
1907
|
+
)
|
|
1908
|
+
const frameID = action.frameID
|
|
1909
|
+
|
|
1910
|
+
// The frame is checked once; its context is read on each poll, so one that turns into an extension's
|
|
1911
|
+
// document while this waits fails the wait.
|
|
1912
|
+
if (frameID) await agentFrameOf(frameID)
|
|
1913
|
+
// Whether a check failed; otherwise the wait ran out of time, which the server reports as met: false.
|
|
1914
|
+
const checks = { failed: false }
|
|
1915
|
+
|
|
1916
|
+
const holds = async () => {
|
|
1917
|
+
if (action.condition === "load") return !contents.isLoading()
|
|
1918
|
+
// A navigation to an extension page while this waits ends it: the text would be that page's.
|
|
1919
|
+
const page = agentRefusal({ type: "wait" }, mainDocument())
|
|
1920
|
+
|
|
1921
|
+
if (page) throw new Error(page)
|
|
1922
|
+
|
|
1923
|
+
if (action.condition === "url") return Browser.matchesURL(state().url, action.url ?? "")
|
|
1924
|
+
const context = frameID ? contexts.get(frameID) : undefined
|
|
1925
|
+
|
|
1926
|
+
if (frameID && (!context || extensionFrames().has(frameID))) {
|
|
1927
|
+
// Names an extension's document by what it is, when that is why the context went.
|
|
1928
|
+
await agentFrameOf(frameID)
|
|
1929
|
+
throw new Error(
|
|
1930
|
+
"Frame context is unavailable. Call browser.frames({tabID}) and use a frameID from this tab.",
|
|
1931
|
+
)
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
const value = await cdp.send(
|
|
1935
|
+
"Runtime.evaluate",
|
|
1936
|
+
{
|
|
1937
|
+
expression: `document.body?.innerText.includes(${JSON.stringify(action.text)}) ?? false`,
|
|
1938
|
+
returnByValue: true,
|
|
1939
|
+
contextId: context?.id,
|
|
1940
|
+
},
|
|
1941
|
+
context?.sessionID,
|
|
1942
|
+
)
|
|
1943
|
+
|
|
1944
|
+
return Boolean(value.result.value) === (action.condition === "text")
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
await waitFor(
|
|
1948
|
+
() =>
|
|
1949
|
+
holds().catch((error: Error) => {
|
|
1950
|
+
checks.failed = true
|
|
1951
|
+
throw error
|
|
1952
|
+
}),
|
|
1953
|
+
signal,
|
|
1954
|
+
action.timeoutMs,
|
|
1955
|
+
).catch((cause: Error) => {
|
|
1956
|
+
if (signal.aborted) throw cause
|
|
1957
|
+
const text = `browser.wait failed for condition ${JSON.stringify(action.condition)} (timeoutMs: ${action.timeoutMs ?? 10_000}). Inspect browser.snapshot({tabID}) and check text/frameID before retrying; timeoutMs can be increased up to 30000 for a genuinely slow page. Details: ${cause.message}`
|
|
1958
|
+
|
|
1959
|
+
throw checks.failed ? new Error(text, { cause }) : new CodedError(Browser.FailureCode.unmet, text, { cause })
|
|
1960
|
+
})
|
|
1961
|
+
break
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
case "screenshot": {
|
|
1965
|
+
if (action.ref && action.fullPage)
|
|
1966
|
+
throw new Error(
|
|
1967
|
+
"Choose either ref for an element screenshot or fullPage:true for the whole page. Remove the other argument before retrying.",
|
|
1968
|
+
)
|
|
1969
|
+
|
|
1970
|
+
const blocked = undrawable({
|
|
1971
|
+
platform: process.platform,
|
|
1972
|
+
minimized: win.isMinimized(),
|
|
1973
|
+
visible: win.isVisible(),
|
|
1974
|
+
appHidden: process.platform === "darwin" && electron.app.isHidden(),
|
|
1975
|
+
})
|
|
1976
|
+
|
|
1977
|
+
if (blocked) throw new Error(undrawableMessage(blocked))
|
|
1978
|
+
const capture = await captureFrame(action, signal)
|
|
1979
|
+
|
|
1980
|
+
const id = await files.save(`screenshot.${capture.format}`, `image/${capture.format}`, capture.data, [
|
|
1981
|
+
...captureSources,
|
|
1982
|
+
...sourceURLs(),
|
|
1983
|
+
])
|
|
1984
|
+
|
|
1985
|
+
return result({ tab: state() }, [await transfer(id)])
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
case "dialog": {
|
|
1989
|
+
if (action.action !== "get") {
|
|
1990
|
+
const open = selectOpenDialog(dialogGate)
|
|
1991
|
+
|
|
1992
|
+
// The user may answer it in the pane first; then it is closed for the agent too.
|
|
1993
|
+
if (!open || dispatchDialog({ type: "dialog.answering", revision: open.revision, by: "agent" }).answer !== "accepted")
|
|
1994
|
+
throw new Error(
|
|
1995
|
+
'This tab has no JavaScript dialog to handle. browser.dialog({tabID,action:"get"}) returns null when none is open; continue without accepting or dismissing one.',
|
|
1996
|
+
)
|
|
1997
|
+
await cdp
|
|
1998
|
+
.send("Page.handleJavaScriptDialog", { accept: action.action === "accept", promptText: action.promptText })
|
|
1999
|
+
.catch((error: Error) => {
|
|
2000
|
+
dispatchDialog({ type: "dialog.answer-failed", revision: open.revision })
|
|
2001
|
+
throw error
|
|
2002
|
+
})
|
|
2003
|
+
dispatchDialog({ type: "dialog.handled", revision: open.revision, at: Date.now() })
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
return result({ tab: state(), dialog: selectDialog(dialogGate) })
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
case "files.upload":
|
|
2010
|
+
case "files.drop": {
|
|
2011
|
+
if (!transfers.length)
|
|
2012
|
+
throw new Error(
|
|
2013
|
+
"Upload command has no file bytes. Supply server-local paths to browser.files.upload/drop; do not call the desktop RPC directly with desktop paths. If paths were supplied, report a client/server transfer mismatch.",
|
|
2014
|
+
)
|
|
2015
|
+
|
|
2016
|
+
const local = await Promise.all(
|
|
2017
|
+
transfers.map(async (file) => files.get(await files.save(file.name, file.mime, file.data)).path),
|
|
2018
|
+
)
|
|
2019
|
+
|
|
2020
|
+
const element = target(action.ref)
|
|
2021
|
+
|
|
2022
|
+
if (action.type === "files.upload")
|
|
2023
|
+
await cdp.send("DOM.setFileInputFiles", { files: local, backendNodeId: element.backendID }, element.sessionID)
|
|
2024
|
+
|
|
2025
|
+
if (action.type === "files.drop") {
|
|
2026
|
+
const position = await point(element)
|
|
2027
|
+
|
|
2028
|
+
for (const type of ["dragEnter", "dragOver", "drop"] as const)
|
|
2029
|
+
await input("Input.dispatchDragEvent", {
|
|
2030
|
+
type,
|
|
2031
|
+
...position,
|
|
2032
|
+
data: { items: [], files: local, dragOperationsMask: 1 },
|
|
2033
|
+
})
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
break
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
case "files.list":
|
|
2040
|
+
return result({ tab: state(), files: files.list() })
|
|
2041
|
+
case "files.get":
|
|
2042
|
+
return result({ tab: state() }, [await transfer(action.fileID)])
|
|
2043
|
+
case "console":
|
|
2044
|
+
return result({ tab: state(), ...diagnostics.console(action) })
|
|
2045
|
+
case "network.list":
|
|
2046
|
+
return result({ tab: state(), ...diagnostics.list(action) })
|
|
2047
|
+
case "network.get":
|
|
2048
|
+
return result({ tab: state(), ...(await diagnostics.get(action)) })
|
|
2049
|
+
case "trace.start":
|
|
2050
|
+
await profiling.startTrace(action.durationMs)
|
|
2051
|
+
|
|
2052
|
+
return result({ tab: state(), recording: true })
|
|
2053
|
+
case "trace.stop": {
|
|
2054
|
+
const value = await profiling.stopTrace()
|
|
2055
|
+
|
|
2056
|
+
return result({ tab: state(), durationMs: value.durationMs, incomplete: value.incomplete }, [
|
|
2057
|
+
await transfer(value.id),
|
|
2058
|
+
])
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
case "cpu.start":
|
|
2062
|
+
await profiling.startCpu()
|
|
2063
|
+
|
|
2064
|
+
return result({ tab: state(), recording: true })
|
|
2065
|
+
case "cpu.stop": {
|
|
2066
|
+
const value = await profiling.stopCpu()
|
|
2067
|
+
|
|
2068
|
+
return result({ tab: state(), durationMs: value.durationMs }, [await transfer(value.id)])
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
case "heap.snapshot":
|
|
2072
|
+
return result({ tab: state() }, [await transfer(await profiling.heap())])
|
|
2073
|
+
case "trace.analyze":
|
|
2074
|
+
case "cpu.analyze":
|
|
2075
|
+
case "heap.summary":
|
|
2076
|
+
case "heap.query":
|
|
2077
|
+
case "heap.object":
|
|
2078
|
+
case "heap.compare":
|
|
2079
|
+
return result({ tab: state(), ...(await profiling.analyze(action)) })
|
|
2080
|
+
case "lighthouse": {
|
|
2081
|
+
const { audit } = await import("./lighthouse")
|
|
2082
|
+
const report = await audit(contents, files, cdp, captureSources)
|
|
2083
|
+
|
|
2084
|
+
return result(
|
|
2085
|
+
{ tab: state(), scores: report.scores, failures: report.failures },
|
|
2086
|
+
await Promise.all(report.files.map(transfer)),
|
|
2087
|
+
)
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
default:
|
|
2091
|
+
throw new Error(
|
|
2092
|
+
"This operation was routed to a page instead of the tab manager. Report a desktop/plugin routing mismatch; changing tab IDs or repeating the operation will not fix it.",
|
|
2093
|
+
)
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
abortError(signal)
|
|
2097
|
+
|
|
2098
|
+
return result(state())
|
|
2099
|
+
}
|
|
2100
|
+
|
|
2101
|
+
async function inspect(action: Browser.Action): Promise<Browser.Target> {
|
|
2102
|
+
// Most CDP queries cannot run while a JavaScript dialog blocks the renderer.
|
|
2103
|
+
if (action.type === "dialog")
|
|
2104
|
+
return selectDialogTarget(dialogGate, documentGeneration(documentState), state().url)
|
|
2105
|
+
|
|
2106
|
+
const fileIDs =
|
|
2107
|
+
action.type === "heap.compare" ? [action.before, action.after] : "fileID" in action ? [action.fileID] : []
|
|
2108
|
+
|
|
2109
|
+
if (fileIDs.length)
|
|
2110
|
+
return {
|
|
2111
|
+
resources: [...new Set(fileIDs.flatMap((id) => files.get(id).resources))].sort(),
|
|
2112
|
+
key: JSON.stringify(fileIDs),
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
if (action.type === "network.get") return { resources: [diagnostics.info(action.id).url], key: action.id }
|
|
2116
|
+
|
|
2117
|
+
if (action.type === "trace.stop" || action.type === "cpu.stop")
|
|
2118
|
+
return profiling.target(action.type === "trace.stop" ? "trace" : "cpu")
|
|
2119
|
+
const tree = await frames()
|
|
2120
|
+
tree.forEach((frame) => documents.set(frame.id, frame.url))
|
|
2121
|
+
const selected = actionRefs(action).map(target)
|
|
2122
|
+
|
|
2123
|
+
const frameIDs = selected.length
|
|
2124
|
+
? selected.map((element) => element.frameID)
|
|
2125
|
+
: "frameID" in action && action.frameID
|
|
2126
|
+
? [action.frameID]
|
|
2127
|
+
: []
|
|
2128
|
+
|
|
2129
|
+
const urls = await Promise.all(frameIDs.map(async (id) => (await agentFrameOf(id)).url))
|
|
2130
|
+
|
|
2131
|
+
const capture = ["screenshot", "lighthouse", "trace.start", "cpu.start", "heap.snapshot"].includes(action.type)
|
|
2132
|
+
|
|
2133
|
+
return {
|
|
2134
|
+
resources: [
|
|
2135
|
+
...new Set(
|
|
2136
|
+
action.type === "navigate"
|
|
2137
|
+
? [new URL(normalizeURL(action.url, policy)).href]
|
|
2138
|
+
: capture
|
|
2139
|
+
? sourceURLs()
|
|
2140
|
+
: urls.length
|
|
2141
|
+
? urls
|
|
2142
|
+
: [state().url],
|
|
2143
|
+
),
|
|
2144
|
+
].sort(),
|
|
2145
|
+
key: JSON.stringify([documentGeneration(documentState), revision, selected]),
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
function actionRefs(action: Browser.Action) {
|
|
2150
|
+
if (action.type === "drag") return [action.from, action.to]
|
|
2151
|
+
|
|
2152
|
+
if (action.type === "fill_form") return action.fields.map((field) => field.ref)
|
|
2153
|
+
|
|
2154
|
+
return "ref" in action && action.ref ? [action.ref] : []
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
/** The element a ref names: one from this tab's newest snapshot, or one the user picked. */
|
|
2158
|
+
function lookup(ref: Browser.Ref) {
|
|
2159
|
+
const key = ref.replace(/^@/, "")
|
|
2160
|
+
|
|
2161
|
+
return refs.get(key) ?? picked.get(key)
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
function target(ref: Browser.Ref): Element {
|
|
2165
|
+
const value = lookup(ref)
|
|
2166
|
+
|
|
2167
|
+
if (!value)
|
|
2168
|
+
throw new CodedError(
|
|
2169
|
+
Browser.FailureCode.staleRef,
|
|
2170
|
+
"Element ref is stale or belongs to another tab. Call browser.snapshot({tabID}) and use a ref from the current document.",
|
|
2171
|
+
)
|
|
2172
|
+
|
|
2173
|
+
return value
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
async function frames() {
|
|
2177
|
+
return agentFrames(await frameTrees()).map((frame) => ({ ...frame, url: frame.parentID ? displayURL(frame.url) : state().url }))
|
|
2178
|
+
}
|
|
2179
|
+
|
|
2180
|
+
async function frameTrees() {
|
|
2181
|
+
const root = await cdp.send("Page.getFrameTree")
|
|
2182
|
+
|
|
2183
|
+
const children = await Promise.all(
|
|
2184
|
+
Array.from(sessions, async ([id, sessionID]) => {
|
|
2185
|
+
const tree = await cdp.send("Page.getFrameTree", {}, sessionID).catch(() => undefined)
|
|
2186
|
+
|
|
2187
|
+
return tree ? [{ parentID: parents.get(id) ?? root.frameTree.frame.id, tree: tree.frameTree }] : []
|
|
2188
|
+
}),
|
|
2189
|
+
)
|
|
2190
|
+
|
|
2191
|
+
const excluded = await Promise.all(Array.from(extensionTargets.keys(), async (sessionID) => {
|
|
2192
|
+
const tree = await cdp.send("Page.getFrameTree", {}, sessionID).catch(() => undefined)
|
|
2193
|
+
|
|
2194
|
+
return tree ? [tree.frameTree] : []
|
|
2195
|
+
}))
|
|
2196
|
+
|
|
2197
|
+
return { root: root.frameTree, children: children.flat(), extensions: excludedFrames(extensionFrames(), excluded.flat()) }
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
/** The frame an agent's frameID names; every operation that takes one resolves it here. */
|
|
2201
|
+
async function agentFrameOf(frameID: string) {
|
|
2202
|
+
const access = agentFrame(await frameTrees(), frameID)
|
|
2203
|
+
|
|
2204
|
+
if (access.type !== "frame") throw new Error(access.message)
|
|
2205
|
+
|
|
2206
|
+
return { ...access.frame, url: access.frame.parentID ? displayURL(access.frame.url) : state().url }
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
async function frameContext(frameID: string) {
|
|
2210
|
+
await agentFrameOf(frameID)
|
|
2211
|
+
const context = contexts.get(frameID)
|
|
2212
|
+
|
|
2213
|
+
if (!context)
|
|
2214
|
+
throw new Error(
|
|
2215
|
+
"Frame context is unavailable. Call browser.frames({tabID}) and use a current frameID from this tab, or omit frameID to target the main frame.",
|
|
2216
|
+
)
|
|
2217
|
+
|
|
2218
|
+
return context
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
/** Why the agent may not use these frames: one shows an extension's document, perhaps since the call began. */
|
|
2222
|
+
async function extensionFrameRefusal(frameIDs: readonly string[]) {
|
|
2223
|
+
if (!frameIDs.length) return undefined
|
|
2224
|
+
const trees = await frameTrees()
|
|
2225
|
+
|
|
2226
|
+
return frameIDs.map((frameID) => agentFrame(trees, frameID)).find((access) => access.type !== "frame")?.message
|
|
2227
|
+
}
|
|
2228
|
+
|
|
2229
|
+
/** The frames an action reaches: its frameID, or the frames of the element refs it names. */
|
|
2230
|
+
function actionFrames(action: Browser.Action) {
|
|
2231
|
+
const elements = actionRefs(action).flatMap((ref) => lookup(ref)?.frameID ?? [])
|
|
2232
|
+
|
|
2233
|
+
return "frameID" in action && action.frameID ? [action.frameID, ...elements] : elements
|
|
2234
|
+
}
|
|
2235
|
+
|
|
2236
|
+
async function call(element: Element, functionDeclaration: string, args: unknown[] = []) {
|
|
2237
|
+
const objectId = await resolve(element)
|
|
2238
|
+
|
|
2239
|
+
try {
|
|
2240
|
+
const result = await cdp.send(
|
|
2241
|
+
"Runtime.callFunctionOn",
|
|
2242
|
+
{
|
|
2243
|
+
objectId,
|
|
2244
|
+
functionDeclaration: connectedFunction(functionDeclaration),
|
|
2245
|
+
arguments: args.map((value) => ({ value })),
|
|
2246
|
+
returnByValue: true,
|
|
2247
|
+
awaitPromise: true,
|
|
2248
|
+
},
|
|
2249
|
+
element.sessionID,
|
|
2250
|
+
)
|
|
2251
|
+
|
|
2252
|
+
if (result.exceptionDetails?.exception?.description?.startsWith("Error: browser.detached_ref\n")) throw detachedRef()
|
|
2253
|
+
|
|
2254
|
+
if (result.exceptionDetails)
|
|
2255
|
+
throw new Error(result.exceptionDetails.exception?.description ?? result.exceptionDetails.text)
|
|
2256
|
+
|
|
2257
|
+
// SAFETY: widens CDP's `any` value to unknown; every caller decodes or compares it.
|
|
2258
|
+
return result.result.value as unknown
|
|
2259
|
+
} finally {
|
|
2260
|
+
await cdp.send("Runtime.releaseObject", { objectId }, element.sessionID).catch(() => undefined)
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
async function resolve(element: Element) {
|
|
2265
|
+
const object = await cdp.send("DOM.resolveNode", { backendNodeId: element.backendID }, element.sessionID)
|
|
2266
|
+
|
|
2267
|
+
if (!object.object.objectId) throw detachedRef()
|
|
2268
|
+
|
|
2269
|
+
return object.object.objectId
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
async function rect(element: Element, scroll = false, knownTree?: Awaited<ReturnType<typeof frames>>) {
|
|
2273
|
+
if (scroll) {
|
|
2274
|
+
await cdp.send("DOM.scrollIntoViewIfNeeded", { backendNodeId: element.backendID }, element.sessionID)
|
|
2275
|
+
// A one-DIP capture flushes scrolling even in a hidden tab. A resize can briefly replace the surface.
|
|
2276
|
+
await contents
|
|
2277
|
+
.capturePage({ x: 0, y: 0, width: 1, height: 1 }, { stayHidden: false, stayAwake: true })
|
|
2278
|
+
.catch(() => painted(element.sessionID))
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
const bounds = Schema.Struct({ x: Schema.Finite, y: Schema.Finite, width: Schema.Finite, height: Schema.Finite })
|
|
2282
|
+
|
|
2283
|
+
const value = {
|
|
2284
|
+
...Schema.decodeUnknownSync(bounds)(
|
|
2285
|
+
await call(
|
|
2286
|
+
element,
|
|
2287
|
+
"function() { const r = this.getBoundingClientRect(); return {x:r.x,y:r.y,width:r.width,height:r.height}; }",
|
|
2288
|
+
),
|
|
2289
|
+
),
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2292
|
+
const tree = knownTree ?? await frames()
|
|
2293
|
+
let frame = tree.find((frame) => frame.id === element.frameID)
|
|
2294
|
+
|
|
2295
|
+
while (frame?.parentID) {
|
|
2296
|
+
const parent = { frameID: frame.parentID, sessionID: sessionFor(frame.parentID, tree) }
|
|
2297
|
+
const owner = await cdp.send("DOM.getFrameOwner", { frameId: frame.id }, parent.sessionID)
|
|
2298
|
+
|
|
2299
|
+
// A CSS transform on the iframe scales its content box; the child's own coordinates are unscaled.
|
|
2300
|
+
const box = Schema.decodeUnknownSync(
|
|
2301
|
+
Schema.Struct({ ...bounds.fields, scaleX: Schema.Finite, scaleY: Schema.Finite }),
|
|
2302
|
+
)(
|
|
2303
|
+
await call(
|
|
2304
|
+
{ backendID: owner.backendNodeId, ...parent },
|
|
2305
|
+
"function() { const r = this.getBoundingClientRect(); const sx = this.offsetWidth ? r.width / this.offsetWidth : 1; const sy = this.offsetHeight ? r.height / this.offsetHeight : 1; return {x:r.x+this.clientLeft*sx,y:r.y+this.clientTop*sy,width:r.width,height:r.height,scaleX:sx,scaleY:sy}; }",
|
|
2306
|
+
),
|
|
2307
|
+
)
|
|
2308
|
+
|
|
2309
|
+
value.x = box.x + value.x * box.scaleX
|
|
2310
|
+
value.y = box.y + value.y * box.scaleY
|
|
2311
|
+
value.width *= box.scaleX
|
|
2312
|
+
value.height *= box.scaleY
|
|
2313
|
+
frame = tree.find((item) => item.id === frame?.parentID)
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
return value
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2319
|
+
// Same-process child frames have no CDP target of their own; the nearest ancestor with one owns them.
|
|
2320
|
+
function sessionFor(frameID: string, tree: { id: string; parentID?: string }[]) {
|
|
2321
|
+
let id: string | undefined = frameID
|
|
2322
|
+
|
|
2323
|
+
while (id && !sessions.has(id)) id = tree.find((frame) => frame.id === id)?.parentID
|
|
2324
|
+
|
|
2325
|
+
return id ? sessions.get(id) : undefined
|
|
2326
|
+
}
|
|
2327
|
+
|
|
2328
|
+
async function captureFrame(action: Extract<Browser.Action, { type: "screenshot" }>, signal: AbortSignal) {
|
|
2329
|
+
// A resize between measuring and capturing would crop another layout; captures share the viewport writer's queue.
|
|
2330
|
+
return metrics.exclusive(() => withFrames(view.getVisible() && win.isVisible() && !win.isMinimized(), signal, async stop => {
|
|
2331
|
+
if (isNavigationPending(documentState)) await waitFor(() => !isNavigationPending(documentState), stop)
|
|
2332
|
+
abortError(stop)
|
|
2333
|
+
|
|
2334
|
+
// The restored address never opened (its preview failed, or its load was cancelled before it was issued): the
|
|
2335
|
+
// tab shows no document, so a redraw would pass a blank surface off as the page.
|
|
2336
|
+
if (documentState.status === "restoring")
|
|
2337
|
+
throw new Error("This restored tab has not opened its page. Reload or navigate the tab, then take the screenshot again.")
|
|
2338
|
+
const before = documentState
|
|
2339
|
+
const frame = await screenshot(action, stop)
|
|
2340
|
+
abortError(stop)
|
|
2341
|
+
|
|
2342
|
+
if (!frameStillCurrent(before, documentState)) throw new CodedError(Browser.FailureCode.documentChanged, "The document changed during capture. Check the tab and take a new screenshot.")
|
|
2343
|
+
|
|
2344
|
+
return frame
|
|
2345
|
+
}, action.fullPage ? FULL_PAGE_DEADLINE_MS : undefined))
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2348
|
+
// A fixed viewport is an emulated device scaled into the pane: CDP captures its own layout at the device's size, in
|
|
2349
|
+
// page DIPs, rather than the scaled surface.
|
|
2350
|
+
async function emulatedScreenshot(action: Extract<Browser.Action, { type: "screenshot" }>, signal: AbortSignal) {
|
|
2351
|
+
const format = action.format === "png" ? "png" : "jpeg"
|
|
2352
|
+
const element = action.ref ? await rect(target(action.ref), true) : undefined
|
|
2353
|
+
const layout = await cdp.send("Page.getLayoutMetrics")
|
|
2354
|
+
abortError(signal)
|
|
2355
|
+
const viewport = layout.cssVisualViewport
|
|
2356
|
+
|
|
2357
|
+
const bounds = element
|
|
2358
|
+
? { ...element, x: element.x + layout.cssLayoutViewport.pageX, y: element.y + layout.cssLayoutViewport.pageY }
|
|
2359
|
+
: action.fullPage
|
|
2360
|
+
? layout.cssContentSize
|
|
2361
|
+
: { x: viewport.pageX, y: viewport.pageY, width: viewport.clientWidth, height: viewport.clientHeight }
|
|
2362
|
+
|
|
2363
|
+
if (bounds.width <= 0 || bounds.height <= 0) throw new Error(noVisibleArea)
|
|
2364
|
+
const zoom = viewport.zoom ?? contents.getZoomFactor()
|
|
2365
|
+
const pixelRatio = zoom * electron.screen.getDisplayMatching(win.getBounds()).scaleFactor
|
|
2366
|
+
// A mobile page can initially zoom out to fit a 980 CSS px layout on a phone screen.
|
|
2367
|
+
const scale = Math.min(viewport.scale, (action.maxWidth ?? 2000) / (bounds.width * pixelRatio))
|
|
2368
|
+
|
|
2369
|
+
if (bounds.width * bounds.height * (scale * pixelRatio) ** 2 > 16_000_000)
|
|
2370
|
+
throw new Error("Screenshot exceeds 16 megapixels; capture an element or use a smaller maxWidth.")
|
|
2371
|
+
|
|
2372
|
+
const capture = await device.capture({
|
|
2373
|
+
format,
|
|
2374
|
+
quality: format === "png" ? undefined : (action.quality ?? 80),
|
|
2375
|
+
captureBeyondViewport: true,
|
|
2376
|
+
clip: { ...scaleRect(bounds, zoom), scale },
|
|
2377
|
+
})
|
|
2378
|
+
|
|
2379
|
+
abortError(signal)
|
|
2380
|
+
|
|
2381
|
+
return { format, data: Buffer.from(capture.data, "base64") }
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
async function screenshot(action: Extract<Browser.Action, { type: "screenshot" }>, signal: AbortSignal) {
|
|
2385
|
+
if (metrics.applied().viewport.mode === "fixed") return emulatedScreenshot(action, signal)
|
|
2386
|
+
|
|
2387
|
+
if (!action.fullPage && !action.ref) return captureViewport(action, signal)
|
|
2388
|
+
|
|
2389
|
+
const element = action.ref ? await rect(target(action.ref), true) : undefined
|
|
2390
|
+
const layout = await cdp.send("Page.getLayoutMetrics")
|
|
2391
|
+
abortError(signal)
|
|
2392
|
+
const viewport = layout.cssVisualViewport
|
|
2393
|
+
const onscreen = view.getVisible() && win.isVisible() && !win.isMinimized()
|
|
2394
|
+
|
|
2395
|
+
if (action.fullPage) return beyondViewport(action, layout.cssContentSize)
|
|
2396
|
+
|
|
2397
|
+
if (
|
|
2398
|
+
element &&
|
|
2399
|
+
onscreen &&
|
|
2400
|
+
(element.x < 0 ||
|
|
2401
|
+
element.y < 0 ||
|
|
2402
|
+
element.x + element.width > viewport.clientWidth ||
|
|
2403
|
+
element.y + element.height > viewport.clientHeight)
|
|
2404
|
+
)
|
|
2405
|
+
return beyondViewport(action, { ...element, x: element.x + viewport.pageX, y: element.y + viewport.pageY })
|
|
2406
|
+
|
|
2407
|
+
// Crop the requested redraw to the element's visible part without changing the page's viewport.
|
|
2408
|
+
const clip = element && {
|
|
2409
|
+
x: Math.max(0, element.x),
|
|
2410
|
+
y: Math.max(0, element.y),
|
|
2411
|
+
width: Math.min(viewport.clientWidth, element.x + element.width) - Math.max(0, element.x),
|
|
2412
|
+
height: Math.min(viewport.clientHeight, element.y + element.height) - Math.max(0, element.y),
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
if (clip && (clip.width <= 0 || clip.height <= 0)) throw new Error(noVisibleArea)
|
|
2416
|
+
|
|
2417
|
+
return captureViewport(action, signal, clip)
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
async function captureViewport(action: Extract<Browser.Action, { type: "screenshot" }>, signal: AbortSignal, clip?: Electron.Rectangle) {
|
|
2421
|
+
const viewWidth = view.getBounds().width
|
|
2422
|
+
const zoom = contents.getZoomFactor()
|
|
2423
|
+
const maxWidth = action.maxWidth ?? 2000
|
|
2424
|
+
const format = action.format === "png" ? "png" : "jpeg"
|
|
2425
|
+
// Request the final encoding when the viewport fits. Use a lossless intermediate for cropping or resizing.
|
|
2426
|
+
const encoding = !clip && viewWidth * electron.screen.getDisplayMatching(win.getNormalBounds()).scaleFactor <= maxWidth ? format : "png"
|
|
2427
|
+
|
|
2428
|
+
const shot = await cdp.send("Page.captureScreenshot", {
|
|
2429
|
+
format: encoding,
|
|
2430
|
+
quality: encoding === "jpeg" ? action.quality ?? 80 : undefined,
|
|
2431
|
+
fromSurface: true,
|
|
2432
|
+
captureBeyondViewport: false,
|
|
2433
|
+
optimizeForSpeed: true,
|
|
2434
|
+
})
|
|
2435
|
+
|
|
2436
|
+
abortError(signal)
|
|
2437
|
+
const bytes = Buffer.from(shot.data, "base64")
|
|
2438
|
+
|
|
2439
|
+
if (!clip && encoding === format && (format === "png" ? pngFits : jpegFits)(bytes, maxWidth, Browser.MAX_FILE_BYTES))
|
|
2440
|
+
return { format, data: bytes }
|
|
2441
|
+
|
|
2442
|
+
const viewportImage = electron.nativeImage.createFromBuffer(bytes)
|
|
2443
|
+
|
|
2444
|
+
if (viewportImage.isEmpty()) throw new Error(undrawableMessage("stalled"))
|
|
2445
|
+
const area = clip && cropPixels(clip, viewportImage.getSize(), viewWidth, zoom)
|
|
2446
|
+
|
|
2447
|
+
if (clip && !area) throw new Error(noVisibleArea)
|
|
2448
|
+
const image = area ? viewportImage.crop(area) : viewportImage
|
|
2449
|
+
|
|
2450
|
+
if (image.isEmpty()) throw new Error(noVisibleArea)
|
|
2451
|
+
|
|
2452
|
+
if (!clip && encoding === format && image.getSize().width <= maxWidth && bytes.length <= Browser.MAX_FILE_BYTES)
|
|
2453
|
+
return { format, data: bytes }
|
|
2454
|
+
|
|
2455
|
+
const scaled = image.getSize().width > maxWidth ? image.resize({ width: maxWidth, quality: "good" }) : image
|
|
2456
|
+
|
|
2457
|
+
// A rendered frame encodes only as PNG or JPEG, so WebP comes back as JPEG.
|
|
2458
|
+
return action.format === "png"
|
|
2459
|
+
? { format: "png", data: scaled.toPNG() }
|
|
2460
|
+
: { format: "jpeg", data: scaled.toJPEG(action.quality ?? 80) }
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
async function beyondViewport(
|
|
2464
|
+
action: Extract<Browser.Action, { type: "screenshot" }>,
|
|
2465
|
+
bounds: { x: number; y: number; width: number; height: number },
|
|
2466
|
+
) {
|
|
2467
|
+
const pixelRatio = contents.getZoomFactor() * electron.screen.getDisplayMatching(win.getNormalBounds()).scaleFactor
|
|
2468
|
+
const scale = captureScale(bounds, pixelRatio, action.maxWidth ?? 2000)
|
|
2469
|
+
const format = action.format ?? "jpeg"
|
|
2470
|
+
|
|
2471
|
+
const capture = await cdp.send("Page.captureScreenshot", {
|
|
2472
|
+
format,
|
|
2473
|
+
quality: format === "png" ? undefined : (action.quality ?? 80),
|
|
2474
|
+
fromSurface: true,
|
|
2475
|
+
captureBeyondViewport: true,
|
|
2476
|
+
clip: { ...bounds, scale },
|
|
2477
|
+
})
|
|
2478
|
+
|
|
2479
|
+
return { format, data: Buffer.from(capture.data, "base64") }
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2482
|
+
async function point(element: Element) {
|
|
2483
|
+
return elementCenter(await rect(element, true))
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2486
|
+
async function elementCenter(box: PaneElement["rect"]) {
|
|
2487
|
+
if (!device.mobile()) return inputCenter(box)
|
|
2488
|
+
// Focusing a field can pan the visual viewport inside the layout viewport. CDP adds that offset on dispatch.
|
|
2489
|
+
const { cssVisualViewport } = await cdp.send("Page.getLayoutMetrics")
|
|
2490
|
+
|
|
2491
|
+
return inputCenter({ ...box, x: box.x - cssVisualViewport.offsetX, y: box.y - cssVisualViewport.offsetY })
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2494
|
+
// Input.dispatch* applies page zoom itself. Its coordinates are relative to the full scaled view, even when panned.
|
|
2495
|
+
function inputCenter(box: PaneElement["rect"]) {
|
|
2496
|
+
const scale = metrics.applied().scale
|
|
2497
|
+
|
|
2498
|
+
return { x: (box.x + box.width / 2) * scale, y: (box.y + box.height / 2) * scale }
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
// CDP can't condition a native input event on a hit test. Check the compositor's actual hit after scrolling,
|
|
2502
|
+
// and check again after resolving the node. Do not dispatch into a frame owner whose inner hit is unknown.
|
|
2503
|
+
function dispatchInput(origin: "agent" | "user", signal: AbortSignal) {
|
|
2504
|
+
return async (
|
|
2505
|
+
method: "Input.dispatchMouseEvent" | "Input.dispatchDragEvent" | "Input.dispatchKeyEvent" | "Input.insertText",
|
|
2506
|
+
params: Protocol.Input.DispatchMouseEventRequest | Protocol.Input.DispatchDragEventRequest | Protocol.Input.DispatchKeyEventRequest | Protocol.Input.InsertTextRequest,
|
|
2507
|
+
) => {
|
|
2508
|
+
if (origin === "user") return cdp.send(method, params)
|
|
2509
|
+
// Context-menu delivery can follow the CDP reply. A later user input, not the end of the command, re-arms it.
|
|
2510
|
+
nativeMenu = false
|
|
2511
|
+
|
|
2512
|
+
if (process.platform === "linux" && "button" in params && params.button === "middle")
|
|
2513
|
+
throw new Error("Middle-click can paste the system selection. Use fill/type to enter text and evaluate to read page text.")
|
|
2514
|
+
const changed = "Input target changed or could not be verified. Take a fresh snapshot and use the page outside extension UI."
|
|
2515
|
+
|
|
2516
|
+
// The user sees a still of the page under "Leave site?" or a sign-in, not the page the input would reach.
|
|
2517
|
+
if (prompts.covered())
|
|
2518
|
+
throw new Error("The user is answering a prompt over this page. Wait for them, or use another tab; no input was sent.")
|
|
2519
|
+
|
|
2520
|
+
if ("x" in params) {
|
|
2521
|
+
const version = revision
|
|
2522
|
+
const trees = await frameTrees()
|
|
2523
|
+
const position = { x: Math.round(params.x), y: Math.round(params.y) }
|
|
2524
|
+
const hitTest = () => cdp.send("DOM.getNodeForLocation", { ...position, ignorePointerEventsNone: false })
|
|
2525
|
+
const hit = await hitTest()
|
|
2526
|
+
const access = agentFrame(trees, hit.frameId)
|
|
2527
|
+
|
|
2528
|
+
if (access.type !== "frame") throw new Error(access.message)
|
|
2529
|
+
const sessionID = sessionFor(hit.frameId, agentFrames(trees))
|
|
2530
|
+
const { node } = await cdp.send("DOM.describeNode", { backendNodeId: hit.backendNodeId }, sessionID)
|
|
2531
|
+
|
|
2532
|
+
if (/^(?:iframe|frame|object|embed)$/i.test(node.nodeName)) throw new Error(changed)
|
|
2533
|
+
const last = await hitTest()
|
|
2534
|
+
|
|
2535
|
+
if (version !== revision || last.backendNodeId !== hit.backendNodeId || last.frameId !== hit.frameId || extensionFrames().has(hit.frameId)) throw new Error(changed)
|
|
2536
|
+
|
|
2537
|
+
if (!inputDocument(contents.mainFrame.url, contents.mainFrame.origin)) throw new Error(changed)
|
|
2538
|
+
abortError(signal)
|
|
2539
|
+
|
|
2540
|
+
// Counted before it is sent and never taken back: a press that fails to arrive costs the person one press
|
|
2541
|
+
// read as the agent's, never the reverse.
|
|
2542
|
+
if ("type" in params && params.type === "mousePressed") agentPresses++
|
|
2543
|
+
|
|
2544
|
+
return cdp.send(method, { ...params, ...position })
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
const focused = contents.focusedFrame
|
|
2548
|
+
|
|
2549
|
+
if (!focused) throw new Error(changed)
|
|
2550
|
+
|
|
2551
|
+
for (let frame: Electron.WebFrameMain | null = focused; frame; frame = frame.parent) {
|
|
2552
|
+
if (frame.detached || !inputDocument(frame.url, frame.origin)) throw new Error(changed)
|
|
2553
|
+
|
|
2554
|
+
if (!frame.parent && frame.frameTreeNodeId !== contents.mainFrame.frameTreeNodeId) throw new Error(changed)
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
abortError(signal)
|
|
2558
|
+
|
|
2559
|
+
return cdp.send(method, params)
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
async function click(input: ReturnType<typeof dispatchInput>, element: Element, button: Protocol.Input.MouseButton = "left", count = 1, modifiers: readonly string[] = []) {
|
|
2564
|
+
const position = await point(element)
|
|
2565
|
+
const flags = modifiers.reduce((mask, key) => mask | ({ Alt: 1, Control: 2, Meta: 4, Shift: 8 }[key] ?? 0), 0)
|
|
2566
|
+
await input("Input.dispatchMouseEvent", { type: "mouseMoved", ...position, modifiers: flags })
|
|
2567
|
+
|
|
2568
|
+
for (let clickCount = 1; clickCount <= count; clickCount++) {
|
|
2569
|
+
await input("Input.dispatchMouseEvent", {
|
|
2570
|
+
type: "mousePressed",
|
|
2571
|
+
...position,
|
|
2572
|
+
button,
|
|
2573
|
+
clickCount,
|
|
2574
|
+
modifiers: flags,
|
|
2575
|
+
})
|
|
2576
|
+
await input("Input.dispatchMouseEvent", {
|
|
2577
|
+
type: "mouseReleased",
|
|
2578
|
+
...position,
|
|
2579
|
+
button,
|
|
2580
|
+
clickCount,
|
|
2581
|
+
modifiers: flags,
|
|
2582
|
+
})
|
|
2583
|
+
}
|
|
2584
|
+
}
|
|
2585
|
+
|
|
2586
|
+
async function fill(input: ReturnType<typeof dispatchInput>, element: Element, value: string, signal: AbortSignal) {
|
|
2587
|
+
const kind = await call(
|
|
2588
|
+
element,
|
|
2589
|
+
"function() { if (this.disabled || this.readOnly) return; if (this instanceof HTMLTextAreaElement || this.isContentEditable) return 'text'; if (!(this instanceof HTMLInputElement)) return; if (['date','time','datetime-local','month','week'].includes(this.type)) return 'structured'; if (!['file','checkbox','radio','button','submit','reset','image','hidden','range','color'].includes(this.type)) return 'text'; }",
|
|
2590
|
+
)
|
|
2591
|
+
|
|
2592
|
+
if (!kind)
|
|
2593
|
+
throw new Error(
|
|
2594
|
+
"Target is not an enabled editable text field. Take a fresh snapshot and choose a textbox; use browser.select for dropdowns, browser.check for checkboxes/radios, or browser.files.upload for file inputs.",
|
|
2595
|
+
)
|
|
2596
|
+
|
|
2597
|
+
// Keyboard input cannot compose a date or time control's value; Chromium clears a malformed one.
|
|
2598
|
+
if (kind === "structured") {
|
|
2599
|
+
await call(
|
|
2600
|
+
element,
|
|
2601
|
+
"function(value) { const previous = this.value; this.focus(); this.value = value; if (this.value !== value) { this.value = previous; throw new Error('The ' + this.type + ' input rejected this value and keeps its previous one. Use its required format, for example 2026-09-07 for date, 14:45 for time, 2026-09-07T14:45 for datetime-local, 2026-09 for month, or 2026-W37 for week.'); } this.dispatchEvent(new Event('input',{bubbles:true})); this.dispatchEvent(new Event('change',{bubbles:true})); }",
|
|
2602
|
+
[value],
|
|
2603
|
+
)
|
|
2604
|
+
|
|
2605
|
+
return
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
await cdp.send("DOM.focus", { backendNodeId: element.backendID }, element.sessionID)
|
|
2609
|
+
// Focusing this field blurs the previous one; a validation dialog from that blur must stop here.
|
|
2610
|
+
abortError(signal)
|
|
2611
|
+
await key(input, process.platform === "darwin" ? "Meta+A" : "Control+A")
|
|
2612
|
+
await key(input, "Backspace")
|
|
2613
|
+
abortError(signal)
|
|
2614
|
+
await input("Input.insertText", { text: value })
|
|
2615
|
+
}
|
|
2616
|
+
|
|
2617
|
+
async function select(element: Element, values: readonly string[]) {
|
|
2618
|
+
await call(
|
|
2619
|
+
element,
|
|
2620
|
+
`function(values) { if (!(this instanceof HTMLSelectElement) || this.disabled) throw new Error('Target is not an enabled HTML select. Take a fresh snapshot and choose an enabled dropdown ref.'); if (!this.multiple && values.length !== 1) throw new Error('This dropdown accepts exactly one value; pass a one-item values array.'); for (const value of values) if (!Array.from(this.options).some(option => option.value === value && !option.disabled)) throw new Error('Option value was not found or is disabled. Inspect option values with browser.evaluate before retrying browser.select; values are not visible labels.'); for (const option of this.options) option.selected = values.includes(option.value); this.dispatchEvent(new Event('input',{bubbles:true})); this.dispatchEvent(new Event('change',{bubbles:true})); }`,
|
|
2621
|
+
[values],
|
|
2622
|
+
)
|
|
2623
|
+
}
|
|
2624
|
+
|
|
2625
|
+
async function check(input: ReturnType<typeof dispatchInput>, element: Element, checked: boolean) {
|
|
2626
|
+
const current = await call(
|
|
2627
|
+
element,
|
|
2628
|
+
"function(checked) { if (!(this instanceof HTMLInputElement) || !['checkbox','radio'].includes(this.type) || this.disabled) throw new Error('Target is not an enabled checkbox or radio. Take a fresh snapshot and choose the correct ref.'); if (this.type === 'radio' && this.checked && !checked) throw new Error('A selected radio cannot be cleared by clicking it. Select a different radio in its group instead.'); return this.checked; }",
|
|
2629
|
+
[checked],
|
|
2630
|
+
)
|
|
2631
|
+
|
|
2632
|
+
if (current !== checked) await click(input, element)
|
|
2633
|
+
|
|
2634
|
+
if ((await call(element, "function() { return this.checked; }")) !== checked)
|
|
2635
|
+
throw new Error(
|
|
2636
|
+
"The page did not keep the requested checked state. Inspect the current snapshot and page validation before retrying; do not blindly toggle the control again.",
|
|
2637
|
+
)
|
|
2638
|
+
}
|
|
2639
|
+
|
|
2640
|
+
async function key(input: ReturnType<typeof dispatchInput>, chord: string) {
|
|
2641
|
+
if (!chord)
|
|
2642
|
+
throw new Error(
|
|
2643
|
+
"A key is required. Use a named key such as Enter or ArrowDown, a single character, or a chord such as Control+A.",
|
|
2644
|
+
)
|
|
2645
|
+
const parts = (chord.endsWith("+") ? chord.slice(0, -1) : chord).split("+")
|
|
2646
|
+
const key = parts.pop() || "+"
|
|
2647
|
+
|
|
2648
|
+
const modifiers = parts.reduce((mask, key) => {
|
|
2649
|
+
const bit = { Alt: 1, Control: 2, Meta: 4, Shift: 8 }[key]
|
|
2650
|
+
|
|
2651
|
+
if (!bit)
|
|
2652
|
+
throw new Error(
|
|
2653
|
+
`Unknown key modifier ${JSON.stringify(key)}. Supported modifiers are Alt, Control, Meta, and Shift; for example Control+A. Use Meta for macOS command shortcuts.`,
|
|
2654
|
+
)
|
|
2655
|
+
|
|
2656
|
+
return mask | bit
|
|
2657
|
+
}, 0)
|
|
2658
|
+
|
|
2659
|
+
const codes: KeyCodes = {
|
|
2660
|
+
Enter: 13,
|
|
2661
|
+
Tab: 9,
|
|
2662
|
+
Escape: 27,
|
|
2663
|
+
Backspace: 8,
|
|
2664
|
+
Delete: 46,
|
|
2665
|
+
ArrowUp: 38,
|
|
2666
|
+
ArrowDown: 40,
|
|
2667
|
+
ArrowLeft: 37,
|
|
2668
|
+
ArrowRight: 39,
|
|
2669
|
+
PageUp: 33,
|
|
2670
|
+
PageDown: 34,
|
|
2671
|
+
Home: 36,
|
|
2672
|
+
End: 35,
|
|
2673
|
+
Space: 32,
|
|
2674
|
+
}
|
|
2675
|
+
|
|
2676
|
+
const code =
|
|
2677
|
+
codes[key] ??
|
|
2678
|
+
(key.length === 1
|
|
2679
|
+
? key.toUpperCase().charCodeAt(0)
|
|
2680
|
+
: /^F([1-9]|1[0-2])$/.test(key)
|
|
2681
|
+
? 111 + Number(key.slice(1))
|
|
2682
|
+
: undefined)
|
|
2683
|
+
|
|
2684
|
+
const refusal = agentKeyRefusal(key, modifiers, code)
|
|
2685
|
+
|
|
2686
|
+
if (refusal) throw new Error(refusal)
|
|
2687
|
+
|
|
2688
|
+
if (code === undefined)
|
|
2689
|
+
throw new Error(
|
|
2690
|
+
`Unknown key ${JSON.stringify(key)}. Use Enter, Tab, Escape, Backspace, Delete, ArrowUp/Down/Left/Right, PageUp/Down, Home, End, Space, F1–F12, or one character. Use browser.fill for text.`,
|
|
2691
|
+
)
|
|
2692
|
+
// Named keys need their character data too: Enter submits forms and inserts newlines only with "\r".
|
|
2693
|
+
const text = key === "Enter" ? "\r" : key === "Space" ? " " : key.length === 1 ? key : undefined
|
|
2694
|
+
|
|
2695
|
+
const event = { key: key === "Space" ? " " : key, windowsVirtualKeyCode: code, modifiers }
|
|
2696
|
+
const params = text !== undefined && !(modifiers & 6) ? { ...event, text } : event
|
|
2697
|
+
|
|
2698
|
+
await input("Input.dispatchKeyEvent", { type: "keyDown", ...params })
|
|
2699
|
+
await input("Input.dispatchKeyEvent", { type: "keyUp", ...params })
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
async function snapshot(action: Extract<Browser.Action, { type: "snapshot" | "find" }>, signal: AbortSignal) {
|
|
2703
|
+
const generation = documentGeneration(documentState)
|
|
2704
|
+
const tree = await frames()
|
|
2705
|
+
const selected = action.type === "snapshot" && action.ref ? target(action.ref) : undefined
|
|
2706
|
+
const named = selected?.frameID ?? action.frameID
|
|
2707
|
+
const frameID = named ? (await agentFrameOf(named)).id : tree[0]?.id
|
|
2708
|
+
|
|
2709
|
+
if (!frameID)
|
|
2710
|
+
throw new Error(
|
|
2711
|
+
"Frame is unavailable. Call browser.frames({tabID}) and use a current frameID from this tab; omit frameID for the main frame.",
|
|
2712
|
+
)
|
|
2713
|
+
const sessionID = sessionFor(frameID, tree)
|
|
2714
|
+
const ax = await cdp.send("Accessibility.getFullAXTree", { frameId: frameID }, sessionID)
|
|
2715
|
+
abortError(signal)
|
|
2716
|
+
|
|
2717
|
+
const byNode = (source: Map<string, Element>) => new Map(Array.from(source)
|
|
2718
|
+
.filter(([, element]) => element.frameID === frameID && element.sessionID === sessionID)
|
|
2719
|
+
.map(([ref, element]) => [element.backendID, ref]))
|
|
2720
|
+
|
|
2721
|
+
const snapshot = await accessibilitySnapshot(ax.nodes, {
|
|
2722
|
+
root: selected?.backendID,
|
|
2723
|
+
depth: action.type === "snapshot" ? action.depth : undefined,
|
|
2724
|
+
text: action.type === "find" ? action.text : undefined,
|
|
2725
|
+
interactive: action.interactive,
|
|
2726
|
+
maxLines: action.maxLines,
|
|
2727
|
+
maxChars: action.maxChars,
|
|
2728
|
+
signal,
|
|
2729
|
+
previous: refs.previous(frameID, sessionID),
|
|
2730
|
+
picked: byNode(picked),
|
|
2731
|
+
ref: options.shared.ref,
|
|
2732
|
+
// AX does not distinguish password textboxes. Fail closed if the backing field is gone or sensitive.
|
|
2733
|
+
readableValue: async (backendID, name) => {
|
|
2734
|
+
abortError(signal)
|
|
2735
|
+
const field = await call({ backendID, frameID, sessionID }, describeField).catch(() => undefined)
|
|
2736
|
+
|
|
2737
|
+
return Schema.is(Field)(field) && readableField(field, name)
|
|
2738
|
+
},
|
|
2739
|
+
box: action.type === "snapshot" && action.boxes ? async (backendID) => {
|
|
2740
|
+
abortError(signal)
|
|
2741
|
+
const box = await rect({ backendID, frameID, sessionID }, false, tree).catch(() => undefined)
|
|
2742
|
+
|
|
2743
|
+
return box ? ` box=${JSON.stringify(box)}` : ""
|
|
2744
|
+
} : undefined,
|
|
2745
|
+
})
|
|
2746
|
+
|
|
2747
|
+
abortError(signal)
|
|
2748
|
+
|
|
2749
|
+
if (documentGeneration(documentState) !== generation) throw new CodedError(Browser.FailureCode.documentChanged, "Document changed during snapshot; request a fresh snapshot.")
|
|
2750
|
+
refs.add(frameID, sessionID, snapshot.refs)
|
|
2751
|
+
|
|
2752
|
+
return { content: snapshot.content, truncated: snapshot.truncated }
|
|
2753
|
+
}
|
|
2754
|
+
|
|
2755
|
+
/** Moves the picker and runs its effects; resolves once they ran, so input waits for the picker to disarm. */
|
|
2756
|
+
async function dispatchPicker(event: PickerEvent): Promise<void> {
|
|
2757
|
+
const next = transitionPicker(pickerState, event)
|
|
2758
|
+
pickerState = next.state
|
|
2759
|
+
await Promise.all(next.effects.map(runPicker))
|
|
2760
|
+
}
|
|
2761
|
+
|
|
2762
|
+
async function runPicker(effect: PickerEffect): Promise<void> {
|
|
2763
|
+
switch (effect.type) {
|
|
2764
|
+
case "arm": {
|
|
2765
|
+
const attempt = effect.attempt
|
|
2766
|
+
// Each out-of-process frame arms its own picker; the main target decides whether the picker started.
|
|
2767
|
+
const frames = Array.from(sessions.values(), (id) => arm(attempt, id).catch(() => undefined))
|
|
2768
|
+
|
|
2769
|
+
return Promise.all([arm(attempt), ...frames]).then(
|
|
2770
|
+
() => dispatchPicker({ type: "arm.succeeded", attempt }),
|
|
2771
|
+
() => dispatchPicker({ type: "arm.failed", attempt }),
|
|
2772
|
+
)
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2775
|
+
case "arm-frame":
|
|
2776
|
+
return arm(effect.attempt, effect.sessionID).catch(() => undefined)
|
|
2777
|
+
case "disarm":
|
|
2778
|
+
return disarm()
|
|
2779
|
+
case "describe": {
|
|
2780
|
+
const attempt = effect.attempt
|
|
2781
|
+
|
|
2782
|
+
return metrics
|
|
2783
|
+
.exclusive(() => describePick(effect.backendID, effect.sessionID))
|
|
2784
|
+
.then(
|
|
2785
|
+
(pick) =>
|
|
2786
|
+
dispatchPicker({ type: "describe.succeeded", attempt, target: pick.target, element: pick.element }),
|
|
2787
|
+
() => dispatchPicker({ type: "describe.failed", attempt }),
|
|
2788
|
+
)
|
|
2789
|
+
}
|
|
2790
|
+
|
|
2791
|
+
case "pick": {
|
|
2792
|
+
const ref = options.shared.ref()
|
|
2793
|
+
picked.set(ref, effect.target)
|
|
2794
|
+
focusHost()
|
|
2795
|
+
options.inspect?.({ active: false, element: { ref: Browser.Ref.make(ref), ...effect.element } })
|
|
2796
|
+
|
|
2797
|
+
return
|
|
2798
|
+
}
|
|
2799
|
+
|
|
2800
|
+
case "flash": {
|
|
2801
|
+
const attempt = effect.attempt
|
|
2802
|
+
const target = effect.target
|
|
2803
|
+
|
|
2804
|
+
return cdp
|
|
2805
|
+
.send("DOM.scrollIntoViewIfNeeded", { backendNodeId: target.backendID }, target.sessionID)
|
|
2806
|
+
.then(() =>
|
|
2807
|
+
cdp.send(
|
|
2808
|
+
"Overlay.highlightNode",
|
|
2809
|
+
{ backendNodeId: target.backendID, highlightConfig: pickedHighlight },
|
|
2810
|
+
target.sessionID,
|
|
2811
|
+
),
|
|
2812
|
+
)
|
|
2813
|
+
.then(
|
|
2814
|
+
() => dispatchPicker({ type: "flash.shown", attempt }),
|
|
2815
|
+
() => dispatchPicker({ type: "flash.failed", attempt }),
|
|
2816
|
+
)
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2819
|
+
case "hide-highlight":
|
|
2820
|
+
return hideHighlight()
|
|
2821
|
+
case "report":
|
|
2822
|
+
options.inspect?.({ active: effect.active })
|
|
2823
|
+
|
|
2824
|
+
return
|
|
2825
|
+
case "timer": {
|
|
2826
|
+
const attempt = effect.attempt
|
|
2827
|
+
const phase = effect.phase
|
|
2828
|
+
clearTimeout(pickerTimer)
|
|
2829
|
+
pickerTimer = setTimeout(
|
|
2830
|
+
() => void dispatchPicker({ type: "timeout", phase, attempt }),
|
|
2831
|
+
PICKER_TIMEOUT_MS[phase],
|
|
2832
|
+
)
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2837
|
+
async function arm(attempt: number, sessionID?: string) {
|
|
2838
|
+
// The main target enables DOM at startup; frame targets only need it for the picker.
|
|
2839
|
+
if (sessionID) await cdp.send("DOM.enable", {}, sessionID)
|
|
2840
|
+
await cdp.send("Overlay.enable", {}, sessionID)
|
|
2841
|
+
|
|
2842
|
+
// The picker may have been turned off while the domains were enabling.
|
|
2843
|
+
if (pickerAttempt(pickerState) !== attempt) return
|
|
2844
|
+
await cdp.send("Overlay.setInspectMode", { mode: "searchForNode", highlightConfig: inspectHighlight }, sessionID)
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
async function disarm() {
|
|
2848
|
+
await Promise.all(
|
|
2849
|
+
[undefined, ...sessions.values()].map((id) =>
|
|
2850
|
+
cdp.send("Overlay.setInspectMode", inspectOff, id).catch(() => undefined),
|
|
2851
|
+
),
|
|
2852
|
+
)
|
|
2853
|
+
}
|
|
2854
|
+
|
|
2855
|
+
async function describePick(backendID: number, sessionID?: string) {
|
|
2856
|
+
await disarm()
|
|
2857
|
+
// Keep the box model on the picked element, without the tooltip, while the renderer freezes the page.
|
|
2858
|
+
await cdp.send("Overlay.highlightNode", { backendNodeId: backendID, highlightConfig: pickedHighlight }, sessionID)
|
|
2859
|
+
const target = { backendID, frameID: await frameOf(backendID, sessionID), sessionID }
|
|
2860
|
+
|
|
2861
|
+
const [details, box, accessible, layout] = await Promise.all([
|
|
2862
|
+
describe(target),
|
|
2863
|
+
rect(target),
|
|
2864
|
+
accessibility(target),
|
|
2865
|
+
cdp.send("Page.getLayoutMetrics"),
|
|
2866
|
+
])
|
|
2867
|
+
|
|
2868
|
+
await painted(sessionID)
|
|
2869
|
+
const visual = layout.cssVisualViewport
|
|
2870
|
+
const scale = contents.getZoomFactor() * metrics.applied().scale * visual.scale
|
|
2871
|
+
|
|
2872
|
+
return {
|
|
2873
|
+
target,
|
|
2874
|
+
element: {
|
|
2875
|
+
...details,
|
|
2876
|
+
...accessible,
|
|
2877
|
+
rect: scaleRect({ ...box, x: box.x - visual.offsetX, y: box.y - visual.offsetY }, scale),
|
|
2878
|
+
},
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
|
|
2882
|
+
async function hideHighlight() {
|
|
2883
|
+
await Promise.all(
|
|
2884
|
+
[undefined, ...sessions.values()].map((sessionID) =>
|
|
2885
|
+
cdp.send("Overlay.hideHighlight", {}, sessionID).catch(() => undefined),
|
|
2886
|
+
),
|
|
2887
|
+
)
|
|
2888
|
+
}
|
|
2889
|
+
|
|
2890
|
+
// The picker names a node but not its frame. A target owns its root frame plus any same-process
|
|
2891
|
+
// child frames, so match the node's document against each child frame's content document.
|
|
2892
|
+
async function frameOf(backendID: number, sessionID?: string) {
|
|
2893
|
+
const tree = await frames()
|
|
2894
|
+
const owned = tree.filter((frame) => sessionFor(frame.id, tree) === sessionID)
|
|
2895
|
+
const root = owned.find((frame) => !frame.parentID || sessionFor(frame.parentID, tree) !== sessionID) ?? tree[0]
|
|
2896
|
+
const nested = owned.filter((frame) => frame !== root)
|
|
2897
|
+
|
|
2898
|
+
if (!nested.length) return root.id
|
|
2899
|
+
// The node and its document join one object group, released even when a later call rejects.
|
|
2900
|
+
const objectGroup = `frame-of-${crypto.randomUUID()}`
|
|
2901
|
+
|
|
2902
|
+
const described = await (async () => {
|
|
2903
|
+
const node = await cdp.send("DOM.resolveNode", { backendNodeId: backendID, objectGroup }, sessionID)
|
|
2904
|
+
|
|
2905
|
+
const document = node.object.objectId
|
|
2906
|
+
? await cdp.send(
|
|
2907
|
+
"Runtime.callFunctionOn",
|
|
2908
|
+
{
|
|
2909
|
+
objectId: node.object.objectId,
|
|
2910
|
+
functionDeclaration: "function() { return this.ownerDocument; }",
|
|
2911
|
+
objectGroup,
|
|
2912
|
+
},
|
|
2913
|
+
sessionID,
|
|
2914
|
+
)
|
|
2915
|
+
: undefined
|
|
2916
|
+
|
|
2917
|
+
return document?.result.objectId
|
|
2918
|
+
? await cdp.send("DOM.describeNode", { objectId: document.result.objectId }, sessionID)
|
|
2919
|
+
: undefined
|
|
2920
|
+
})().finally(() => void cdp.send("Runtime.releaseObjectGroup", { objectGroup }, sessionID).catch(() => undefined))
|
|
2921
|
+
|
|
2922
|
+
const owners = await Promise.all(
|
|
2923
|
+
nested.map(async (frame) => {
|
|
2924
|
+
const owner = await cdp.send("DOM.getFrameOwner", { frameId: frame.id }, sessionID).catch(() => undefined)
|
|
2925
|
+
|
|
2926
|
+
const iframe = owner
|
|
2927
|
+
? await cdp.send("DOM.describeNode", { backendNodeId: owner.backendNodeId }, sessionID).catch(() => undefined)
|
|
2928
|
+
: undefined
|
|
2929
|
+
|
|
2930
|
+
return { id: frame.id, document: iframe?.node.contentDocument?.backendNodeId }
|
|
2931
|
+
}),
|
|
2932
|
+
)
|
|
2933
|
+
|
|
2934
|
+
return owners.find((owner) => owner.document === described?.node.backendNodeId)?.id ?? root.id
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
async function describe(element: Element) {
|
|
2938
|
+
return Schema.decodeUnknownSync(
|
|
2939
|
+
Schema.Struct({ label: Schema.String, selector: Schema.String, text: Schema.optionalKey(Schema.String) }),
|
|
2940
|
+
)(
|
|
2941
|
+
await call(
|
|
2942
|
+
element,
|
|
2943
|
+
`function() {
|
|
2944
|
+
const clip = (value, max) => (value.length > max ? value.slice(0, max - 1) + "\u2026" : value)
|
|
2945
|
+
const label = this.localName + (this.id ? "#" + this.id : "") + Array.from(this.classList, (name) => "." + name).join("")
|
|
2946
|
+
// One segment per document or shadow root, outermost first; " >>> " steps into a host's shadow root.
|
|
2947
|
+
const segments = []
|
|
2948
|
+
for (let start = this; start; ) {
|
|
2949
|
+
const root = start.getRootNode()
|
|
2950
|
+
const path = []
|
|
2951
|
+
for (let node = start; node; node = node.parentElement) {
|
|
2952
|
+
if (node.id && root.querySelectorAll("#" + CSS.escape(node.id)).length === 1) {
|
|
2953
|
+
path.unshift("#" + CSS.escape(node.id))
|
|
2954
|
+
break
|
|
2955
|
+
}
|
|
2956
|
+
if (node === node.ownerDocument.body) {
|
|
2957
|
+
path.unshift("body")
|
|
2958
|
+
break
|
|
2959
|
+
}
|
|
2960
|
+
const same = Array.from(node.parentNode?.children ?? []).filter((child) => child.localName === node.localName)
|
|
2961
|
+
path.unshift(CSS.escape(node.localName) + (same.length > 1 ? ":nth-of-type(" + (same.indexOf(node) + 1) + ")" : ""))
|
|
2962
|
+
}
|
|
2963
|
+
segments.unshift(path.join(" > "))
|
|
2964
|
+
start = root instanceof ShadowRoot ? root.host : undefined
|
|
2965
|
+
}
|
|
2966
|
+
const selector = segments.join(" >>> ")
|
|
2967
|
+
const text = clip((this.innerText ?? this.textContent ?? "").replace(/\\s+/g, " ").trim(), 160)
|
|
2968
|
+
// A cut selector is invalid syntax; leave it out rather than pass it off as usable.
|
|
2969
|
+
return { label: clip(label, 200), selector: selector.length > 2000 ? "" : selector, ...(text ? { text } : {}) }
|
|
2970
|
+
}`,
|
|
2971
|
+
),
|
|
2972
|
+
)
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2975
|
+
async function accessibility(element: Element) {
|
|
2976
|
+
const tree = await cdp
|
|
2977
|
+
.send(
|
|
2978
|
+
"Accessibility.getPartialAXTree",
|
|
2979
|
+
{ backendNodeId: element.backendID, fetchRelatives: false },
|
|
2980
|
+
element.sessionID,
|
|
2981
|
+
)
|
|
2982
|
+
.catch(() => undefined)
|
|
2983
|
+
|
|
2984
|
+
const node = tree?.nodes.find((node) => node.backendDOMNodeId === element.backendID && !node.ignored)
|
|
2985
|
+
const role = String(node?.role?.value ?? "")
|
|
2986
|
+
|
|
2987
|
+
const name = String(node?.name?.value ?? "")
|
|
2988
|
+
.replace(/\s+/g, " ")
|
|
2989
|
+
.trim()
|
|
2990
|
+
.slice(0, 160)
|
|
2991
|
+
|
|
2992
|
+
const labeled = role && !["generic", "none", "presentation"].includes(role) ? { role: role.slice(0, 128) } : {}
|
|
2993
|
+
|
|
2994
|
+
return name ? { ...labeled, name } : labeled
|
|
2995
|
+
}
|
|
2996
|
+
|
|
2997
|
+
// Give the picker or scrolled input target a chance to lay out. This is not a compositor acknowledgement;
|
|
2998
|
+
// screenshots wait for their own redraw instead.
|
|
2999
|
+
async function painted(sessionID?: string) {
|
|
3000
|
+
await Promise.race([
|
|
3001
|
+
cdp
|
|
3002
|
+
.send(
|
|
3003
|
+
"Runtime.evaluate",
|
|
3004
|
+
{
|
|
3005
|
+
expression: "new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)))",
|
|
3006
|
+
awaitPromise: true,
|
|
3007
|
+
},
|
|
3008
|
+
sessionID,
|
|
3009
|
+
)
|
|
3010
|
+
.catch(() => undefined),
|
|
3011
|
+
new Promise((resolve) => setTimeout(resolve, 150)),
|
|
3012
|
+
])
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
|
|
3016
|
+
function scaleRect(box: PaneElement["rect"], scale: number) {
|
|
3017
|
+
return { x: box.x * scale, y: box.y * scale, width: box.width * scale, height: box.height * scale }
|
|
3018
|
+
}
|