lantern-harness 0.1.45 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +242 -0
- package/README.md +25 -8
- package/builtin/case-backup-contract.mjs +27 -0
- package/builtin/case-workflow-contract.mjs +158 -0
- package/builtin/session/lh-fs.mjs +93 -4
- package/builtin/session/lh-nav-groups.mjs +36 -1
- package/builtin/session/mcp-client.mjs +7 -3
- package/builtin/session/session-runs.mjs +5 -1
- package/builtin/session/skill-validation.mjs +72 -0
- package/builtin/session/space-layout.mjs +8 -1
- package/builtin/session/space-skills.mjs +758 -0
- package/cli/data-root.mjs +21 -4
- package/cli/lantern.mjs +26 -1
- package/cli/mcp-server.mjs +3733 -0
- package/cli/server.mjs +10 -2
- package/config/app.defaults.json +4 -2
- package/dist/500.html +14 -6
- package/dist/_astro/Base.BQf1tZMl.css +1 -0
- package/dist/_astro/Base.astro_astro_type_script_index_0_lang.Dm3O_y-S.js +2 -0
- package/dist/_astro/BusinessMapBoard.CYxHcku_.js +5 -0
- package/dist/_astro/CaseExecBoard.CK9aGPmH.js +1 -0
- package/dist/_astro/CaseExecutionBoard.C94pmIMQ.js +5 -0
- package/dist/_astro/CaseGenerateApp.D5xlk9At.js +10 -0
- package/dist/_astro/CasesLibrary.BHQC955x.js +21 -0
- package/dist/_astro/ChatApp.CIt15w_1.js +1 -0
- package/dist/_astro/ChatApp.d4a9R3YS.js +262 -0
- package/dist/_astro/{ConfirmDialog.DrrPf1MB.js → ConfirmDialog.DQFd6g2r.js} +1 -1
- package/dist/_astro/DashboardBoard.qgc1s7pG.js +5 -0
- package/dist/_astro/{DatePicker.Bkl71M49.js → DatePicker.BRO_CjVQ.js} +1 -1
- package/dist/_astro/DefectSubmitEntry.JI85N1-i.js +2 -0
- package/dist/_astro/DocsFileBrowser.z5JZ74cy.js +1 -0
- package/dist/_astro/{DocsPager.Duf4I68E.js → DocsPager.Dg765uHW.js} +1 -1
- package/dist/_astro/{DrawerField.BH3p4Q4D.js → DrawerField.CLdvmHc6.js} +1 -1
- package/dist/_astro/KnowledgeLibrary.mkShtVun.js +1 -0
- package/dist/_astro/LifeKrTasksBoard.DpAwQffE.js +1 -0
- package/dist/_astro/LifeKrTodosBoard.BIjPiZ8H.js +1 -0
- package/dist/_astro/LifeObjectivesBoard.DYwLHPEG.js +1 -0
- package/dist/_astro/LifePlanTypeSelect.CYaziESp.js +1 -0
- package/dist/_astro/{LifeReviewsBoard.BPXeVpg1.js → LifeReviewsBoard.DIxoWBDA.js} +3 -3
- package/dist/_astro/{LifeShared.tnT7aQON.js → LifeShared.DuFQsMEx.js} +2 -2
- package/dist/_astro/LifeStagesBoard.DtOri9EW.js +1 -0
- package/dist/_astro/LifeYearCycleSelect.ByJ9-PGg.js +1 -0
- package/dist/_astro/LifeYearPlansBoard.BQN07wcv.js +1 -0
- package/dist/_astro/MultiSelectDropdown.D-rbpivp.js +1 -0
- package/dist/_astro/{NamePromptDialog.Csfnh5eM.js → NamePromptDialog.KPCeXmri.js} +1 -1
- package/dist/_astro/NavLibraries.BO4ezcUc.js +1 -0
- package/dist/_astro/PluginsPage.B1VeDtLx.js +18 -0
- package/dist/_astro/PmBugsBoard.Ddl3kqqt.js +1 -0
- package/dist/_astro/PmIterationsBoard.BJN7disI.js +1 -0
- package/dist/_astro/{PmProjectDetail.DneFVBpy.js → PmProjectDetail.D78gWhqk.js} +1 -1
- package/dist/_astro/PmProjectsBoard.Bf8VB3t6.js +1 -0
- package/dist/_astro/PmRequirementsBoard.CDyNHN2a.js +1 -0
- package/dist/_astro/PmRequirementsBoard.DarfGIrL.js +1 -0
- package/dist/_astro/PmShared.TOjBbtV8.js +1 -0
- package/dist/_astro/ReportsPage.BXGduuY3.js +1 -0
- package/dist/_astro/ReqAnalysisBoard.WLtIfBg8.js +39 -0
- package/dist/_astro/RequirementBreakdownLibrary.DMoeTeqX.js +2 -0
- package/dist/_astro/RequirementsLibrary.Iv7zOqWe.js +1 -0
- package/dist/_astro/SearchableSelect.DXclLMJI.js +1 -0
- package/dist/_astro/SelectDropdown.D7IeyHDI.js +1 -0
- package/dist/_astro/SettingsDialog.BvDU9EU6.js +1 -0
- package/dist/_astro/SlideOverDrawer.CvyB-quk.js +1 -0
- package/dist/_astro/SpaceSwitcher.D9bBNQBZ.js +7 -0
- package/dist/_astro/{TableFieldConfig.C7O-mL-p.js → TableFieldConfig.DHj25OKN.js} +1 -1
- package/dist/_astro/{TagSelect.UUXgkMqJ.js → TagSelect.B_r2p0fp.js} +1 -1
- package/dist/_astro/TasksBoard.CXmGdylV.js +1 -0
- package/dist/_astro/TemplatesLibrary.DsL2q-wp.js +1 -0
- package/dist/_astro/TestReportsLibrary.BBC1TYgP.js +1 -0
- package/dist/_astro/TestStatsBoard.VXjP4hu6.js +1 -0
- package/dist/_astro/Toast.BydY-X7T.js +1 -0
- package/dist/_astro/TodosBoard.-yKgp06M.js +1 -0
- package/dist/_astro/UiAutoBoard.BD5ZyLHj.js +3 -0
- package/dist/_astro/UiAutoEnvPanel.DrHUOlmH.js +10 -0
- package/dist/_astro/UiAutoGenerationDialog.gypq1zP9.js +12 -0
- package/dist/_astro/UiAutoProjectsPage.Dhzr09E9.js +3 -0
- package/dist/_astro/app-config.BSO5r82v.js +1 -0
- package/dist/_astro/app-version.CkDFkv4s.js +1 -0
- package/dist/_astro/{bash-tools.D9HCzC_7.js → bash-tools.C4DJiRJs.js} +1 -1
- package/dist/_astro/business-map.BiJ85oxm.js +1 -0
- package/dist/_astro/business-map.DKwdW1VL.css +1 -0
- package/dist/_astro/case-fields.C03NY3zC.js +148 -0
- package/dist/_astro/case-gen-run.C4p8uyU3.js +26 -0
- package/dist/_astro/case-prompt.ByLTgz4r.js +2 -0
- package/dist/_astro/{case-review.TdDs1WFM.js → case-review.BodP2jKm.js} +2 -2
- package/dist/_astro/{case-template.Cd2xNbgy.js → case-template.CC2eXegU.js} +2 -2
- package/dist/_astro/case-types.BjF1BivA.js +1 -0
- package/dist/_astro/case-workflow-contract.BBQ9bbKL.js +1 -0
- package/dist/_astro/defect-submit.Dc49lFjm.css +1 -0
- package/dist/_astro/defect-workbench.DBmohR-y.js +6 -0
- package/dist/_astro/dialog.XgRGNF_Q.js +1 -0
- package/dist/_astro/doc-roots.C-20VD0x.js +1 -0
- package/dist/_astro/{hydrate-cache.B15Nrpq0.js → hydrate-cache.CMMErx63.js} +1 -1
- package/dist/_astro/i18n.CEWjL5GX.js +7 -0
- package/dist/_astro/{llm.DN5S1KBK.js → llm.BCYNgppW.js} +1 -1
- package/dist/_astro/mcp-tools.Kf-lupGn.js +7 -0
- package/dist/_astro/{open-docs-in-session.CRiZT022.js → open-docs-in-session.BoyV6R2A.js} +1 -1
- package/dist/_astro/plugins.ChGmBEkF.js +1 -0
- package/dist/_astro/project-docs.BRgNjXhG.js +1 -0
- package/dist/_astro/prompts-meta.VAjE4OET.js +2 -0
- package/dist/_astro/report-prompt.CwHuOcRN.js +1 -0
- package/dist/_astro/req-analysis.BLvcktvQ.js +31 -0
- package/dist/_astro/requirement-breakdown-library.l0rPd7b3.js +1 -0
- package/dist/_astro/{settings.38J2uD5M.js → settings.BojKNwUC.js} +2 -2
- package/dist/_astro/space-skills.CPucW8zt.js +1 -0
- package/dist/_astro/{spaces-client.DV04tRyD.js → spaces-client.B28rzu8J.js} +1 -1
- package/dist/_astro/story-review.dEBWTeOW.js +7 -0
- package/dist/_astro/test-points.BuNgdNcU.js +8 -0
- package/dist/_astro/test-reports.0gr6-c_0.js +19 -0
- package/dist/_astro/ui-auto-prompt.BmO3ja2m.js +8 -0
- package/dist/_astro/ui-auto.LUcREUMe.js +1 -0
- package/dist/_astro/{view-prefs.DhdLZjGh.js → view-prefs.CWc5cQ2q.js} +1 -1
- package/dist/business-map/index.html +988 -0
- package/dist/case-exec/index.html +15 -7
- package/dist/{prompts → case-execution}/index.html +17 -9
- package/dist/cases/api/index.html +988 -0
- package/dist/cases/automation/index.html +988 -0
- package/dist/cases/functional/index.html +988 -0
- package/dist/cases/generate/index.html +14 -6
- package/dist/cases/index.html +1 -1
- package/dist/cases/library/index.html +1 -980
- package/dist/cases/other/index.html +988 -0
- package/dist/cases/performance/index.html +988 -0
- package/dist/dashboard/index.html +15 -7
- package/dist/defect-rules/index.html +695 -0
- package/dist/defect-submit/index.html +695 -0
- package/dist/defect-submit/templates/index.html +695 -0
- package/dist/docs/changelog/index.html +289 -52
- package/dist/docs/install/index.html +50 -12
- package/dist/docs/manual/index.html +230 -82
- package/dist/knowledge/index.html +15 -7
- package/dist/life/kr-tasks/index.html +15 -7
- package/dist/life/kr-todos/index.html +15 -7
- package/dist/life/objectives/index.html +15 -7
- package/dist/life/reviews/index.html +15 -7
- package/dist/life/stages/index.html +15 -7
- package/dist/life/year-plans/index.html +15 -7
- package/dist/plugins/index.html +15 -7
- package/dist/pm/bugs/index.html +15 -7
- package/dist/pm/iterations/index.html +15 -7
- package/dist/pm/projects/detail/index.html +15 -7
- package/dist/pm/projects/index.html +15 -7
- package/dist/pm/requirements/index.html +15 -7
- package/dist/reports/index.html +15 -7
- package/dist/requirement-analysis/index.html +15 -7
- package/dist/requirement-breakdowns/index.html +988 -0
- package/dist/requirements/index.html +15 -7
- package/dist/tasks/index.html +15 -7
- package/dist/templates/index.html +15 -7
- package/dist/test-automation/index.html +15 -7
- package/dist/test-automation/projects/index.html +15 -7
- package/dist/test-reports/index.html +15 -7
- package/dist/test-stats/index.html +15 -7
- package/dist/todos/index.html +15 -7
- package/dist/workbench/index.html +14 -6
- package/docs/Codex-MCP/351/233/206/346/210/220.md +340 -0
- package/docs//344/270/232/345/212/241/345/234/260/345/233/276/350/257/204/344/274/260.md +39 -0
- package/docs//344/270/232/345/212/241/345/234/260/345/233/276/350/257/206/345/210/253/351/207/215/346/236/204/346/226/271/346/241/210.md +88 -0
- package/docs//344/274/232/350/257/235/346/217/222/344/273/266.md +28 -3
- package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +41 -1
- package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +65 -17
- package/docs//346/217/222/344/273/266/344/273/223/345/272/223/344/270/216/346/212/200/350/203/275/346/225/264/345/220/210/346/226/271/346/241/210.md +187 -0
- package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +219 -74
- package/lh-plugins/business-map/assistant.mjs +958 -0
- package/lh-plugins/business-map/auth-paths.mjs +61 -0
- package/lh-plugins/business-map/jobs.mjs +749 -0
- package/lh-plugins/business-map/login.mjs +295 -0
- package/lh-plugins/business-map/sources.mjs +1014 -0
- package/lh-plugins/case-automation/service.mjs +921 -0
- package/lh-plugins/case-automation/store.mjs +231 -0
- package/lh-plugins/case-automation/tables.mjs +115 -0
- package/lh-plugins/case-automation-prompt.mjs +57 -0
- package/lh-plugins/case-execution/assets.mjs +180 -0
- package/lh-plugins/case-execution/files.mjs +829 -0
- package/lh-plugins/case-execution/plans.mjs +318 -0
- package/lh-plugins/case-execution/service.mjs +1026 -0
- package/lh-plugins/case-execution-prompt.mjs +36 -0
- package/lh-plugins/lh-business-map.mjs +2431 -0
- package/lh-plugins/lh-case-automation.mjs +169 -0
- package/lh-plugins/lh-case-design.mjs +456 -0
- package/lh-plugins/lh-case-execution.mjs +356 -0
- package/lh-plugins/lh-case-review.mjs +29 -11
- package/lh-plugins/lh-config.mjs +13 -0
- package/lh-plugins/lh-defect-submit.mjs +989 -0
- package/lh-plugins/lh-project-docs.mjs +55 -140
- package/lh-plugins/lh-reports.mjs +29 -57
- package/lh-plugins/lh-req-analysis.mjs +32 -3
- package/lh-plugins/lh-req-breakdown-library.mjs +1084 -0
- package/lh-plugins/lh-uiauto.mjs +625 -24
- package/lh-plugins/plugin-prompts.mjs +20 -15
- package/lh-plugins/req-analysis-revision.mjs +24 -0
- package/lh-plugins/test-points-prompt.mjs +2 -3
- package/lh-plugins/uiauto-adapters/playwright.mjs +44 -4
- package/lh-plugins/uiauto-adapters/shared.mjs +4 -0
- package/lh-plugins/uiauto-auth-setup.mjs +218 -0
- package/lh-plugins/uiauto-explorer/apps.mjs +13 -2
- package/lh-plugins/uiauto-explorer/emit-files.mjs +16 -2
- package/lh-plugins/uiauto-explorer/ir.mjs +3 -0
- package/lh-plugins/uiauto-explorer/merge.mjs +37 -1
- package/lh-plugins/uiauto-explorer/navigation-guard.mjs +255 -0
- package/lh-plugins/uiauto-explorer/runner.mjs +80 -5
- package/lh-plugins/uiauto-explorer/sessions.mjs +334 -18
- package/lh-plugins/uiauto-node.mjs +102 -11
- package/lh-plugins/uiauto-prompt.mjs +20 -15
- package/lh-plugins/uiauto-sso.mjs +407 -0
- package/package.json +5 -2
- package/skills/case-automation-bridge/SKILL.md +27 -0
- package/skills/case-execution/SKILL.md +41 -0
- package/skills/lantern-defect-submit/SKILL.md +15 -0
- package/skills/lantern-workflow/SKILL.md +95 -0
- package/skills/office/SKILL.md +26 -0
- package/dist/_astro/Base.Bkt1lrgu.css +0 -1
- package/dist/_astro/Base.astro_astro_type_script_index_0_lang.UKTVQqk7.js +0 -2
- package/dist/_astro/CaseExecBoard.DICluCbK.js +0 -1
- package/dist/_astro/CaseGenerateApp.Be3h5XPG.js +0 -10
- package/dist/_astro/CasesLibrary.Buys7Cy-.js +0 -21
- package/dist/_astro/ChatApp.D3BheKci.js +0 -227
- package/dist/_astro/DashboardBoard.Qvf8o4v1.js +0 -5
- package/dist/_astro/DocsFileBrowser.DwKBffbM.js +0 -1
- package/dist/_astro/KnowledgeLibrary.MDpMqeOd.js +0 -1
- package/dist/_astro/LifeKrTasksBoard.DsvW_S66.js +0 -1
- package/dist/_astro/LifeKrTodosBoard.D2KTqvg1.js +0 -1
- package/dist/_astro/LifeObjectivesBoard.B0cDK934.js +0 -1
- package/dist/_astro/LifePlanTypeSelect.BELDvMWU.js +0 -1
- package/dist/_astro/LifeStagesBoard.CZftLR9K.js +0 -1
- package/dist/_astro/LifeYearCycleSelect.Bw2eRbSm.js +0 -1
- package/dist/_astro/LifeYearPlansBoard.DB-RJFEl.js +0 -1
- package/dist/_astro/MultiSelectDropdown.CBC7aNOv.js +0 -1
- package/dist/_astro/NavLibraries.DdQYsZbe.js +0 -1
- package/dist/_astro/OverflowHint.CHZeFfUj.js +0 -1
- package/dist/_astro/PluginsPage.C1JnInH4.js +0 -17
- package/dist/_astro/PluginsPage.C3eEwy3K.js +0 -1
- package/dist/_astro/PmBugsBoard.CGpXUTPu.js +0 -1
- package/dist/_astro/PmIterationsBoard.BaKiFIam.js +0 -1
- package/dist/_astro/PmProjectsBoard.BxoMF9gK.js +0 -1
- package/dist/_astro/PmRequirementsBoard.-SI8VZXI.js +0 -1
- package/dist/_astro/PmRequirementsBoard.DsK6RF7Q.js +0 -1
- package/dist/_astro/PmShared.BK8kWRSV.js +0 -1
- package/dist/_astro/PromptMountDialog.mrTx3U5T.js +0 -1
- package/dist/_astro/PromptsLibrary.B_SUf47p.js +0 -1
- package/dist/_astro/ReportsPage.B9lGg1_s.js +0 -16
- package/dist/_astro/ReqAnalysisBoard.CIZKnCQH.js +0 -39
- package/dist/_astro/RequirementsLibrary.cJc-bnGQ.js +0 -1
- package/dist/_astro/SearchableSelect.SyLRS-Jj.js +0 -1
- package/dist/_astro/SelectDropdown.T3CKHaLt.js +0 -1
- package/dist/_astro/SettingsDialog.DYdtCvLc.js +0 -1
- package/dist/_astro/SpaceSwitcher.C47_S1g9.js +0 -7
- package/dist/_astro/TasksBoard.BUEg2BYk.js +0 -1
- package/dist/_astro/TemplatesLibrary.BLVIphXO.js +0 -1
- package/dist/_astro/TestReportsLibrary.DVq30Jae.js +0 -1
- package/dist/_astro/TestStatsBoard.-5BWQ6bI.js +0 -1
- package/dist/_astro/Toast.BO2NFckG.js +0 -1
- package/dist/_astro/TodosBoard.DI_lTp2e.js +0 -1
- package/dist/_astro/UiAutoBoard.ChFdgv7s.js +0 -2
- package/dist/_astro/UiAutoEnvPanel.B50q4kYb.js +0 -19
- package/dist/_astro/UiAutoGenerationDialog.CLkFAHrm.js +0 -1
- package/dist/_astro/UiAutoProjectsPage.DCsDeN5d.js +0 -3
- package/dist/_astro/app-config.DkyjuL-S.js +0 -1
- package/dist/_astro/app-version.Cy-5oZO2.js +0 -1
- package/dist/_astro/case-fields.CmePqYfh.js +0 -148
- package/dist/_astro/case-gen-run.BklG1H8k.js +0 -22
- package/dist/_astro/case-types.DlFkbZJN.js +0 -1
- package/dist/_astro/dialog.DZHZCe_T.js +0 -1
- package/dist/_astro/doc-roots.CO3IBiY6.js +0 -1
- package/dist/_astro/i18n.D_aOCHSN.js +0 -7
- package/dist/_astro/markdown-client.BS19nLL3.js +0 -62
- package/dist/_astro/plugins.BRvXWHLe.js +0 -1
- package/dist/_astro/project-docs.CCjtiFjB.js +0 -1
- package/dist/_astro/prompts-meta.BUGutlsk.js +0 -2
- package/dist/_astro/report-prompt.B9C4cv84.js +0 -1
- package/dist/_astro/req-analysis.B12_MGMQ.js +0 -31
- package/dist/_astro/story-review.D2W5tEOY.js +0 -14
- package/dist/_astro/test-reports.CuIjlEyK.js +0 -19
- package/dist/_astro/ui-auto-prompt.H9_yhau9.js +0 -9
- package/dist/_astro/ui-auto.DMv940x4.js +0 -1
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
const HTTP_PROTOCOLS = new Set(['http:', 'https:']);
|
|
2
|
+
const DOCUMENT_TYPES = new Set(['Document']);
|
|
3
|
+
const REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);
|
|
4
|
+
const MAX_BLOCKED_LOG = 80;
|
|
5
|
+
const MAX_REDIRECTS = 10;
|
|
6
|
+
|
|
7
|
+
function normalizeOrigin(value) {
|
|
8
|
+
try {
|
|
9
|
+
const url = new URL(String(value || ''));
|
|
10
|
+
if (!HTTP_PROTOCOLS.has(url.protocol) || url.username || url.password) return '';
|
|
11
|
+
return url.origin;
|
|
12
|
+
} catch {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function normalizeAllowedOrigins(values) {
|
|
18
|
+
if (!Array.isArray(values)) return [];
|
|
19
|
+
return [...new Set(values.map(normalizeOrigin).filter(Boolean))];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function isAllowedNavigationUrl(value, allowedOrigins) {
|
|
23
|
+
let url;
|
|
24
|
+
try {
|
|
25
|
+
url = new URL(String(value || ''));
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (url.href === 'about:blank') return true;
|
|
30
|
+
if (!HTTP_PROTOCOLS.has(url.protocol) || url.username || url.password) return false;
|
|
31
|
+
return allowedOrigins.includes(url.origin);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Keep every browser page, popup and redirect inside the explicitly allowed origins.
|
|
36
|
+
*
|
|
37
|
+
* Playwright's context route does not see the destination of a server-side redirect:
|
|
38
|
+
* Chromium follows the new Location internally. The CDP Fetch domain pauses every
|
|
39
|
+
* document request, including each redirect hop, before it is sent. The context route
|
|
40
|
+
* remains as the first-navigation guard for newly created popup pages, which can begin
|
|
41
|
+
* navigating before a page-specific CDP session is attached.
|
|
42
|
+
*/
|
|
43
|
+
export async function installNavigationGuard(context, rawOrigins, options = {}) {
|
|
44
|
+
const allowedOrigins = normalizeAllowedOrigins(rawOrigins);
|
|
45
|
+
if (!allowedOrigins.length) {
|
|
46
|
+
return {
|
|
47
|
+
allowedOrigins,
|
|
48
|
+
blocked: () => [],
|
|
49
|
+
guardPage: async () => undefined,
|
|
50
|
+
dispose: async () => undefined,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const onBlocked = typeof options.onBlocked === 'function' ? options.onBlocked : () => undefined;
|
|
55
|
+
const onError = typeof options.onError === 'function' ? options.onError : () => undefined;
|
|
56
|
+
const blocked = [];
|
|
57
|
+
const pageGuards = new WeakMap();
|
|
58
|
+
const sessions = new Set();
|
|
59
|
+
let disposed = false;
|
|
60
|
+
|
|
61
|
+
const recordBlocked = (value, source, pageUrl = '') => {
|
|
62
|
+
const entry = {
|
|
63
|
+
url: String(value || '').slice(0, 2000),
|
|
64
|
+
source,
|
|
65
|
+
pageUrl: String(pageUrl || '').slice(0, 2000),
|
|
66
|
+
allowedOrigins: [...allowedOrigins],
|
|
67
|
+
at: new Date().toISOString(),
|
|
68
|
+
};
|
|
69
|
+
blocked.push(entry);
|
|
70
|
+
if (blocked.length > MAX_BLOCKED_LOG) blocked.shift();
|
|
71
|
+
try {
|
|
72
|
+
onBlocked(entry);
|
|
73
|
+
} catch {
|
|
74
|
+
// A log sink must not weaken the navigation boundary.
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const safeRedirectHeaders = (headers, from, to) => {
|
|
79
|
+
if (from.origin === to.origin) return headers;
|
|
80
|
+
const next = { ...headers };
|
|
81
|
+
for (const name of [
|
|
82
|
+
'authorization',
|
|
83
|
+
'cookie',
|
|
84
|
+
'proxy-authorization',
|
|
85
|
+
'host',
|
|
86
|
+
'content-length',
|
|
87
|
+
]) {
|
|
88
|
+
delete next[name];
|
|
89
|
+
}
|
|
90
|
+
return next;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* New popup pages are not exposed to Playwright until their navigation finishes.
|
|
95
|
+
* For their first request, preflight every redirect with manual follow and stop on
|
|
96
|
+
* the first unauthorized Location. A successful first response is then fulfilled;
|
|
97
|
+
* for an allowed redirect chain Chromium can continue normally with the final URL.
|
|
98
|
+
*/
|
|
99
|
+
const inspectPopupNavigation = async (route, request) => {
|
|
100
|
+
let current = request.url();
|
|
101
|
+
let method = request.method();
|
|
102
|
+
let postData = request.postDataBuffer() || undefined;
|
|
103
|
+
let headers = await request.allHeaders().catch(() => request.headers());
|
|
104
|
+
let firstResponse = null;
|
|
105
|
+
for (let hop = 0; hop <= MAX_REDIRECTS; hop += 1) {
|
|
106
|
+
let response;
|
|
107
|
+
try {
|
|
108
|
+
response = await route.fetch({
|
|
109
|
+
url: current,
|
|
110
|
+
method,
|
|
111
|
+
headers,
|
|
112
|
+
postData,
|
|
113
|
+
maxRedirects: 0,
|
|
114
|
+
});
|
|
115
|
+
} catch (error) {
|
|
116
|
+
onError(error instanceof Error ? error : new Error(String(error)));
|
|
117
|
+
await route.abort('failed');
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
firstResponse ||= response;
|
|
121
|
+
if (!REDIRECT_STATUSES.has(response.status())) {
|
|
122
|
+
await route.fulfill({ response: firstResponse });
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
const location = response.headers().location;
|
|
126
|
+
if (!location) {
|
|
127
|
+
await route.fulfill({ response: firstResponse });
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
let next;
|
|
131
|
+
try {
|
|
132
|
+
next = new URL(location, current);
|
|
133
|
+
} catch {
|
|
134
|
+
recordBlocked(location, 'popup-redirect', current);
|
|
135
|
+
await route.abort('blockedbyclient');
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
if (!isAllowedNavigationUrl(next.href, allowedOrigins)) {
|
|
139
|
+
recordBlocked(next.href, 'popup-redirect', current);
|
|
140
|
+
await route.abort('blockedbyclient');
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
headers = safeRedirectHeaders(headers, new URL(current), next);
|
|
144
|
+
if (
|
|
145
|
+
response.status() === 303 ||
|
|
146
|
+
([301, 302].includes(response.status()) && method.toUpperCase() === 'POST')
|
|
147
|
+
) {
|
|
148
|
+
method = 'GET';
|
|
149
|
+
postData = undefined;
|
|
150
|
+
delete headers['content-type'];
|
|
151
|
+
delete headers['content-length'];
|
|
152
|
+
delete headers['transfer-encoding'];
|
|
153
|
+
}
|
|
154
|
+
current = next.href;
|
|
155
|
+
}
|
|
156
|
+
await route.abort('failed');
|
|
157
|
+
onError(new Error(`弹窗重定向超过 ${MAX_REDIRECTS} 次`));
|
|
158
|
+
return false;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
await context.route('**/*', async (route) => {
|
|
162
|
+
const request = route.request();
|
|
163
|
+
if (!request.isNavigationRequest()) return route.continue();
|
|
164
|
+
const allowed = isAllowedNavigationUrl(request.url(), allowedOrigins);
|
|
165
|
+
let pageUrl = '';
|
|
166
|
+
let requestPage = null;
|
|
167
|
+
let frameUnavailable = false;
|
|
168
|
+
try {
|
|
169
|
+
const frame = request.frame();
|
|
170
|
+
pageUrl = frame?.url() || '';
|
|
171
|
+
requestPage = frame?.page?.() || null;
|
|
172
|
+
} catch {
|
|
173
|
+
// Popup documents can be intercepted before Playwright has attached a frame.
|
|
174
|
+
frameUnavailable = true;
|
|
175
|
+
}
|
|
176
|
+
if (frameUnavailable) {
|
|
177
|
+
if (!allowed) {
|
|
178
|
+
recordBlocked(request.url(), 'route', pageUrl);
|
|
179
|
+
return route.abort('blockedbyclient');
|
|
180
|
+
}
|
|
181
|
+
await inspectPopupNavigation(route, request);
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
// A popup can begin navigating before context.on('page') finishes attaching CDP.
|
|
185
|
+
// Wait for the request page guard before releasing this first request, otherwise
|
|
186
|
+
// a same-origin popup that immediately 302s cross-origin could race the guard.
|
|
187
|
+
if (requestPage) await guardPage(requestPage);
|
|
188
|
+
else await Promise.all(context.pages().map((page) => guardPage(page)));
|
|
189
|
+
if (allowed) return route.continue();
|
|
190
|
+
recordBlocked(request.url(), 'route', pageUrl);
|
|
191
|
+
return route.abort('blockedbyclient');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
const guardPage = (page) => {
|
|
195
|
+
if (disposed) return Promise.resolve();
|
|
196
|
+
const existing = pageGuards.get(page);
|
|
197
|
+
if (existing) return existing;
|
|
198
|
+
const task = (async () => {
|
|
199
|
+
try {
|
|
200
|
+
const session = await context.newCDPSession(page);
|
|
201
|
+
if (disposed) {
|
|
202
|
+
await session.detach().catch(() => undefined);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
sessions.add(session);
|
|
206
|
+
session.on('Fetch.requestPaused', async (event) => {
|
|
207
|
+
if (disposed) return;
|
|
208
|
+
const isDocument = DOCUMENT_TYPES.has(event.resourceType);
|
|
209
|
+
const allowed = !isDocument || isAllowedNavigationUrl(event.request.url, allowedOrigins);
|
|
210
|
+
try {
|
|
211
|
+
if (allowed) {
|
|
212
|
+
await session.send('Fetch.continueRequest', { requestId: event.requestId });
|
|
213
|
+
} else {
|
|
214
|
+
recordBlocked(event.request.url, 'cdp', page.url());
|
|
215
|
+
await session.send('Fetch.failRequest', {
|
|
216
|
+
requestId: event.requestId,
|
|
217
|
+
errorReason: 'BlockedByClient',
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
} catch (error) {
|
|
221
|
+
if (!disposed) onError(error instanceof Error ? error : new Error(String(error)));
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
session.on('Inspector.detached', () => sessions.delete(session));
|
|
225
|
+
await session.send('Fetch.enable', {
|
|
226
|
+
patterns: [{ urlPattern: '*', requestStage: 'Request' }],
|
|
227
|
+
});
|
|
228
|
+
} catch (error) {
|
|
229
|
+
if (!disposed) onError(error instanceof Error ? error : new Error(String(error)));
|
|
230
|
+
}
|
|
231
|
+
})();
|
|
232
|
+
pageGuards.set(page, task);
|
|
233
|
+
return task;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
context.on('page', (page) => void guardPage(page));
|
|
237
|
+
await Promise.all(context.pages().map((page) => guardPage(page)));
|
|
238
|
+
|
|
239
|
+
return {
|
|
240
|
+
allowedOrigins,
|
|
241
|
+
blocked: () => blocked.map((entry) => ({ ...entry })),
|
|
242
|
+
guardPage,
|
|
243
|
+
dispose: async () => {
|
|
244
|
+
disposed = true;
|
|
245
|
+
await Promise.all(
|
|
246
|
+
[...sessions].map(async (session) => {
|
|
247
|
+
await session.send('Fetch.disable').catch(() => undefined);
|
|
248
|
+
await session.detach().catch(() => undefined);
|
|
249
|
+
}),
|
|
250
|
+
);
|
|
251
|
+
sessions.clear();
|
|
252
|
+
await context.unroute('**/*').catch(() => undefined);
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
}
|
|
@@ -17,6 +17,7 @@ import { createRequire } from 'node:module';
|
|
|
17
17
|
|
|
18
18
|
import { takeSnapshot, describeElement } from './snapshot.mjs';
|
|
19
19
|
import { probeLocators } from './locators.mjs';
|
|
20
|
+
import { installNavigationGuard, normalizeAllowedOrigins } from './navigation-guard.mjs';
|
|
20
21
|
|
|
21
22
|
const config = (() => {
|
|
22
23
|
try {
|
|
@@ -54,8 +55,11 @@ let page = null;
|
|
|
54
55
|
let closing = false;
|
|
55
56
|
let shotSeq = 0;
|
|
56
57
|
let lastAction = '';
|
|
58
|
+
let blockedSeq = 0;
|
|
59
|
+
let navigationGuard = null;
|
|
57
60
|
const consoleLog = [];
|
|
58
61
|
const networkLog = [];
|
|
62
|
+
const navigationBlockedLog = [];
|
|
59
63
|
|
|
60
64
|
function remember(list, entry, max = 120) {
|
|
61
65
|
list.push(entry);
|
|
@@ -72,6 +76,32 @@ function describeError(err) {
|
|
|
72
76
|
return message.split('\n').slice(0, 6).join('\n');
|
|
73
77
|
}
|
|
74
78
|
|
|
79
|
+
function rememberBlockedNavigation(entry) {
|
|
80
|
+
blockedSeq += 1;
|
|
81
|
+
const logged = { ...entry, seq: blockedSeq };
|
|
82
|
+
remember(navigationBlockedLog, logged);
|
|
83
|
+
remember(networkLog, {
|
|
84
|
+
status: 0,
|
|
85
|
+
url: logged.url,
|
|
86
|
+
method: 'GET',
|
|
87
|
+
failure: '跨域导航已拦截',
|
|
88
|
+
blocked: true,
|
|
89
|
+
source: logged.source,
|
|
90
|
+
});
|
|
91
|
+
return logged;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function blockedSince(seq) {
|
|
95
|
+
return navigationBlockedLog.filter((entry) => entry.seq > seq);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function navigationFailure(error, seq) {
|
|
99
|
+
const blocked = blockedSince(seq);
|
|
100
|
+
if (!blocked.length) return error;
|
|
101
|
+
const targets = [...new Set(blocked.map((entry) => entry.url))].slice(0, 3).join('、');
|
|
102
|
+
return new Error(`跨域导航已拦截:${targets}`);
|
|
103
|
+
}
|
|
104
|
+
|
|
75
105
|
async function resolveRef(ref) {
|
|
76
106
|
const handle = await page.evaluateHandle((key) => {
|
|
77
107
|
const store = window.__lanternRefs;
|
|
@@ -110,9 +140,16 @@ async function ensurePage() {
|
|
|
110
140
|
const handlers = {
|
|
111
141
|
async open(args) {
|
|
112
142
|
const url = String(args.url || '/').trim() || '/';
|
|
113
|
-
|
|
143
|
+
const beforeBlocked = blockedSeq;
|
|
144
|
+
try {
|
|
145
|
+
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30000 });
|
|
146
|
+
} catch (error) {
|
|
147
|
+
throw navigationFailure(error, beforeBlocked);
|
|
148
|
+
}
|
|
114
149
|
await page.waitForLoadState('networkidle', { timeout: 4000 }).catch(() => undefined);
|
|
115
150
|
await settle(args.settle ?? 400);
|
|
151
|
+
const blocked = blockedSince(beforeBlocked);
|
|
152
|
+
if (blocked.length) throw navigationFailure(new Error('页面访问被拦截'), beforeBlocked);
|
|
116
153
|
lastAction = `打开 ${url}`;
|
|
117
154
|
return snapshotResult(args);
|
|
118
155
|
},
|
|
@@ -127,6 +164,7 @@ const handlers = {
|
|
|
127
164
|
const action = String(args.action || '');
|
|
128
165
|
const ref = String(args.ref || '');
|
|
129
166
|
const note = String(args.note || '');
|
|
167
|
+
const beforeBlocked = blockedSeq;
|
|
130
168
|
let label = '';
|
|
131
169
|
const element = ref ? await resolveRef(ref) : null;
|
|
132
170
|
try {
|
|
@@ -165,12 +203,16 @@ const handlers = {
|
|
|
165
203
|
} else {
|
|
166
204
|
throw new Error(`不支持的动作:${action}`);
|
|
167
205
|
}
|
|
206
|
+
} catch (error) {
|
|
207
|
+
throw navigationFailure(error, beforeBlocked);
|
|
168
208
|
} finally {
|
|
169
209
|
if (element) await element.dispose().catch(() => undefined);
|
|
170
210
|
}
|
|
171
211
|
|
|
172
212
|
await page.waitForLoadState('networkidle', { timeout: 3000 }).catch(() => undefined);
|
|
173
213
|
await settle(args.settle ?? 300);
|
|
214
|
+
const blocked = blockedSince(beforeBlocked);
|
|
215
|
+
if (blocked.length) throw navigationFailure(new Error('页面操作触发了跨域导航'), beforeBlocked);
|
|
174
216
|
lastAction = note ? `${label}(${note})` : label;
|
|
175
217
|
if (args.snapshot === false) {
|
|
176
218
|
return { action: lastAction, url: page.url(), title: await page.title(), snapshot: '' };
|
|
@@ -233,7 +275,10 @@ const handlers = {
|
|
|
233
275
|
},
|
|
234
276
|
|
|
235
277
|
async network() {
|
|
236
|
-
return {
|
|
278
|
+
return {
|
|
279
|
+
requests: networkLog.slice(-40),
|
|
280
|
+
blockedNavigations: navigationBlockedLog.slice(-40),
|
|
281
|
+
};
|
|
237
282
|
},
|
|
238
283
|
|
|
239
284
|
async state() {
|
|
@@ -242,6 +287,8 @@ const handlers = {
|
|
|
242
287
|
},
|
|
243
288
|
|
|
244
289
|
async close() {
|
|
290
|
+
// 回包后立刻关;不要只靠外层 .then,避免父进程哨兵 id / 并发命令时漏关
|
|
291
|
+
void Promise.resolve().then(() => shutdown());
|
|
245
292
|
return { closed: true };
|
|
246
293
|
},
|
|
247
294
|
};
|
|
@@ -269,11 +316,27 @@ async function start() {
|
|
|
269
316
|
// 给主进程一点时间读到最后一行,然后退出;不留在后台当僵尸
|
|
270
317
|
setTimeout(() => process.exit(0), 50);
|
|
271
318
|
});
|
|
272
|
-
const
|
|
319
|
+
const allowedOrigins = normalizeAllowedOrigins(config.allowedOrigins);
|
|
320
|
+
const contextOptions = {
|
|
321
|
+
viewport: { width: 1440, height: 900 },
|
|
322
|
+
...(allowedOrigins.length ? { serviceWorkers: 'block' } : {}),
|
|
323
|
+
};
|
|
273
324
|
if (config.baseURL) contextOptions.baseURL = String(config.baseURL);
|
|
274
325
|
if (storageState && fs.existsSync(storageState)) contextOptions.storageState = storageState;
|
|
275
326
|
context = await browser.newContext(contextOptions);
|
|
327
|
+
if (allowedOrigins.length) {
|
|
328
|
+
navigationGuard = await installNavigationGuard(context, allowedOrigins, {
|
|
329
|
+
onBlocked: rememberBlockedNavigation,
|
|
330
|
+
onError: (error) => {
|
|
331
|
+
remember(consoleLog, {
|
|
332
|
+
type: 'navigation-guard',
|
|
333
|
+
text: describeError(error).slice(0, 500),
|
|
334
|
+
});
|
|
335
|
+
},
|
|
336
|
+
});
|
|
337
|
+
}
|
|
276
338
|
page = await context.newPage();
|
|
339
|
+
await navigationGuard?.guardPage(page);
|
|
277
340
|
page.setDefaultTimeout(15000);
|
|
278
341
|
// 文档编号随导航递增:旧 ref 在刷新后一定失效,而不是误指到别的元素
|
|
279
342
|
await page.addInitScript(() => {
|
|
@@ -317,6 +380,7 @@ async function start() {
|
|
|
317
380
|
|
|
318
381
|
async function shutdown() {
|
|
319
382
|
closing = true;
|
|
383
|
+
await navigationGuard?.dispose().catch(() => undefined);
|
|
320
384
|
try {
|
|
321
385
|
await context?.close();
|
|
322
386
|
} catch {
|
|
@@ -345,7 +409,19 @@ rl.on('line', (line) => {
|
|
|
345
409
|
return;
|
|
346
410
|
}
|
|
347
411
|
const { id, cmd, args } = message || {};
|
|
348
|
-
|
|
412
|
+
// 主动关窗优先:父进程可能用哨兵 id(如 -1),不能按 !id 直接丢弃
|
|
413
|
+
if (cmd === 'close') {
|
|
414
|
+
if (id != null && id !== '') {
|
|
415
|
+
try {
|
|
416
|
+
process.stdout.write(`${JSON.stringify({ id, ok: true, result: { closed: true } })}\n`);
|
|
417
|
+
} catch {
|
|
418
|
+
// 管道已断
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
void shutdown();
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
if (id == null || id === '') return;
|
|
349
425
|
const handler = handlers[cmd];
|
|
350
426
|
if (!handler) {
|
|
351
427
|
process.stdout.write(
|
|
@@ -357,7 +433,6 @@ rl.on('line', (line) => {
|
|
|
357
433
|
.then(() => handler(args || {}))
|
|
358
434
|
.then((result) => {
|
|
359
435
|
process.stdout.write(`${JSON.stringify({ id, ok: true, result })}\n`);
|
|
360
|
-
if (cmd === 'close') void shutdown();
|
|
361
436
|
})
|
|
362
437
|
.catch((err) => {
|
|
363
438
|
process.stdout.write(`${JSON.stringify({ id, ok: false, error: describeError(err) })}\n`);
|