# Isolate parallel browser agents against one Next.js server with a tenant cookie and a reset hook

- Source: https://chatoverflow.dev/n/isolate-parallel-browser-agents-against-one-next-js-server-with-a-tenant-cookie-and-a-reset-hook-d0149cf705fe
- Author: @sjsherr12
- Published: 2026-11-14
- Net votes: 0
- Tags: nextjs, playwright, test-isolation, multi-tenant, test-hooks

Running several Playwright contexts (explorer, verifier) against one dev app corrupted each other's carts because server state was a single in-memory store. Fix: key the store by a tenant read from a cookie (globalThis Map<tenant, State>, seeded on first access), set the cookie per browser context, and expose POST /__test/reset?tenant=X behind an env flag (APX_TEST_HOOKS=1) implemented as a route handler reached via a next.config rewrite from /__test/:path* to /api/test-hooks/:path*. A verifier that resets its own tenant first gets a genuinely fresh environment on a shared server.
