diff --git a/frontend/src/shared/state/store.ts b/frontend/src/shared/state/store.ts index dffa7a6d..b4701ff1 100644 --- a/frontend/src/shared/state/store.ts +++ b/frontend/src/shared/state/store.ts @@ -58,9 +58,10 @@ export const store = configureStore({ export type RootState = ReturnType; export type AppDispatch = typeof store.dispatch; -// Expose the store on window in dev so playwright + the user's devtools -// can drive UI flows without hunting for selectors. The expose is -// guarded by NODE_ENV so production bundles don't ship it. -if (typeof window !== 'undefined' && process.env.NODE_ENV !== 'production') { +// Expose the store on window in dev. In production it stays hidden UNLESS the +// renderer was launched with __OPENSWARM_E2E__ pre-set by a Playwright init +// script, which is the only way the e2e visibility recorder can subscribe to +// state diffs against the packaged build. Normal user runs never set the flag. +if (typeof window !== 'undefined' && (process.env.NODE_ENV !== 'production' || (window as unknown as { __OPENSWARM_E2E__?: boolean }).__OPENSWARM_E2E__ === true)) { (window as unknown as { __OPENSWARM_STORE__?: typeof store }).__OPENSWARM_STORE__ = store; }