# Pages with JavaScript

> Load JavaScript pages in a real browser: wait conditions, steps (click, type, select, scripts), screenshots, PDF and captured background requests.

Source: https://docs.virginproxy.com/render/

Some pages are empty until their scripts have run: search results, shops built as web apps, dashboards and single-page apps. `render` loads the page in a real browser, lets its scripts run and returns the finished page as HTML – plus screenshots, a PDF, the page's own background requests and the results of your steps if you ask for them.

## Render a page

This demo page builds its quotes with JavaScript. A plain request gets an empty frame; rendered, the quotes are there.

**cURL**

```bash
curl https://api.virginproxy.com/v1/requests \
  -H "Authorization: Bearer $VP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://quotes.toscrape.com/js/",
    "render": {
      "wait_for": ".quote"
    }
  }'
```

**Python**

```python
import os, requests

r = requests.post(
    "https://api.virginproxy.com/v1/requests",
    headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
    json={
        "url": "https://quotes.toscrape.com/js/",
        "render": {"wait_for": ".quote"},
    },
    timeout=180,
)
data = r.json()
if not r.ok:
    raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["rendered"], data["status"], data["body"].count('class="quote"'), data["cost"]["credits"])
```

**Node.js**

```javascript
const res = await fetch("https://api.virginproxy.com/v1/requests", {
  method: "POST",
  headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({
    url: "https://quotes.toscrape.com/js/",
    render: { wait_for: ".quote" },
  }),
  signal: AbortSignal.timeout(180_000),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.code + ": " + data.error.message);
console.log(data.rendered, data.status, data.body.split('class="quote"').length - 1, data.cost.credits);
```

**Python SDK**

```pysdk
from virginproxy import VirginProxy  # docs.virginproxy.com/sdk/virginproxy.py

vp = VirginProxy()  # reads VP_KEY
data = vp.request({
    "url": "https://quotes.toscrape.com/js/",
    "render": {"wait_for": ".quote"},
})
print(data)
```

**Node SDK**

```nodesdk
import { VirginProxy } from "./virginproxy.mjs"; // docs.virginproxy.com/sdk/virginproxy.mjs

const vp = new VirginProxy(); // reads VP_KEY
const data = await vp.request({
  url: "https://quotes.toscrape.com/js/",
  render: { wait_for: ".quote" },
});
console.log(data);
```

**PHP**

```php
<?php
$ch = curl_init("https://api.virginproxy.com/v1/requests");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 180,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("VP_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "url" => "https://quotes.toscrape.com/js/",
        "render" => ["wait_for" => ".quote"],
    ], JSON_UNESCAPED_SLASHES),
]);
$data = json_decode(curl_exec($ch), true);
if (isset($data["error"])) {
    exit($data["error"]["code"] . ": " . $data["error"]["message"] . PHP_EOL);
}
echo json_encode([$data["rendered"], $data["status"], $data["cost"]["credits"]], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), PHP_EOL;
```

**Go**

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"os"
	"time"
)

