fix(browser): retain attached scenario emulation until cleanup

This commit is contained in:
dakjdakd
2026-10-10 01:45:00 +08:00
committed by morluto
parent 5e8fb531e2
commit a0523b375e
5 changed files with 240 additions and 16 deletions
+14 -16
View File
@@ -173,22 +173,20 @@ const configureAttachedEnvironment = async (
reducedMotion: scenario.environment.reduced_motion,
});
const session = await context.newCDPSession(page);
try {
await session.send("Emulation.setDeviceMetricsOverride", {
width: scenario.environment.viewport.width,
height: scenario.environment.viewport.height,
deviceScaleFactor: scenario.environment.viewport.device_scale_factor,
mobile: false,
});
await session.send("Emulation.setLocaleOverride", {
locale: scenario.environment.locale,
});
await session.send("Emulation.setTimezoneOverride", {
timezoneId: scenario.environment.timezone,
});
} finally {
await session.detach();
}
// Chromium resets these overrides when the CDP session detaches. Keep it on
// the scenario transport until cleanup disconnects the attached browser.
await session.send("Emulation.setDeviceMetricsOverride", {
width: scenario.environment.viewport.width,
height: scenario.environment.viewport.height,
deviceScaleFactor: scenario.environment.viewport.device_scale_factor,
mobile: false,
});
await session.send("Emulation.setLocaleOverride", {
locale: scenario.environment.locale,
});
await session.send("Emulation.setTimezoneOverride", {
timezoneId: scenario.environment.timezone,
});
};
/** Preserve an operation failure while reporting any incomplete cleanup. */