# Device and environment

> Set the device a rendered page sees: time zone, geolocation, screen and pixel density, colour scheme, CPU cores, memory, JavaScript and storage.

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

A page that runs scripts can ask the browser a lot: the time zone, the location, the screen, the colour scheme, how many processor cores and how much memory there are, what it stored on the last visit. With `render` you decide each of these answers.

> **Note:** These options belong into the `render` object and only work there: a plain request runs no JavaScript, so the page cannot ask anything.

**cURL**

```bash
curl https://api.virginproxy.com/v1/requests \
  -H "Authorization: Bearer $VP_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://httpbin.org/anything",
    "render": {
      "timezone": "America/New_York",
      "geolocation": {
        "latitude": 40.713,
        "longitude": -74.006
      },
      "viewport": {
        "width": 390,
        "height": 844,
        "scale": 3
      },
      "color_scheme": "dark",
      "actions": [
        {
          "evaluate": "({ zone: Intl.DateTimeFormat().resolvedOptions().timeZone, screen: screen.width + \"x\" + screen.height, dark: matchMedia(\"(prefers-color-scheme: dark)\").matches })"
        }
      ]
    }
  }'
```

**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/anything",
        "render": {
            "timezone": "America/New_York",
            "geolocation": {"latitude": 40.713, "longitude": -74.006},
            "viewport": {"width": 390, "height": 844, "scale": 3},
            "color_scheme": "dark",
            "actions": [
                {
                    "evaluate": "({ zone: Intl.DateTimeFormat().resolvedOptions().timeZone, screen: screen.width + \"x\" + screen.height, dark: matchMedia(\"(prefers-color-scheme: dark)\").matches })",
                },
            ],
        },
    },
    timeout=180,
)
data = r.json()
if not r.ok:
    raise SystemExit(data["error"]["code"] + ": " + data["error"]["message"])
print(data["steps"][0]["value"])  # {"zone": "America/New_York", "screen": "390x844", "dark": true}
```

**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/anything",
    render: {
      timezone: "America/New_York",
      geolocation: { latitude: 40.713, longitude: -74.006 },
      viewport: { width: 390, height: 844, scale: 3 },
      color_scheme: "dark",
      actions: [
        {
          evaluate: "({ zone: Intl.DateTimeFormat().resolvedOptions().timeZone, screen: screen.width + \"x\" + screen.height, dark: matchMedia(\"(prefers-color-scheme: dark)\").matches })",
        },
      ],
    },
  }),
  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.steps[0].value); // { zone: "America/New_York", screen: "390x844", dark: true }
```

**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/anything",
    "render": {
        "timezone": "America/New_York",
        "geolocation": {"latitude": 40.713, "longitude": -74.006},
        "viewport": {"width": 390, "height": 844, "scale": 3},
        "color_scheme": "dark",
        "actions": [
            {
                "evaluate": "({ zone: Intl.DateTimeFormat().resolvedOptions().timeZone, screen: screen.width + \"x\" + screen.height, dark: matchMedia(\"(prefers-color-scheme: dark)\").matches })",
            },
        ],
    },
})
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/anything",
  render: {
    timezone: "America/New_York",
    geolocation: { latitude: 40.713, longitude: -74.006 },
    viewport: { width: 390, height: 844, scale: 3 },
    color_scheme: "dark",
    actions: [
      {
        evaluate: "({ zone: Intl.DateTimeFormat().resolvedOptions().timeZone, screen: screen.width + \"x\" + screen.height, dark: matchMedia(\"(prefers-color-scheme: dark)\").matches })",
      },
    ],
  },
});
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/anything",
        "render" => [
            "timezone" => "America/New_York",
            "geolocation" => ["latitude" => 40.713, "longitude" => -74.006],
            "viewport" => ["width" => 390, "height" => 844, "scale" => 3],
            "color_scheme" => "dark",
            "actions" => [
                [
                    "evaluate" => "({ zone: Intl.DateTimeFormat().resolvedOptions().timeZone, screen: screen.width + \"x\" + screen.height, dark: matchMedia(\"(prefers-color-scheme: dark)\").matches })",
                ],
            ],
        ],
    ], 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"][0]["value"], 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://httpbin.org/anything",
  "render": {
    "timezone": "America/New_York",
    "geolocation": {
      "latitude": 40.713,
      "longitude": -74.006
    },
    "viewport": {
      "width": 390,
      "height": 844,
      "scale": 3
    },
    "color_scheme": "dark",
    "actions": [
      {
        "evaluate": "({ zone: Intl.DateTimeFormat().resolvedOptions().timeZone, screen: screen.width + \"x\" + screen.height, dark: matchMedia(\"(prefers-color-scheme: dark)\").matches })"
      }
    ]
  }
}`)
	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"].([]any)[0].(map[string]any)["value"])
}
```

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

## Options

| Field | Type | Meaning |
| --- | --- | --- |
| `timezone` | string | IANA time zone such as `Europe/Berlin` (default), `Europe/London` or `America/New_York`. Affects `Date`, `Intl` and everything the page derives from it. |
| `geolocation` | object | `{"latitude": -90…90, "longitude": -180…180, "accuracy": 1…100000}` (accuracy in metres, default 50). What `navigator.geolocation` reports; the permission is granted automatically, so no prompt blocks the page. |
| `viewport` | object | `{"width": 240…3840, "height": 240…4320, "scale": 0.5…4}`. Screen size in CSS pixels and the pixel density. Default: 1366 × 900 for desktop browsers, 412 × 915 at 2.625 for phones. With a phone browser, a page without a viewport tag is laid out 980 pixels wide, just like on a real phone; `screen.width` still reports your width. |
| `color_scheme` | string | `"light"` or `"dark"`: what `prefers-color-scheme` answers. |
| `reduced_motion` | boolean | `true`: `prefers-reduced-motion: reduce`, many pages then skip animations. |
| `cpu_cores` | integer | 1 to 64: `navigator.hardwareConcurrency`. |
| `memory_gb` | number | `0.25`, `0.5`, `1`, `2`, `4` or `8`: `navigator.deviceMemory`. |
| `javascript` | boolean | `false` loads the page without running its scripts. Faster, and useful to see what a page delivers without them – but most pages that need `render` stay empty then. |
| `local_storage` | object | Up to 100 `{"key": "text"}` entries (together at most 1 MB), put into `localStorage` of the target's origin before the page's scripts run. Values the page sets itself are not overwritten. |
| `session_storage` | object | The same for `sessionStorage`. |

## Example: a stored consent

Many sites remember the cookie banner in `localStorage`. If you know the key, the banner does not appear at all:

*request:*

```json
{
  "url": "https://shop.example/",
  "render": {
    "local_storage": {
      "consent": "{\"necessary\":true,\"stats\":false}"
    }
  }
}
```

## Keep it consistent

Pages compare these values with each other. A phone browser with a 2560-pixel screen, or a German language with a time zone on another continent and a location on a third, looks odd. Choose values that belong together: `browser`, `locale`, `timezone`, `geolocation` and `viewport`. Leave out what you do not need – the defaults already fit together.
