Skip to main content
Requires Python 3.12 or newer. Install the published surfsky package:
Set SURFSKY_API_TOKEN and SURFSKY_API_BASE_URL from the dashboard. See credential setup. You can also pass api_token and base_url to the client constructor.

Start a browser

Save as first_browser.py and run python first_browser.py:
Expected output is Example Domain. The browser context manager stops the session on exit, including when a page operation raises an exception. Cleanup still requires a running process and a working API connection. AsyncSurfsky provides browser automation and asynchronous REST calls. The synchronous Surfsky client provides REST calls and managed sessions for use with other browser frameworks.

Interact with the page

Page operations run inside the client.browser() block. Common methods include goto, click, type, hover, inner_text, and wait_for_selector. Wait timeouts are in seconds and default to 30; expiration raises BrowserTimeoutError. Use selectors from your target page. For example, in a form with an email field:
evaluate() executes JavaScript. It uses an isolated execution context by default; pass isolated=False when the script needs variables defined by the page. The DOM is shared, so page code can observe DOM changes made by your script.

Save traffic

Pass block_resources when starting the browser:
Keep resources needed for screenshots, layout, or challenges. See Speed optimization.

Capture a page’s API response

Start capture before the request occurs. Adapt the URL and matching path to your application:

Multiple tabs

browser operates on the first tab. browser.pages includes other tabs and popups:
Close tabs you no longer need. See the session page limit.

Running many browsers

This example runs two jobs concurrently and reports each outcome:
The pool can reuse browsers between jobs. A leased browser retains its fingerprint, proxy, and cookies between leases. Use browser.retire() to replace it after the current lease when a job needs a fresh identity. For manual leasing:
Account limits include browsers started by other workers. See Concurrency before distributing work across processes.

Proxies

Pass a proxy choice to browser() or session():
client.proxies exposes location lookups and quota calls. See Proxies for tier availability and targeting rules.

Profiles

Create a profile and save its UUID for later use:
Run this inside an AsyncSurfsky client context. Start the same UUID on subsequent runs; do not create a new profile for each job. Sessions describes the login-and-reuse workflow.

Use Playwright

Use client.session() to let the SDK manage the session while Playwright handles page operations. Install surfsky and playwright, and set the environment variables before running this example:
The session context stops the remote browser when the block exits.

Raw requests

request() returns an httpx.Response. Unlike resource methods, it does not raise for an HTTP error unless you call raise_for_status(). The SDK repository includes the full method reference and additional examples.