fix(agent-browser): enable preview page domain

This commit is contained in:
2026-08-27 02:35:36 +08:00
parent afb5c10fae
commit 23c49aa3d2
3 changed files with 98 additions and 0 deletions

View File

@@ -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);
});
});