# Automate hybrid WebViews

Source: https://olef.dev/docs/guides/automate-webviews

**Outcome:** inspect DOM elements, enter text, tap controls, evaluate JavaScript, and capture console errors across the native/WebView boundary.

## Prerequisites

The target app must be debuggable and enable WebView debugging (`WebView.setWebContentsDebuggingEnabled(true)`). `olef web` runs host-side over ADB `localabstract:` sockets and is scoped strictly to `--app` by default (separate browsers on the device are excluded unless you pass `--include-browsers`).

## Ask your agent

```text
Open the Checkout screen, discover the app's WebView with Olef, fill the
promo code field inside the WebView, tap Apply, and report both the DOM state
and any JavaScript console errors or native dialogs blocking the page.
```

## 1. Discover targets and inspect the DOM

```bash
olef web targets --app com.example.app
olef web dump --app com.example.app
```

`web dump` pierces open Shadow DOM and same-origin iframes and returns compact interactive elements mapped to device-space screen coordinates.

## 2. Find, act, and wait inside the WebView

```bash
olef web find --app com.example.app --css "#promo-code"
olef web text "SAVE20" --app com.example.app --css "#promo-code"
olef web tap --app com.example.app --text "Apply"
olef web wait --app com.example.app --text "Discount applied" --timeout-ms 5000
```

When Olef's native device service is connected, `web tap` also checks for **native Android overlays** covering the WebView element—catching cases where a DOM node looks clickable in HTML but sits behind a native dialog or bottom sheet.

## 3. Inspect console logs, cookies, and JS state

```bash
olef web console --app com.example.app
olef web cookies --app com.example.app
olef web eval --app com.example.app --expr "document.title"
```

Cookie values are masked by default; pass `--values` only when needed (and note `--redact` always masks them). Uncaught WebView JavaScript exceptions also surface automatically in [`olef why`](https://olef.dev/docs/reference/cli/why), so one triage call correlates native crashes, HTTP errors, and WebView JS failures together.

## Limits

- Cross-origin iframes are subject to browser security boundaries.
- Release builds with WebView debugging disabled do not expose DevTools sockets.
- `web eval` executes inside the page context and can have side effects.

See the full command reference in [`olef web`](https://olef.dev/docs/reference/cli/web).