func main() {
	payload := []byte(`{
  "url": "https://quotes.toscrape.com/js/",
  "render": {
    "wait_for": ".quote"
  }
}`)
	req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/requests", bytes.NewReader(payload))
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("VP_KEY"))
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{Timeout: 180 * time.Second}
	res, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()

	var data map[string]any
	if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
		log.Fatal(err)
	}
	if res.StatusCode >= 300 {
		e := data["error"].(map[string]any)
		log.Fatalf("%v: %v", e["code"], e["message"])
	}
	fmt.Println(data["rendered"], data["status"], data["cost"].(map[string]any)["credits"])
}
```

POST`/v1/requests`[≈ 10 credits](https://docs.virginproxy.com/billing/#cost)[Open in Playground](https://dash.virginproxy.com/playground#request=eyJ1cmwiOiJodHRwczovL3F1b3Rlcy50b3NjcmFwZS5jb20vanMvIiwicmVuZGVyIjp7IndhaXRfZm9yIjoiLnF1b3RlIn19)

`"render": true` is enough for many pages. The object form adds everything below. The device the page sees (time zone, location, screen, colour scheme, device properties, stored values) is described on [Device and environment](https://docs.virginproxy.com/device/).

## What you get back

| Field | Meaning |
| --- | --- |
| `body` | The page as HTML after its scripts and your steps ran, always UTF-8 text. |
| `status`, `headers`, `final_url`, `redirects` | Of the page itself. |
| `cookies` | Every cookie the browser holds at the end. |
| `rendered` | `true`. |
| `screenshot`, `screenshot_type` | The screenshot as base64 and its type (`image/png`, `image/jpeg` or `image/webp`) when you asked for one, otherwise `null`. |
| `pdf` | The page as a base64 PDF, only with `"pdf": true`. |
| `steps` | One entry per action: `{"action", "ok", "skipped"?, "error"?, "value"?}`. `value` is the result of an `evaluate` step. |
| `captured` | The background requests you asked for with `capture`: `{"url", "method", "status", "content_type", "body", "body_encoding", "truncated"}`. |
| `extracted` | With `extract`, see [Extract data](https://docs.virginproxy.com/extract/). |

## Options

| Field | Type | Meaning |
| --- | --- | --- |
| `wait_until` | string | When the page counts as loaded: `load` (default, everything loaded), `domcontentloaded` (the HTML is there, faster) or `networkidle` (no request ran for half a second, at most 15 seconds – for pages that keep fetching data after loading). |
| `wait_for` | string | A CSS selector, up to 500 characters. Waits until such an element is visible. |
| `wait_ms` | integer | 0 to 15,000. Waits this long at the end, for content that arrives late. |
| `scroll` | integer | 0 to 20. Scrolls to the bottom this many times, with a short pause each time, so that content which loads while you scroll appears. |
| `screenshot` | boolean or object | `true`: the visible area as PNG. Object: `{"full_page": true}` for the whole page (up to 16,000 pixels high), `{"selector": "#chart"}` for one element, `"format": "png" \| "jpeg" \| "webp"`, `"quality": 1–100` for JPEG and WebP. |
| `pdf` | boolean | `true` also returns the page as a PDF (with backgrounds). |
| `block` | list | What the browser does not load: any of `image`, `media`, `font`, `stylesheet`. Default `["image", "media", "font"]`, which saves time and credits. `[]` loads everything, for example for a screenshot with pictures. |
| `block_urls` | list | Up to 50 address patterns the browser does not load, for example trackers or ads. Without `*` a pattern matches anywhere in the address; with `*` it is a wildcard: `*analytics.example*`, `https://cdn.example/*.js`. |
| `capture` | list | Up to 10 address patterns (same rules). Matching background requests of the page (XHR, fetch, scripts …) come back in `captured`, at most 20, each body up to 1 MB. Many web apps load their data as JSON – this is often the cleanest way to get it. |
| `actions` | list | Up to 30 steps that are carried out in order, see below. |

## Steps: click, type, keys, select, scripts

Each step is an object with exactly one of these forms, plus optionally `"optional": true` and `"timeout_ms": 100–30000`:

| Step | What it does |
| --- | --- |
| `{"click": "selector"}` | Clicks the first visible element that matches. |
| `{"type": "selector", "text": "…"}` | Types the text (up to 2,000 characters) into the element. |
| `{"press": "Enter"}` | Presses a key: `Enter`, `Tab`, `Escape`, `Backspace`, `Delete`, `ArrowDown`, `ArrowUp`, `ArrowLeft`, `ArrowRight`, `PageDown`, `PageUp`, `Home`, `End`, `Space` or a single character. |
| `{"hover": "selector"}` | Moves the mouse over the element, for menus that open on hover. |
| `{"select": "selector", "value": "…"}` | Chooses the option with this value in a `<select>` and lets the page know. |
| `{"scroll_to": "selector"}` | Scrolls the element into view, for content that loads when it becomes visible. |
| `{"scroll": 2}` | Scrolls to the bottom 1 to 20 times. |
| `{"wait_for": "selector"}` | Waits until such an element is visible. |
| `{"wait_for_hidden": "selector"}` | Waits until the element is gone, for example a loading spinner. |
| `{"wait_for_navigation": true}` | Waits until the next page has loaded, after a click that opens one. |
| `{"wait_ms": 1500}` | Waits 1 to 15,000 milliseconds. |
| `{"evaluate": "…"}` | Runs JavaScript in the page (up to 20,000 characters). The value of the expression comes back in `steps[i].value` as JSON; promises are awaited. Example: `"[...document.querySelectorAll("h2")].map(e => e.textContent)"`. |
| `{"goto": "https://…"}` | Opens another address in the same browser, with the cookies collected so far. |

