From 76cca7fc2c3dc5e58cf1acfbf956d862fbf207ce Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Thu, 1 Aug 2024 17:28:48 +0200 Subject: [PATCH] fix(ui): only populate settings once (#31958) We populate `localStorage` using an init script. Currently, this script isn't just run for the UI though, but also for all iframes. So we're resetting `localStorage` every time the UI loads an iframe. This hasn't been a problem in the past, because the only consumer of `localStorage`, `Settings`, only read from `localStorage` once and kept most state in `useState` afterwards. With https://github.com/microsoft/playwright/pull/31911, this is no longer true, so the bug starts biting us! The fix is to ensure the init script isn't run on iframes. --- packages/playwright-core/src/server/launchApp.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/playwright-core/src/server/launchApp.ts b/packages/playwright-core/src/server/launchApp.ts index 12cb343f95..eab457691c 100644 --- a/packages/playwright-core/src/server/launchApp.ts +++ b/packages/playwright-core/src/server/launchApp.ts @@ -90,6 +90,8 @@ export async function syncLocalStorageWithSettings(page: Page, appName: string) // iframes w/ snapshots, etc. if (location && location.protocol === 'data:') return; + if (window.top !== window) + return; Object.entries(settings).map(([k, v]) => localStorage[k] = v); (window as any).saveSettings = () => { (window as any)._saveSerializedSettings(JSON.stringify({ ...localStorage }));