ProtectedconstructorMaximum number of tests a recycled context can serve before being automatically rotated (closed and recreated). Long-lived contexts accumulate localStorage entries, dirty SPA state, and memory pressure which leads to load failures after ~25 reuses.
Diagnostic: how many workers have cached storage state. Used by tests to verify that capture+replay is wired correctly.
StaticInstanceThe Global Object Store is a place to store global objects that need to be shared across the application. Depending on the execution environment, this could be the window object in a browser, or the global object in a node environment, or something else in other contexts. The key here is that in some cases static variables are not truly shared because it is possible that a given class might have copies of its code in multiple paths in a deployed application. This approach ensures that no matter how many code copies might exist, there is only one instance of the object in question by using the Global Object Store.
Get an isolated adapter — a fresh BrowserContext seeded with the
cached storageState (cookies + localStorage) for the given worker
key, if any. Every call returns a NEW context, even within the same
worker, so test mutations cannot leak forward.
Pair every GetIsolated(key) with ReleaseIsolated(adapter) after
the test completes — that's when the context's storage is captured
back into _workerStorageState[key] for the next test in the worker
to replay. Without the matching release, the cache won't update and
subsequent tests will start from the previous cached state (or empty).
Stable identifier for the worker (e.g. worker-0).
All tests run by this worker share the same cached
storage state.
Optionalconfig: BrowserConfigBrowser config used when constructing the context.
Create a brand-new BrowserContext and adapter. The caller owns the lifecycle — call adapter.Close() when done. The context is not tracked by key and cannot be recycled.
Optionalconfig: BrowserConfigGet a recycled adapter for the given key. If no context exists for the key, a new one is created. If one already exists, the same adapter is returned — auth state (localStorage, cookies) persists.
After RotateAfterUses checkouts, the context is automatically rotated (closed and a fresh one created) to prevent state accumulation.
Identifies the shared session (e.g. "suite:abc:worker-0")
Optionalconfig: BrowserConfigBrowser config used only when creating a new context
Launch or attach to the shared Chromium browser. Safe to call multiple times — subsequent calls are no-ops if the browser is already running.
Run launched browser without a visible window.
Ignored when connect is set (the external browser
already decided).
Optionalconnect: stringOptional. Endpoint of an already-running browser to
attach to instead of launching one. http(s)://… uses
Chrome DevTools Protocol; ws(s)://… uses a Playwright
browser server. When set, Shutdown() will NOT close
the browser — the caller owns its lifecycle.
OptionalconnectType: "cdp" | "server" | "auto"Force the connect method. Defaults to 'auto'
(scheme-based detection). Ignored when connect is unset.
Note: this is a process-wide singleton. When the test driver runs
parallel workers and one of them passes connect, every worker that
subsequently calls Initialize (or hits ensureBrowser via GetNew /
GetRecycled / GetIsolated) will share the same attached browser —
the first call wins. Callers should ensure all workers agree on the
connect endpoint.
Forget the cached storage state for a worker — the next GetIsolated
call for the same key will create a context with no auth seed,
forcing the AuthHandler to run from scratch. Use when a token has
expired mid-suite or when an opt-out is desired.
Release a single recycled key — closes the adapter's page and the underlying BrowserContext. The key can be reused after release (a new context will be created on next GetRecycled call).
Release all recycled contexts. Does not close the browser itself.
Release an isolated adapter — captures the context's storageState
back into the worker's cache (so the next isolated context for the
same worker replays auth + cookies + localStorage), then closes the
adapter's page and the underlying context.
No-op when the adapter was not produced by GetIsolated. Best-effort
on failures — closing always proceeds.
Full shutdown: close all fresh adapters, release all recycled contexts, close the browser. Safe to call multiple times.
When attached to an external browser (_connected === true), the
browser itself is NOT closed — the caller owns its lifecycle. All
contexts WE created (recycled, fresh, isolated) ARE closed.
Protected StaticgetReturns the singleton instance of the class. If the instance does not exist, it is created and stored in the Global Object Store. If className is provided it will be used as part of the key in the Global Object Store, otherwise the actual class name will be used. NOTE: the class name used by default is the lowest level of the object hierarchy, so if you have a class that extends another class, the lowest level class name will be used.
OptionalclassName: string
Generic, abstract base class for any scenario where we want to use a Singleton pattern. This base class abstracts away the complexity of ensuring a truly global singleton instance across multiple code paths in a deployed application. It uses a Global Object Store to ensure that only one instance of the class exists in the application even if the class has code imported into multiple execution paths (which is not optimal, of course, but can occur in some situations).