**Optional steps.** A step with `"optional": true` is skipped when its element does not show up within its time limit (default 5 seconds) – made for cookie banners that only appear sometimes. A required step waits up to 10 seconds by default; if it fails, the remaining steps are skipped, you still get the page, and `steps` shows which step failed.

**cURL**

```bash
curl https://api.virginproxy.com/v1/requests \
  -H "Authorization: Bearer $VP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://httpbin.org/forms/post",
    "render": {
      "actions": [
        {
          "click": "#cookie-accept",
          "optional": true,
          "timeout_ms": 2000
        },
        {
          "type": "input[name=\"custname\"]",
          "text": "Ada Lovelace"
        },
        {
          "click": "input[value=\"large\"]"
        },
        {
          "evaluate": "document.querySelector('\''input[name=\"custname\"]'\'').value"
        },
        {
          "click": "button"
        },
        {
          "wait_for_navigation": true
        }
      ],
      "screenshot": true
    }
  }'
```

**Python**

```python
import os, requests

r = requests.post(
    "https://api.virginproxy.com/v1/requests",
    headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
    json={
        "url": "https://httpbin.org/forms/post",
        "render": {
            "actions": [
                {
                    "click": "#cookie-accept",
                    "optional": True,
                    "timeout_ms": 2000,
                },
                {"type": "input[name=\"custname\"]", "text": "Ada Lovelace"},
                {"click": "input[value=\"large\"]"},
                {
                    "evaluate": "document.querySelector('input[name=\"custname\"]').value",
                },
                {"click": "button"},
                {"wait_for_navigation": True},
            ],
            "screenshot": True,
        },
    },
    timeout=180,
)
data = r.json()
if not r.ok:
    raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
for step in data["steps"]:
    print(step)
print(data["final_url"])  # the page after the form was sent
```

**Node.js**

```javascript
const res = await fetch("https://api.virginproxy.com/v1/requests", {
  method: "POST",
  headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({
    url: "https://httpbin.org/forms/post",
    render: {
      actions: [
        { click: "#cookie-accept", optional: true, timeout_ms: 2000 },
        { type: "input[name=\"custname\"]", text: "Ada Lovelace" },
        { click: "input[value=\"large\"]" },
        {
          evaluate: "document.querySelector('input[name=\"custname\"]').value",
        },
        { click: "button" },
        { wait_for_navigation: true },
      ],
      screenshot: true,
    },
  }),
  signal: AbortSignal.timeout(180_000),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.code + ": " + data.error.message);
for (const step of data.steps) console.log(step);
console.log(data.final_url); // the page after the form was sent
```

**Python SDK**

```pysdk
from virginproxy import VirginProxy  # docs.virginproxy.com/sdk/virginproxy.py

vp = VirginProxy()  # reads VP_KEY
data = vp.request({
    "url": "https://httpbin.org/forms/post",
    "render": {
        "actions": [
            {
                "click": "#cookie-accept",
                "optional": True,
                "timeout_ms": 2000,
            },
            {"type": "input[name=\"custname\"]", "text": "Ada Lovelace"},
            {"click": "input[value=\"large\"]"},
            {
                "evaluate": "document.querySelector('input[name=\"custname\"]').value",
            },
            {"click": "button"},
            {"wait_for_navigation": True},
        ],
        "screenshot": True,
    },
})
print(data)
```

