From 23c49aa3d28730be657387cf9c061fb3a3bb53a8 Mon Sep 17 00:00:00 2001 From: brother7 <7brother7@gmail.com> Date: Thu, 27 Aug 2026 02:35:36 +0800 Subject: [PATCH] fix(agent-browser): enable preview page domain --- .../tasks/20260827-x01-cdp-enable-4e8a2c71.md | 73 +++++++++++++++++++ electron/agent-browser/module.ts | 5 ++ tests/unit/agent-browser-core.test.ts | 20 +++++ 3 files changed, 98 insertions(+) create mode 100644 .project-docs/30-worklog/tasks/20260827-x01-cdp-enable-4e8a2c71.md diff --git a/.project-docs/30-worklog/tasks/20260827-x01-cdp-enable-4e8a2c71.md b/.project-docs/30-worklog/tasks/20260827-x01-cdp-enable-4e8a2c71.md new file mode 100644 index 0000000..655a83e --- /dev/null +++ b/.project-docs/30-worklog/tasks/20260827-x01-cdp-enable-4e8a2c71.md @@ -0,0 +1,73 @@ +# Task: Remediate X-01 preview CDP enable + +## Identity + +- Task ID: 20260827-x01-cdp-enable-4e8a2c71 +- Mode: Feature +- Branch: codex/20260827-x01-cdp-enable-4e8a2c71-x01-cdp-enable-4e8a2c71 +- Worktree: D:\Datas\OthersProjects\makelore-x01-cdp-enable-4e8a2c71 +- Base commit: afb5c10fae090567869fcd7a10410a8be2c963ad +- Owner: codex +- Status: Ready for Integration + +## Scope + +- Update `electron/agent-browser/module.ts` so preview-data CDP setup enables the + same root or child session immediately before `Page.addScriptToEvaluateOnNewDocument`. +- Add focused root/child ordering and `sessionRef` regression coverage in + `tests/unit/agent-browser-core.test.ts`. +- Maintain this task record only; no coordinator worktree, PR, live run, or + broader CDP refactor. + +## Intent And Constraints + +- Exact remediation for X-01 packaged evidence: `Page.enable` must precede + every preview-data script installation while preserving the optional + `sessionRef`. +- Preserve the existing target URL origin fix and exact-origin getter from the + base commit; ownership is limited to the two source/test files and this record. +- The prior injection-origin task was released before this task started; the + coordinator remains at the recorded exact base and is not modified. + +## Planning Gate + +- Result: Passed. +- Evidence: prior task released; isolated task/worktree started from + `afb5c10fae090567869fcd7a10410a8be2c963ad`; repository project-docs startup + instructions and architecture/coordinator scope records were read; no + conflicting ownership was found. + +## Plan + +1. Add `Page.enable` with the same optional session reference immediately before + each preview script command. +2. Assert root ordering and child ordering/session propagation in focused tests. +3. Run focused tests, typecheck, scoped lint, documentation drift, then commit + once and leave the worktree clean. + +## Outcome + +- Added `Page.enable` immediately before every preview-data + `Page.addScriptToEvaluateOnNewDocument` call, passing the same optional + `sessionRef` for root and document-child sessions. Added root and child + ordering/session propagation assertions while preserving the existing + target URL and exact-origin injection behavior. + +## Verification + +- PASS: `corepack pnpm vitest run tests/unit/agent-browser-core.test.ts` (77/77). +- PASS: `corepack pnpm run typecheck`. +- PASS: `corepack pnpm exec eslint electron/agent-browser/module.ts tests/unit/agent-browser-core.test.ts`. +- PASS: `git diff --check`. +- PASS: project-docs drift/completion gates (recorded before commit). +- The isolated worktree required `corepack pnpm install --frozen-lockfile --offline` + before the focused command; no tracked dependency files changed. + +## Follow-ups + +- None. No live/E2E run was requested for this bounded remediation. + +## Promotion Candidates + +- Commit the single source/test/documentation change after the documentation + gate passes. diff --git a/electron/agent-browser/module.ts b/electron/agent-browser/module.ts index 775efc1..fc028cb 100644 --- a/electron/agent-browser/module.ts +++ b/electron/agent-browser/module.ts @@ -865,6 +865,11 @@ export class AgentBrowserModule { value: PreviewDataInjectionValue, sessionRef?: string, ): Promise { + await record.view.webContents.debugger.sendCommand( + 'Page.enable', + undefined, + sessionRef, + ); const response = await record.view.webContents.debugger.sendCommand( 'Page.addScriptToEvaluateOnNewDocument', { source: previewDataInjectionScript(binding.session.origin, value) }, diff --git a/tests/unit/agent-browser-core.test.ts b/tests/unit/agent-browser-core.test.ts index 2be87ec..896f963 100644 --- a/tests/unit/agent-browser-core.test.ts +++ b/tests/unit/agent-browser-core.test.ts @@ -579,9 +579,16 @@ describe('AgentBrowserModule', () => { 'load:about:blank', 'attach:1.3', 'command:Target.setAutoAttach', + 'command:Page.enable', 'command:Page.addScriptToEvaluateOnNewDocument', 'load:http://127.0.0.1:4173/', ]); + expect(view.webContents.debugger.operationLog.indexOf('command:Page.enable')) + .toBeLessThan(view.webContents.debugger.operationLog.indexOf( + 'command:Page.addScriptToEvaluateOnNewDocument', + )); + expect(view.webContents.debugger.commands.find((command) => command.method === 'Page.enable')?.sessionRef) + .toBeUndefined(); expect(addScript?.params?.sessionRef).toBeUndefined(); expect(addScript?.params?.source).toContain('globalThis.location?.origin'); expect(addScript?.params?.source).toContain('http://127.0.0.1:13210/api/runtime/data/v1'); @@ -745,6 +752,10 @@ describe('AgentBrowserModule', () => { }); await vi.waitFor(() => { expect(view.webContents.debugger.commands).toEqual(expect.arrayContaining([ + expect.objectContaining({ + method: 'Page.enable', + sessionRef: 'child-session', + }), expect.objectContaining({ method: 'Page.addScriptToEvaluateOnNewDocument', sessionRef: 'child-session', @@ -754,6 +765,15 @@ describe('AgentBrowserModule', () => { sessionRef: 'child-session', }), ])); + const childEnableIndex = view.webContents.debugger.commands.findIndex( + (command) => command.method === 'Page.enable' && command.sessionRef === 'child-session', + ); + const childAddScriptIndex = view.webContents.debugger.commands.findIndex( + (command) => command.method === 'Page.addScriptToEvaluateOnNewDocument' + && command.sessionRef === 'child-session', + ); + expect(childEnableIndex).toBeGreaterThanOrEqual(0); + expect(childEnableIndex).toBeLessThan(childAddScriptIndex); }); });