fix(agent-browser): defer preview origin exposure
This commit is contained in:
@@ -600,7 +600,9 @@ describe('AgentBrowserModule', () => {
|
||||
contractVersion: 1,
|
||||
});
|
||||
const descriptor = Object.getOwnPropertyDescriptor(sameOriginGlobal, '__MAKELORE_DATA__');
|
||||
expect(descriptor).toMatchObject({ enumerable: false, writable: false, configurable: false });
|
||||
expect(descriptor).toMatchObject({ enumerable: false, configurable: false });
|
||||
expect(descriptor?.get).toEqual(expect.any(Function));
|
||||
expect(descriptor).not.toHaveProperty('value');
|
||||
|
||||
const externalGlobal: Record<string, unknown> = {
|
||||
location: { origin: 'https://external.example' },
|
||||
@@ -609,6 +611,48 @@ describe('AgentBrowserModule', () => {
|
||||
expect(externalGlobal.__MAKELORE_DATA__).toBeUndefined();
|
||||
});
|
||||
|
||||
it('resolves preview data after an early unstable Origin settles', async () => {
|
||||
const adapter = new FakeAdapter();
|
||||
const preview = new FakePreviewDataSession();
|
||||
adapter.onCreate = (view) => {
|
||||
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,
|
||||
});
|
||||
const source = adapter.views[0].webContents.debugger.commands.find(
|
||||
(command) => command.method === 'Page.addScriptToEvaluateOnNewDocument',
|
||||
)?.params?.source;
|
||||
expect(typeof source).toBe('string');
|
||||
|
||||
const changingGlobal: { location: { origin: string }; __MAKELORE_DATA__?: unknown } = {
|
||||
location: { origin: 'null' },
|
||||
};
|
||||
runInNewContext(source as string, changingGlobal);
|
||||
expect(changingGlobal.__MAKELORE_DATA__).toBeUndefined();
|
||||
|
||||
changingGlobal.location.origin = 'http://127.0.0.1:4173';
|
||||
expect(changingGlobal.__MAKELORE_DATA__).toEqual({
|
||||
endpoint: 'http://127.0.0.1:13210/api/runtime/data/v1',
|
||||
token: 'preview-token',
|
||||
contractVersion: 1,
|
||||
});
|
||||
const descriptor = Object.getOwnPropertyDescriptor(changingGlobal, '__MAKELORE_DATA__');
|
||||
expect(descriptor).toMatchObject({ enumerable: false, configurable: false });
|
||||
expect(descriptor?.get).toEqual(expect.any(Function));
|
||||
expect(String(descriptor?.get)).not.toContain('preview-token');
|
||||
|
||||
changingGlobal.location.origin = 'https://external.example';
|
||||
expect(changingGlobal.__MAKELORE_DATA__).toBeUndefined();
|
||||
});
|
||||
|
||||
it('uses the target Origin when the prime navigation reports about:blank', async () => {
|
||||
const adapter = new FakeAdapter();
|
||||
const preview = new FakePreviewDataSession();
|
||||
|
||||
Reference in New Issue
Block a user