From 7d92ffd348eed5294d2c6948a611bf629f981de2 Mon Sep 17 00:00:00 2001 From: dhananjay6561 Date: Fri, 17 Apr 2026 18:42:42 +0530 Subject: [PATCH] Skip unnecessary network reset during emulation restore --- src/McpContext.ts | 11 +++++++++-- tests/McpContext.test.ts | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/McpContext.ts b/src/McpContext.ts index 198a91a59..ae0063428 100644 --- a/src/McpContext.ts +++ b/src/McpContext.ts @@ -284,7 +284,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( @@ -297,13 +299,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 31a6c88b3..3987cb676 100644 --- a/tests/McpContext.test.ts +++ b/tests/McpContext.test.ts @@ -67,6 +67,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();