**Node SDK**

```nodesdk
import { VirginProxy } from "./virginproxy.mjs"; // docs.virginproxy.com/sdk/virginproxy.mjs

const vp = new VirginProxy(); // reads VP_KEY
const data = await vp.request({
  url: "https://httpbin.org/forms/post",
  render: {
    actions: [
      { click: "#cookie-accept", optional: true, timeout_ms: 2000 },
      { type: "input[name=\"custname\"]", text: "Ada Lovelace" },
      { click: "input[value=\"large\"]" },
      {
        evaluate: "document.querySelector('input[name=\"custname\"]').value",
      },
      { click: "button" },
      { wait_for_navigation: true },
    ],
    screenshot: true,
  },
});
console.log(data);
```

**PHP**

```php
<?php
$ch = curl_init("https://api.virginproxy.com/v1/requests");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 180,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("VP_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "url" => "https://httpbin.org/forms/post",
        "render" => [
            "actions" => [
                [
                    "click" => "#cookie-accept",
                    "optional" => true,
                    "timeout_ms" => 2000,
                ],
                ["type" => "input[name=\"custname\"]", "text" => "Ada Lovelace"],
                ["click" => "input[value=\"large\"]"],
                [
                    "evaluate" => "document.querySelector('input[name=\"custname\"]').value",
                ],
                ["click" => "button"],
                ["wait_for_navigation" => true],
            ],
            "screenshot" => true,
        ],
    ], JSON_UNESCAPED_SLASHES),
]);
$data = json_decode(curl_exec($ch), true);
if (isset($data["error"])) {
    exit($data["error"]["code"] . ": " . $data["error"]["message"] . PHP_EOL);
}
echo json_encode($data["steps"], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), PHP_EOL;
echo $data["final_url"], PHP_EOL;
```

**Go**

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"os"
	"time"
)

func main() {
	payload := []byte(`{
  "url": "https://httpbin.org/forms/post",
  "render": {
    "actions": [
      {
        "click": "#cookie-accept",
        "optional": true,
        "timeout_ms": 2000
      },
      {
        "type": "input[name=\"custname\"]",
        "text": "Ada Lovelace"
      },
      {
        "click": "input[value=\"large\"]"
      },
      {
        "evaluate": "document.querySelector('input[name=\"custname\"]').value"
      },
      {
        "click": "button"
      },
      {
        "wait_for_navigation": true
      }
    ],
    "screenshot": true
  }
}`)
	req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/requests", bytes.NewReader(payload))
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("VP_KEY"))
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{Timeout: 180 * time.Second}
	res, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()

	var data map[string]any
	if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
		log.Fatal(err)
	}
	if res.StatusCode >= 300 {
		e := data["error"].(map[string]any)
		log.Fatalf("%v: %v", e["code"], e["message"])
	}
	fmt.Println(data["steps"])
	fmt.Println(data["final_url"])
}
```

POST`/v1/requests`[≈ 10 credits](https://docs.virginproxy.com/billing/#cost)[Open in Playground](https://dash.virginproxy.com/playground#request=eyJ1cmwiOiJodHRwczovL2h0dHBiaW4ub3JnL2Zvcm1zL3Bvc3QiLCJyZW5kZXIiOnsiYWN0aW9ucyI6W3siY2xpY2siOiIjY29va2llLWFjY2VwdCIsIm9wdGlvbmFsIjp0cnVlLCJ0aW1lb3V0X21zIjoyMDAwfSx7InR5cGUiOiJpbnB1dFtuYW1lPVwiY3VzdG5hbWVcIl0iLCJ0ZXh0IjoiQWRhIExvdmVsYWNlIn0seyJjbGljayI6ImlucHV0W3ZhbHVlPVwibGFyZ2VcIl0ifSx7ImV2YWx1YXRlIjoiZG9jdW1lbnQucXVlcnlTZWxlY3RvcignaW5wdXRbbmFtZT1cImN1c3RuYW1lXCJdJykudmFsdWUifSx7ImNsaWNrIjoiYnV0dG9uIn0seyJ3YWl0X2Zvcl9uYXZpZ2F0aW9uIjp0cnVlfV0sInNjcmVlbnNob3QiOnRydWV9fQ)

## Only when needed: "render": "auto"

`"render": "auto"` first fetches the page without a browser. Only when that answer is an error status (401, 403, 429, 503), a page that needs a browser to show its content, a page that is only a JavaScript shell, a page without the element `render_options.wait_for` waits for, or when `extract` found nothing, it is fetched again in the browser. You pay for the answer you get: the first try is free when it is not the answer, and the browser part (9 credits) only when the browser was needed.

*Request:*

```json
{
  "url": "https://shop.example/p/42",
  "render": "auto",
  "render_options": {
    "wait_for": ".price"
  },
  "extract": {
    "price": ".price"
  }
}
```

The answer says what happened: `"strategy": "http"` or `"browser"`, and `strategy_attempts` lists each try with its status, the reason for the second (`blocked_status`, `challenge_page`, `javascript_shell`, `wait_for_missing` – the element `render_options.wait_for` names is not in the plain page –, `nothing_extracted`, `no_answer`) and its credits. Browser settings for the second try go into `render_options` (the options of `render`); screenshots, PDFs, steps and captured requests need the browser every time – use `render: {…}` for those. `max_credits` counts the browser part.

## See every step: render.trace

`"trace": true` in `render` returns `trace`: a small picture (JPEG, up to 800 pixels wide) after every step of `actions` and at the end, each with the time, the address and the page's console messages. Use it to see where a sequence of clicks went wrong. At most 25 pictures; free.

## Background requests

Many pages load their actual data afterwards, as JSON. With `capture` you get those answers directly, without parsing the HTML:

**cURL**

```bash
curl https://api.virginproxy.com/v1/requests \
  -H "Authorization: Bearer $VP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://quotes.toscrape.com/scroll",
    "render": {
      "capture": [
        "/api/quotes"
      ],
      "wait_until": "networkidle"
    }
  }'
