gamesheet_sdk.common.browser¶
Reusable Playwright browser session for the JS-heavy WebUI path.
Sibling of gamesheet_sdk.common.session with matching shape:
- One context owning cookies and localStorage.
- Storage state persisted via Config.browser_state_path.
- Base-URL resolution against Config.base_url.
- Context-manager that saves state on exit.
Browsers are heavyweight, so BrowserSession starts Playwright
lazily on first reach for the browser; bare construction is free.
Classes
A Playwright-driven session for the JavaScript-heavy code path. |
- class gamesheet_sdk.common.browser.BrowserSession[source]¶
Bases:
objectA Playwright-driven session for the JavaScript-heavy code path.
Mirror of
gamesheet_sdk.Sessionfor flows whererequestsis not enough (single-page apps, anti-bot challenges, anything that needs a real engine to render).Example:
from gamesheet_sdk import BrowserSession, Config with BrowserSession(Config()) as bs: page = bs.goto("/login") page.fill("input[name='email']", "...")
Initialize a browser session without starting Playwright.
Stores the configuration and sets up internal state for lazy browser initialization. Playwright and Chromium are only launched when
contextorgoto()is first accessed. This makes construction cheap and allows sessions that never reach for the browser (e.g. configuration-only runs) to avoid the startup overhead.- Parameters:
config (Config | None) – Optional configuration object. If
None, a defaultConfigis created.
- __init__(config=None)[source]¶
Initialize a browser session without starting Playwright.
Stores the configuration and sets up internal state for lazy browser initialization. Playwright and Chromium are only launched when
contextorgoto()is first accessed. This makes construction cheap and allows sessions that never reach for the browser (e.g. configuration-only runs) to avoid the startup overhead.
- property context: BrowserContext¶
The underlying Playwright BrowserContext.
Starts Playwright and launches Chromium on first access, so a
BrowserSessionthat never reaches for the browser is effectively free.- Returns:
The active browser context.
- Return type:
BrowserContext
- Raises:
RuntimeError – If the session has already been closed.
ValueError – If the browser failed to start (defensive check).
- new_page()[source]¶
Open a fresh tab in the session’s context and return it.
Starts Playwright and Chromium on first call if not already running. :returns: Return value. :rtype: Page
- Return type:
Page
- goto(url, **kwargs)[source]¶
Open a fresh tab navigated to
url.urlmay be absolute or a path relative toConfig.base_url. Starts Playwright and Chromium on first call if not already running.Example:
with BrowserSession() as bs: page = bs.goto("/login", wait_until="networkidle") page.fill("input[name='email']", "test@example.com")
- Parameters:
url (str) – An absolute or relative URL to navigate to.
kwargs (Any) – Additional keyword arguments passed to
playwright.sync_api.Page.goto().
- Returns:
A
Pagenavigated to the resolved URL.- Return type:
Page