> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/products/headless-browser/geolocation-and-proxy-selection.md).

# Geolocation & Proxy Selection

Use geolocation and proxy routing parameters directly to the WebSocket connection URL to route your automated Headless Browser sessions through targeted geographic regions and control your proxy IP usage.

## Geolocation parameters

You can target specific geographic locations by country, state, or city using three primary query parameters.

### Country

<table data-header-hidden><thead><tr><th width="90"></th><th></th></tr></thead><tbody><tr><td><code>p_cc</code></td><td>2 letter country code (e.g., <code>US</code>, <code>DE</code>, <code>FR</code>). If no country is specified, it's automatically assigned based on availability.</td></tr></tbody></table>

```
wss://USER:PASS@ubc.oxylabs.io?p_cc=US
```

### City

<table data-header-hidden><thead><tr><th width="90"></th><th></th></tr></thead><tbody><tr><td><code>p_city</code></td><td>City name written in lowercase (e.g., <code>berlin</code>, <code>los_angeles</code>). Must also specify either <code>p_cc</code> or <code>p_state</code>.</td></tr></tbody></table>

```
wss://USER:PASS@ubc.oxylabs.io?p_cc=US&p_city=new_york
```

{% hint style="info" %}
City-level targeting operates as *best-effort preference*. If the residential proxy pool doesn't have an available proxy in exact requested location, it automatically falls back to the country scope.
{% endhint %}

### State (US-only)

<table data-header-hidden><thead><tr><th width="90"></th><th></th></tr></thead><tbody><tr><td><code>p_state</code></td><td>US state name in lowercase (e.g., <code>texas</code>, <code>ohio</code>). See the full  <a href="https://content.gitbook.com/content/BQ7Zf9paoN3FTeGcyfY1/blobs/cVjpiu1GKicluiVIT9og/us_states.txt">supported states list</a>.</td></tr></tbody></table>

```
wss://USER:PASS@ubc.oxylabs.io?p_state=texas&p_city=houston
```

{% hint style="info" %}
**Note:** If `p_state` and `p_cc` are both specified, `p_state` takes priority and `p_cc` is ignored.
{% endhint %}

## Proxy selection (sticky proxies)

By default, the proxy gateway assigns a fresh exit IP to each unique browser connection session. Alternatively, you can pin a specific residential exit IP across continuous browser connection attempts by including the `proxy_resi_ses_id` and `proxy_resi_ses_time` parameters.

<table><thead><tr><th width="181">Parameter</th><th width="479">Description</th><th width="83">Type</th></tr></thead><tbody><tr><td><code>proxy_resi_ses_id</code></td><td>Alphanumeric session tracker name ranging from 3 to 36 characters.</td><td>string</td></tr><tr><td><code>proxy_resi_ses_time</code></td><td>Number of minutes to hold the pinned residential proxy exit IP. Min – 1 minute, max – 1440 minutes (24 hours).</td><td>integer</td></tr></tbody></table>

```bash
# Example: Pin a US-based IP for a 60 minutes
wss://USER:PASS@ubc.oxylabs.io?p_cc=US&proxy_resi_ses_id=unique_job_id_101&proxy_resi_ses_time=60
```

{% hint style="warning" %}
To maintain the exact same exit IP across consecutive connections, you must pass identical values for both `proxy_resi_ses_id` and `proxy_resi_ses_time` in every subsequent URL string.
{% endhint %}

## Code examples

The following examples show how to construct connection strings that apply geographic targeting together sticky residential proxy IP constraints.

{% tabs %}
{% tab title="Python (Playwright)" %}

```python
from playwright.sync_api import sync_playwright

username = "USERNAME_abc12"
password = "PASSWORD"
endpoint = "ubc.oxylabs.io"

# Target New York city and pin the residential IP for 30 minutes
geolocation = "p_cc=US&p_city=new_york"
sticky_proxy = "proxy_resi_ses_id=scrape_session_404&proxy_resi_ses_time=30"
browser_url = f"wss://{username}:{password}@{endpoint}?{geolocation}&{sticky_proxy}"

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(browser_url)
    page = browser.new_page()
    page.goto("https://ip.oxylabs.io/location")
    print(page.title())
    browser.close()
```

{% endtab %}

{% tab title="JavaScript (Playwright)" %}

```javascript
import { chromium } from "playwright";

const username = "USERNAME_abc12";
const password = "PASSWORD";
const endpoint = "ubc.oxylabs.io";

// Target Texas state and pin the residential IP for 60 minutes
const geolocation = "p_state=texas&p_city=houston";
const sticky_proxy = "proxy_resi_ses_id=scrape_session_404&proxy_resi_ses_time=60";
const browserUrl = `wss://${username}:${password}@${endpoint}?${geolocation}&${sticky_proxy}`;

(async () => {
    const browser = await chromium.connectOverCDP(browserUrl);
    const page = await browser.newPage();
    await page.goto("https://ip.oxylabs.io/location");
    console.log(await page.title());
    await browser.close();
})();
```

{% endtab %}

{% tab title="JavaScript (Puppeteer)" %}

```javascript
import puppeteer from 'puppeteer';

(async () => {
    const username = 'USERNAME';
    const password = 'PASSWORD';
    const endpoint = 'ubc.oxylabs.io';
    
    // Target Texas state and pin the residential IP for 60 minutes
    const geolocation = "p_state=texas&p_city=houston";
    const sticky_proxy = "proxy_resi_ses_id=scrape_session_404&proxy_resi_ses_time=60";
    const browserUrl = `wss://${username}:${password}@${endpoint}?${geolocation}&${sticky_proxy}`;

    const browser = await puppeteer.connect({
        browserWSEndpoint: browserUrl
    });
    const page = await browser.newPage();
    await page.goto('https://example.com');
    await browser.close();
})();
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers.oxylabs.io/products/headless-browser/geolocation-and-proxy-selection.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
