fix(agent-browser): enable preview page domain
This commit is contained in:
@@ -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.
|
||||||
@@ -865,6 +865,11 @@ export class AgentBrowserModule {
|
|||||||
value: PreviewDataInjectionValue,
|
value: PreviewDataInjectionValue,
|
||||||
sessionRef?: string,
|
sessionRef?: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
await record.view.webContents.debugger.sendCommand(
|
||||||
|
'Page.enable',
|
||||||
|
undefined,
|
||||||
|
sessionRef,
|
||||||
|
);
|
||||||
const response = await record.view.webContents.debugger.sendCommand(
|
const response = await record.view.webContents.debugger.sendCommand(
|
||||||
'Page.addScriptToEvaluateOnNewDocument',
|
'Page.addScriptToEvaluateOnNewDocument',
|
||||||
{ source: previewDataInjectionScript(binding.session.origin, value) },
|
{ source: previewDataInjectionScript(binding.session.origin, value) },
|
||||||
|
|||||||
@@ -579,9 +579,16 @@ describe('AgentBrowserModule', () => {
|
|||||||
'load:about:blank',
|
'load:about:blank',
|
||||||
'attach:1.3',
|
'attach:1.3',
|
||||||
'command:Target.setAutoAttach',
|
'command:Target.setAutoAttach',
|
||||||
|
'command:Page.enable',
|
||||||
'command:Page.addScriptToEvaluateOnNewDocument',
|
'command:Page.addScriptToEvaluateOnNewDocument',
|
||||||
'load:http://127.0.0.1:4173/',
|
'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?.sessionRef).toBeUndefined();
|
||||||
expect(addScript?.params?.source).toContain('globalThis.location?.origin');
|
expect(addScript?.params?.source).toContain('globalThis.location?.origin');
|
||||||
expect(addScript?.params?.source).toContain('http://127.0.0.1:13210/api/runtime/data/v1');
|
expect(addScript?.params?.source).toContain('http://127.0.0.1:13210/api/runtime/data/v1');
|
||||||
@@ -745,6 +752,10 @@ describe('AgentBrowserModule', () => {
|
|||||||
});
|
});
|
||||||
await vi.waitFor(() => {
|
await vi.waitFor(() => {
|
||||||
expect(view.webContents.debugger.commands).toEqual(expect.arrayContaining([
|
expect(view.webContents.debugger.commands).toEqual(expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
method: 'Page.enable',
|
||||||
|
sessionRef: 'child-session',
|
||||||
|
}),
|
||||||
expect.objectContaining({
|
expect.objectContaining({
|
||||||
method: 'Page.addScriptToEvaluateOnNewDocument',
|
method: 'Page.addScriptToEvaluateOnNewDocument',
|
||||||
sessionRef: 'child-session',
|
sessionRef: 'child-session',
|
||||||
@@ -754,6 +765,15 @@ describe('AgentBrowserModule', () => {
|
|||||||
sessionRef: 'child-session',
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user