```

**Python**

```python
import os, requests

r = requests.post(
    "https://api.virginproxy.com/v1/requests",
    headers={"Authorization": "Bearer " + os.environ["VP_KEY"]},
    json={
        "url": "https://quotes.toscrape.com/scroll",
        "render": {"capture": ["/api/quotes"], "wait_until": "networkidle"},
    },
    timeout=180,
)
data = r.json()
if not r.ok:
    raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
import json
for c in data["captured"]:
    print(c["status"], c["url"])
    print(json.loads(c["body"])["quotes"][0]["text"])
```

**Node.js**

```javascript
const res = await fetch("https://api.virginproxy.com/v1/requests", {
  method: "POST",
  headers: { Authorization: "Bearer " + process.env.VP_KEY, "Content-Type": "application/json" },
  body: JSON.stringify({
    url: "https://quotes.toscrape.com/scroll",
    render: { capture: ["/api/quotes"], wait_until: "networkidle" },
  }),
  signal: AbortSignal.timeout(180_000),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.code + ": " + data.error.message);
for (const c of data.captured) {
  console.log(c.status, c.url);
  console.log(JSON.parse(c.body).quotes[0].text);
}
```

**Python SDK**

```pysdk
from virginproxy import VirginProxy  # docs.virginproxy.com/sdk/virginproxy.py

vp = VirginProxy()  # reads VP_KEY
data = vp.request({
    "url": "https://quotes.toscrape.com/scroll",
    "render": {"capture": ["/api/quotes"], "wait_until": "networkidle"},
})
print(data)
```

**Node SDK**

```nodesdk
import { VirginProxy } from "./virginproxy.mjs"; // docs.virginproxy.com/sdk/virginproxy.mjs

const vp = new VirginProxy(); // reads VP_KEY
const data = await vp.request({
  url: "https://quotes.toscrape.com/scroll",
  render: { capture: ["/api/quotes"], wait_until: "networkidle" },
});
console.log(data);
```

**PHP**

```php
<?php
$ch = curl_init("https://api.virginproxy.com/v1/requests");
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 180,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("VP_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "url" => "https://quotes.toscrape.com/scroll",
        "render" => ["capture" => ["/api/quotes"], "wait_until" => "networkidle"],
    ], JSON_UNESCAPED_SLASHES),
]);
$data = json_decode(curl_exec($ch), true);
if (isset($data["error"])) {
    exit($data["error"]["code"] . ": " . $data["error"]["message"] . PHP_EOL);
}
echo json_encode($data["captured"], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), PHP_EOL;
```

**Go**

```go
package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"os"
	"time"
)

