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
- Python
- JavaScript
pip install httpx playwright
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i axios playwright
Connect to browser, load amazon and take screenshot
- Python
- JavaScript
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()
const axios = require('axios')
const { chromium } = require('playwright')
const API_TOKEN = process.env.API_TOKEN
const PROXY = process.env.PROXY
const BROWSER_API = axios.create({
baseURL: 'https://api-public.surfsky.io',
timeout: 100000,
})
async function startOneTimeProfile() {
const response = await BROWSER_API.post(
'/profiles/one_time',
{ proxy: PROXY },
{ headers: { 'X-Cloud-Api-Token': API_TOKEN } }
)
return response.data.ws_url
}
async function main() {
const { wsEndpoint } = await startOneTimeProfile()
const browser = await chromium.connectOverCDP(wsEndpoint)
const page = await browser.newPage()
await page.goto('https://amazon.com')
await page.screenshot({ path: 'screen.png' })
await browser.close()
}
;(async () => await main())()
Connect with Puppeteer
Setup requirements
- Python
- JavaScript
pip install pyppeteer httpx
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 npm i puppeteer axios
Connect to browser, load amazon and take screenshot
- Python
- JavaScript
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())
const axios = require('axios')
const puppeteer = require('puppeteer')
const API_TOKEN = process.env.API_TOKEN
const PROXY = process.env.PROXY
const BROWSER_API = axios.create({
baseURL: 'https://api-public.surfsky.io',
timeout: 100000,
})
async function startOneTimeProfile() {
const response = await BROWSER_API.post(
'/profiles/one_time',
{ proxy: PROXY },
{ headers: { 'X-Cloud-Api-Token': API_TOKEN } }
)
return response.data.ws_url
}
async function main() {
const { wsEndpoint } = await startOneTimeProfile()
const browser = await puppeteer.connect({
browserWSEndpoint: wsEndpoint,
defaultViewport: null
})
const page = await browser.newPage()
await page.goto('https://amazon.com')
await page.screenshot({ path: 'screen.png' })
await browser.disconnect()
}
;(async () => await main())()