Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/McpContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -297,13 +299,18 @@ export class McpContext implements Context {
viewport?: Viewport;
},
targetPage?: Page,
internalOptions: {
skipNetworkReset?: boolean;
} = {},
): Promise<void> {
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({
Expand Down
14 changes: 14 additions & 0 deletions tests/McpContext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down