Skip to main content

One time profiles

This tutorial will show you how to work with surfsky cloud browser one time profiles.

Set environment variables

export API_TOKEN=... # Provided api token
export PROXY=... # Your proxy in `<schema>://<user>:<password>@<host>:<port>` format

Start one time profile

This example will show you how to start one time profile. One time profile don't save it's state after closing, and you have to provide proxy or open vpn config on every start. You can find all parameters explanation on our api page

import os

import httpx

API_TOKEN = os.environ['API_TOKEN']
PROXY = os.environ['PROXY']


async def start_one_time_profile():
async with httpx.AsyncClient(
base_url='https://api-public.surfsky.io',
headers={'X-Cloud-Api-Token': API_TOKEN},
timeout=60.0,
) as client:
browser_data_resp = await client.post('/profiles/one_time', json={'proxy': PROXY})
browser_data_resp.raise_for_status()

return browser_data_resp.json()

Connect with Playwright

Setup requirements

pip install httpx playwright

Connect to browser, load amazon and take screenshot

import os

import httpx
from playwright.sync_api import sync_playwright

ONE_TIME_PROFILE_URL = 'https://api-public.surfsky.io/profiles/one_time'
API_TOKEN = os.getenv('API_TOKEN')
PROXY = os.getenv('PROXY')

headers = {"X-Cloud-Api-Token": API_TOKEN}
body = {"proxy": PROXY}
one_time_profile_create_response = httpx.post(ONE_TIME_PROFILE_URL, json=body, headers=headers)
one_time_profile_url = one_time_profile_create_response.json()['ws_url']

playwright = sync_playwright().start()
browser = playwright.chromium.connect_over_cdp(one_time_profile_url)

page = browser.new_page()
page.goto('https://amazon.com')
page.screenshot(path='screen.png')

browser.close()
playwright.stop()

Connect with Puppeteer

Setup requirements

pip install pyppeteer httpx

Connect to browser, load amazon and take screenshot

import asyncio
import os

import httpx
from pyppeteer import connect

ONE_TIME_PROFILE_URL = 'https://api-public.surfsky.io/profiles/one_time'
API_TOKEN = os.getenv('API_TOKEN')
PROXY = os.getenv('PROXY')

headers = {"X-Cloud-Api-Token": API_TOKEN}
body = {"proxy": PROXY}


async def main():
one_time_profile_create_response = httpx.post(ONE_TIME_PROFILE_URL, json=body, headers=headers)
one_time_profile_url = one_time_profile_create_response.json()['ws_url']

browser = await connect({'browserWSEndpoint': one_time_profile_url, 'defaultViewport': None})

page = await browser.newPage()
await page.goto('https://amazon.com')
await page.screenshot(path='screen.png')

await browser.close()

asyncio.run(main())