> ## Documentation Index
> Fetch the complete documentation index at: https://docs.uplink.build/llms.txt
> Use this file to discover all available pages before exploring further.

# Page API Overview

> Overview of the Page class for browser automation

The `Page` class is where most of your Uplink automation happens. It provides methods for navigation, element interaction, JavaScript execution, and more.

## Getting started

Create a page from a browser instance:

```typescript theme={null}
const browser = await client.launch()
const page = await browser.newPage()

await page.goto('https://example.com')
await page.click('#button')
```

## API categories

The Page API is organized into several categories:

<CardGroup cols={2}>
  <Card title="Navigation" icon="compass" href="/api-reference/page/navigation">
    Navigate to URLs and track page loading
  </Card>

  <Card title="Interaction" icon="hand-pointer" href="/api-reference/page/interaction">
    Click elements, type input, and interact with the page
  </Card>

  <Card title="JavaScript" icon="code" href="/api-reference/page/javascript">
    Execute JavaScript and inject user scripts
  </Card>

  <Card title="Waiting" icon="hourglass" href="/api-reference/page/waiting">
    Wait for elements, functions, and network requests
  </Card>

  <Card title="Authentication" icon="key" href="/api-reference/page/authentication">
    Handle authentication flows
  </Card>

  <Card title="Cookies" icon="cookie" href="/api-reference/page/cookies">
    Manage browser cookies
  </Card>

  <Card title="HTTP Requests" icon="globe" href="/api-reference/page/requests">
    Make HTTP requests via the device
  </Card>

  <Card title="Screenshots" icon="camera" href="/api-reference/page/screenshots">
    Capture screenshots of the page
  </Card>

  <Card title="Events" icon="bell" href="/api-reference/page/events">
    Listen to page events and lifecycle
  </Card>
</CardGroup>

## Common workflows

### User authentication + automation

```typescript theme={null}
// User logs in on their device
await page.goto('https://example.com/login')
await page.waitForAuthentication(
  async (page) => {
    const url = await page.url()
    return url.includes('/dashboard')
  },
  { timeout: 120000 }
)

// Now automate authenticated actions
await page.click('#export-data')
await page.waitForSelector('.download-ready')
```

### Data extraction

```typescript theme={null}
await page.goto('https://example.com/products')

const products = await page.evaluate(() => {
  return Array.from(document.querySelectorAll('.product')).map(el => ({
    name: el.querySelector('.name').textContent,
    price: el.querySelector('.price').textContent
  }))
})

console.log('Found products:', products)
```

### Network monitoring

```typescript theme={null}
const controller = await page.on('xhr', async (event) => {
  const req = event.data
  console.log('Request:', req.method, req.url)

  if (req.response) {
    console.log('Response:', req.response.status)
  }
})

await page.goto('https://example.com')

// Stop monitoring
await page.off(controller)
```

## Lifecycle

### Creating pages

```typescript theme={null}
const browser = await client.launch()
const page = await browser.newPage()
```

### Closing pages

```typescript theme={null}
await page.close()
```

<Tip>
  Always close pages when done to free up device resources.
</Tip>

### UI visibility

Pages can be shown or hidden without closing them:

```typescript theme={null}
await page.show()  // Bring to foreground
await page.hide()  // Send to background
```

## Best practices

<AccordionGroup>
  <Accordion title="Wait for elements before interacting" icon="hourglass">
    Always wait for elements to appear before interacting with them:

    ```typescript theme={null}
    await page.waitForSelector('#button')
    await page.click('#button')
    ```
  </Accordion>

  <Accordion title="Handle timeouts" icon="clock">
    Set appropriate timeouts for navigation and operations:

    ```typescript theme={null}
    // 60 second timeout for slow pages
    await page.goto('https://slow-site.com', {}, 60000)
    ```
  </Accordion>

  <Accordion title="Clean up event listeners" icon="trash">
    Remove event listeners when done to prevent memory leaks:

    ```typescript theme={null}
    const controller = await page.on('xhr', handler)

    // When done
    await page.off(controller)
    ```
  </Accordion>

  <Accordion title="Use evaluate for DOM access" icon="code">
    Access DOM content using `evaluate()` rather than trying to parse HTML:

    ```typescript theme={null}
    const title = await page.evaluate(() => document.title)
    ```
  </Accordion>
</AccordionGroup>

## Next steps

Explore each category of the Page API:

<CardGroup cols={2}>
  <Card title="Navigation" icon="compass" href="/api-reference/page/navigation">
    page.goto(), page.url(), page.progress()
  </Card>

  <Card title="Interaction" icon="hand-pointer" href="/api-reference/page/interaction">
    page.click(), page.input(), page.select()
  </Card>

  <Card title="JavaScript" icon="code" href="/api-reference/page/javascript">
    page.evaluate(), page.addUserScript()
  </Card>

  <Card title="Waiting" icon="hourglass" href="/api-reference/page/waiting">
    page.waitForSelector(), page.waitForFunction()
  </Card>
</CardGroup>
