# Frontend browser automation

`createFrontendPlaywright(options?)` provides a Playwright-shaped API that runs
entirely in the page hosting SandboxedJs. It drives a same-origin `<iframe>`
using the browser the user already has. It does **not** bundle, download or
launch Chromium, and it is not Playwright.

```js
import { createFrontendPlaywright } from 'sandboxedjs';

const pw = createFrontendPlaywright({ mount: document.querySelector('#tests') });
const browser = await pw.chromium.launch();
const page = await browser.newPage();

await page.goto('/preview/index.html');
await page.getByRole('textbox', { name: 'Email' }).fill('a@example.com');
await page.getByRole('button', { name: 'Submit' }).click();
await pw.expect(page.getByText('Thanks')).toBeVisible();

await pw.dispose();
```

## Supported

`page`: `goto`, `setContent`, `title`, `content`, `evaluate`,
`setDefaultTimeout`, `close`; locators via `locator`, `getByTestId`,
`getByText`, and `getByRole` for `button`, `textbox`, `link`, `checkbox`
(plus any explicit `role=` attribute).

`locator`: `first`, `nth`, `locator`, `count`, `isVisible`, `textContent`,
`innerText`, `inputValue`, `getAttribute`, `click`, `fill`, `waitFor`.
Locators are strict: more than one match throws unless you narrow with
`first()`/`nth()`. Actions wait for the element to be visible and enabled.

`expect(locator)`: `toBeVisible`, `toHaveText`.

## Not supported

`screenshot`, `route`/network interception, cross-origin navigation, browser
launch options, and `firefox`/`webkit` all throw
`FrontendAutomationUnsupported`. Clicks and typing are dispatched DOM events,
not OS-level trusted input; `capabilities.trustedEvents` is `false`. `goto`
returns `null` rather than a Response. `evaluate` uses `eval` inside the frame
and fails where the page's CSP forbids it.

Pass `resolveUrl` to map a container's virtual server URL to the same-origin
preview URL served by the SandboxedJs service worker. Inspect
`pw.capabilities` before relying on any behavior; treat this as a labeled
subset for smoke-testing your own preview output, not a Chromium replacement.
