diff --git a/src/McpContext.ts b/src/McpContext.ts index 0b8107693..0b2f04d4b 100644 --- a/src/McpContext.ts +++ b/src/McpContext.ts @@ -290,7 +290,9 @@ export class McpContext implements Context { async restoreEmulation(page: McpPage) { const currentSetting = page.emulationSettings; - await this.emulate(currentSetting, page.pptrPage); + await this.emulate(currentSetting, page.pptrPage, { + skipNetworkReset: !currentSetting.networkConditions, + }); } async emulate( @@ -303,13 +305,18 @@ export class McpContext implements Context { viewport?: Viewport; }, targetPage?: Page, + internalOptions: { + skipNetworkReset?: boolean; + } = {}, ): Promise { const page = targetPage ?? this.getSelectedPptrPage(); const mcpPage = this.#getMcpPage(page); const newSettings: EmulationSettings = {...mcpPage.emulationSettings}; if (!options.networkConditions) { - await page.emulateNetworkConditions(null); + if (!internalOptions.skipNetworkReset) { + await page.emulateNetworkConditions(null); + } delete newSettings.networkConditions; } else if (options.networkConditions === 'Offline') { await page.emulateNetworkConditions({ diff --git a/tests/McpContext.test.ts b/tests/McpContext.test.ts index 487e59561..73d8ce487 100644 --- a/tests/McpContext.test.ts +++ b/tests/McpContext.test.ts @@ -71,6 +71,20 @@ describe('McpContext', () => { }); }); + it('does not reset network during restore when no network emulation exists', async () => { + await withMcpContext(async (_response, context) => { + const page = context.getSelectedMcpPage(); + const emulateNetworkConditionsSpy = sinon.spy( + page.pptrPage, + 'emulateNetworkConditions', + ); + + await context.restoreEmulation(page); + + sinon.assert.notCalled(emulateNetworkConditionsSpy); + }); + }); + it('should call waitForEventsAfterAction with correct multipliers', async () => { await withMcpContext(async (_response, context) => { const page = await context.newPage();