fix(agent-browser): preserve preview injection origin

This commit is contained in:
2026-08-27 01:55:49 +08:00
parent 2f346687b1
commit 0a4f526c2c
3 changed files with 125 additions and 2 deletions

View File

@@ -609,6 +609,33 @@ describe('AgentBrowserModule', () => {
expect(externalGlobal.__MAKELORE_DATA__).toBeUndefined();
});
it('uses the target Origin when the prime navigation reports about:blank', async () => {
const adapter = new FakeAdapter();
const preview = new FakePreviewDataSession();
adapter.onCreate = (view) => {
view.webContents.loadHandler = async (url) => {
view.webContents.emit('did-navigate', {}, url);
};
view.webContents.debugger.responders.set('Page.addScriptToEvaluateOnNewDocument', async () => ({
identifier: 'script-root',
}));
};
const module = new AgentBrowserModule(adapter, { previewDataSession: preview });
await module.open({
projectId: 'clock',
projectPath,
url: 'http://127.0.0.1:4173/',
injectProjectData: true,
});
expect(preview.opens).toEqual([{
projectPath,
origin: 'http://127.0.0.1:4173',
browserGeneration: 1,
}]);
});
it('fails and tears down before target load when preview session setup fails', async () => {
const adapter = new FakeAdapter();
const preview = new FakePreviewDataSession();