# Browser API The `Browser` class is the main entry point for browser automation. > **Heads-up.** `browser.click()`, `browser.find()`, `browser.evaluate()` > and the other DOM-touching shortcuts target the focused page in > `browser.defaultContext` — i.e. `(await browser.activePage()).X(...)`. > They never reach into pages inside a context created by > `browser.newContext()`. See > [Getting Started — `browser.X()` vs `page.X()`](./getting-started.md#browserx-vs-pagex--when-to-use-which). ## Launching ```typescript import { Browser } from 'craftdriver'; const browser = await Browser.launch({ browserName: 'chrome' }); // With pre-loaded session state const browser = await Browser.launch({ browserName: 'chrome', storageState: './auth.json', }); ``` ### Launch options | Option | Type | Default | Description | |--------|------|---------|-------------| | `browserName` | `'chrome' \| 'chromium' \| 'firefox'` | `'chrome'` | Browser to launch | | `enableBiDi` | `boolean` | `true` | Use WebDriver BiDi. Set `false` only when running against a browser that does not support it. | | `storageState` | `string` | — | Path to a session-state JSON file to load on startup | | `mobileEmulation` | `MobileEmulation \| DeviceName` | — | Mobile device emulation settings (Chrome/Chromium only) | | `downloadsDir` | `string` | temp dir | Directory where downloaded files are saved | ## Navigation ```typescript // Navigate to URL — waits for the page load event (default) await browser.navigateTo('https://example.com'); // Wait only until DOMContentLoaded (faster — skips images/fonts) await browser.navigateTo('https://example.com', { waitUntil: 'domcontentloaded' }); // Wait until no requests are in-flight for 500 ms after load await browser.navigateTo('https://example.com', { waitUntil: 'networkidle' }); // Fire-and-forget — does not wait for any load event await browser.navigateTo('https://example.com', { waitUntil: 'none' }); // Get current URL const url = await browser.url(); // Get page title const title = await browser.title(); ``` ### `waitForLoadState(state?, opts?)` Wait for the page to reach a given load state after an action that triggers navigation (e.g. clicking a link or submitting a form). ```typescript // After an action that causes navigation: await browser.click('#submit'); await browser.waitForLoadState(); // default: 'load' await browser.waitForLoadState('domcontentloaded'); await browser.waitForLoadState('networkidle', { timeout: 10_000 }); ``` | State | Description | |-------|-------------| | `'load'` | Page `load` event fired (default) | | `'domcontentloaded'` | `DOMContentLoaded` fired — no waiting for images/fonts | | `'networkidle'` | `load` + no in-flight requests for 500 ms | Uses BiDi `browsingContext.load` / `browsingContext.domContentLoaded` events. ### History ```typescript await browser.goBack(); // history back await browser.goForward(); // history forward await browser.reload(); // reload the active page ``` All three proxy to the active page (`browser.activePage()`); use `page.goBack()` / `page.goForward()` / `page.reload()` directly when working with a specific tab. ### Page content ```typescript // Full document HTML (document.documentElement.outerHTML) const html = await browser.content(); // Replace the document with synthetic HTML and wait for the load event await browser.setContent('