func main() {
	payload := []byte(`{
  "url": "https://quotes.toscrape.com/scroll",
  "render": {
    "capture": [
      "/api/quotes"
    ],
    "wait_until": "networkidle"
  }
}`)
	req, err := http.NewRequest("POST", "https://api.virginproxy.com/v1/requests", bytes.NewReader(payload))
	if err != nil {
		log.Fatal(err)
	}
	req.Header.Set("Authorization", "Bearer "+os.Getenv("VP_KEY"))
	req.Header.Set("Content-Type", "application/json")

	client := &http.Client{Timeout: 180 * time.Second}
	res, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()

	var data map[string]any
	if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
		log.Fatal(err)
	}
	if res.StatusCode >= 300 {
		e := data["error"].(map[string]any)
		log.Fatalf("%v: %v", e["code"], e["message"])
	}
	fmt.Println(data["captured"])
}
```

POST`/v1/requests`[≈ 10 credits](https://docs.virginproxy.com/billing/#cost)[Open in Playground](https://dash.virginproxy.com/playground#request=eyJ1cmwiOiJodHRwczovL3F1b3Rlcy50b3NjcmFwZS5jb20vc2Nyb2xsIiwicmVuZGVyIjp7ImNhcHR1cmUiOlsiL2FwaS9xdW90ZXMiXSwid2FpdF91bnRpbCI6Im5ldHdvcmtpZGxlIn19)

## In which order things happen

1. The device is set up (see [Device and environment](https://docs.virginproxy.com/device/)), cookies and stored values are put in place.
2. The page loads until `wait_until` is reached.
3. `wait_for`, if given, then `scroll`.
4. The `actions`, one after the other.
5. `wait_ms`, if given.
6. The HTML is taken, then screenshot, PDF and the captured requests.

All of this has to fit into the request's timeout (`timeout_ms`, at most your plan's). If the element in `wait_for` never appears, the request ends with `timeout` and costs nothing.

## Browser, language, headers and cookies

- Without `browser`, rendering uses `chrome_android`, the mobile version of Chrome. `chrome_android` and `safari_ios` load the page as a phone (small screen, touch); every other value as a desktop computer.
- `locale` sets the language the browser reports, to the server and to the page's scripts.
- Your `headers` are sent with the requests of the page; your own `User-Agent` and `Accept-Language` replace the browser's.
- `cookies` and the cookies of a `session` are in the browser before the page loads. Cookies the page sets go back into the session, so you can continue with cheaper plain requests.

## Cost

Rendering adds 9 credits to the usual price: a rendered page up to 1 MB costs 10 credits. `bytes.down` counts everything the browser loaded for the page, scripts and styles included, so blocking images, media and fonts (the default) and trackers (`block_urls`) keeps the price down. Screenshots, PDFs, steps and captured requests cost nothing extra. Requests that fail cost nothing.

Try a plain request first. If it already contains what you need, it is ten times cheaper and much faster.

## Limits

- Only `GET`: rendering opens the page like a person would.
- The browsers are shared like all other capacity. When all are in use, the request waits like any other, see [Load and priority](https://docs.virginproxy.com/priority/), and may end with `busy` (503, not charged).
- If rendering is not available for a while, you get `render_unavailable` (503, not charged). Retry later or send the request without `render`.
- `retry` works with rendering too: each attempt loads the page again.
- An invalid option is answered at once with `invalid_render` (400) and a message that names the field.
