Ctrl + K

Browser API

Automate browsers, take screenshots, extract page content, and monitor network requests in your sandbox environment.

Get Page Content

Extract HTML content and text from web pages:

const result = await sandbox.browser.getPageContent({
  url: 'https://example.com',
  waitFor: 1000,
  selector: '.content',
  waitForFullLoad: true
});

console.log(result.html);
console.log(result.text);
const response = await fetch(`${sandbox.url}/browser/content`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://example.com',
    waitFor: 1000,
    selector: '.content',
    waitForFullLoad: true
  })
});

const result = await response.json();
curl -X POST https://sandbox-abc123.oblien.com/browser/content \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "waitFor": 1000,
    "selector": ".content",
    "waitForFullLoad": true
  }'

Response:

{
  "success": true,
  "html": "<div class=\"content\">...</div>",
  "text": "Page text content",
  "url": "https://example.com"
}

Parameters:

ParameterTypeDescription
urlstringURL to visit (required)
pathstringPath for container URLs
waitFornumberWait time in ms
selectorstringCSS selector to extract
extractstringSpecific data to extract
waitForFullLoadbooleanWait for all resources
useProxybooleanUse proxy for request

Take Screenshot

Capture screenshots of web pages:

const result = await sandbox.browser.screenshot({
  url: 'https://example.com',
  width: 1920,
  height: 1080,
  fullPage: true,
  format: 'png',
  save: true
});

console.log(result.screenshot); // base64 encoded
console.log(result.path); // saved file path
const response = await fetch(`${sandbox.url}/browser/screenshot`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://example.com',
    width: 1920,
    height: 1080,
    fullPage: true,
    format: 'png',
    save: true
  })
});

const result = await response.json();
curl -X POST https://sandbox-abc123.oblien.com/browser/screenshot \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "width": 1920,
    "height": 1080,
    "fullPage": true,
    "format": "png",
    "save": true
  }'

Response:

{
  "success": true,
  "screenshot": "iVBORw0KGgoAAAANSUhEUgAA...",
  "path": "/opt/app/screenshots/example-com-1234567890.png",
  "format": "png"
}

Parameters:

ParameterTypeDefaultDescription
urlstringrequiredURL to screenshot
pathstring-Path for container URLs
widthnumber1920Viewport width
heightnumber1080Viewport height
fullPagebooleanfalseCapture full page
formatstringpngpng, jpeg, or webp
qualitynumber80Image quality (1-100)
selectorstring-Screenshot specific element
savebooleanfalseSave to file
deviceTypestring-Device preset
scalenumber1Device scale factor
timeoutnumber30000Timeout in ms

Monitor Network Requests

Capture network requests made by a page:

const result = await sandbox.browser.monitorRequests({
  url: 'https://example.com',
  duration: 5000,
  filterTypes: ['fetch', 'xhr']
});

result.requests.forEach(req => {
  console.log(`${req.method} ${req.url}`);
  console.log(`Status: ${req.status}`);
});
const response = await fetch(`${sandbox.url}/browser/monitor`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://example.com',
    duration: 5000,
    filterTypes: ['fetch', 'xhr']
  })
});

const result = await response.json();
curl -X POST https://sandbox-abc123.oblien.com/browser/monitor \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "duration": 5000,
    "filterTypes": ["fetch", "xhr"]
  }'

Response:

{
  "success": true,
  "requests": [
    {
      "method": "GET",
      "url": "https://api.example.com/data",
      "status": 200,
      "type": "fetch",
      "headers": {...},
      "response": {...}
    }
  ],
  "total": 15
}

Get Console Logs

Capture browser console output:

const result = await sandbox.browser.getConsoleLogs({
  url: 'https://example.com',
  waitFor: 2000,
  includeNetworkErrors: true,
  flatten: true
});

result.logs.forEach(log => {
  console.log(`[${log.type}] ${log.text}`);
});
const response = await fetch(`${sandbox.url}/browser/console`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://example.com',
    waitFor: 2000,
    includeNetworkErrors: true,
    flatten: true
  })
});

const result = await response.json();
curl -X POST https://sandbox-abc123.oblien.com/browser/console \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "waitFor": 2000,
    "includeNetworkErrors": true,
    "flatten": true
  }'

Response:

{
  "success": true,
  "logs": [
    {
      "type": "log",
      "text": "Application loaded",
      "timestamp": 1234567890
    },
    {
      "type": "error",
      "text": "Failed to load resource",
      "timestamp": 1234567891
    }
  ]
}

Get Device Presets

List available device emulation presets:

const presets = await sandbox.browser.getDevicePresets();

console.log(presets.devices);
// iPhone, iPad, Galaxy, etc.
const response = await fetch(`${sandbox.url}/browser/devices`, {
  headers: {
    'Authorization': `Bearer ${sandbox.token}`
  }
});

const presets = await response.json();
curl https://sandbox-abc123.oblien.com/browser/devices \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN"

Clean Screenshots

Remove saved screenshots:

await sandbox.browser.cleanScreenshots({
  url: 'https://example.com'
});
await fetch(`${sandbox.url}/browser/clean`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://example.com'
  })
});
curl -X POST https://sandbox-abc123.oblien.com/browser/clean \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com"
  }'

Complete Example

// Screenshot a web app
const screenshot = await sandbox.browser.screenshot({
  url: 'https://app.example.com/dashboard',
  width: 1920,
  height: 1080,
  fullPage: true,
  save: true
});

console.log('Screenshot saved:', screenshot.path);

// Extract data from page
const content = await sandbox.browser.getPageContent({
  url: 'https://example.com/products',
  selector: '.product-list',
  waitForFullLoad: true
});

console.log('Products HTML:', content.html);

// Monitor API calls
const network = await sandbox.browser.monitorRequests({
  url: 'https://example.com',
  duration: 5000,
  filterTypes: ['fetch', 'xhr']
});

console.log(`Captured ${network.total} requests`);

// Check for console errors
const logs = await sandbox.browser.getConsoleLogs({
  url: 'https://example.com',
  includeNetworkErrors: true
});

const errors = logs.logs.filter(log => log.type === 'error');
if (errors.length > 0) {
  console.log('Found errors:', errors);
}
// Screenshot
let response = await fetch(`${sandbox.url}/browser/screenshot`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://app.example.com/dashboard',
    fullPage: true,
    save: true
  })
});

// Extract content
response = await fetch(`${sandbox.url}/browser/content`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://example.com/products',
    selector: '.product-list'
  })
});

// Monitor requests
response = await fetch(`${sandbox.url}/browser/monitor`, {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${sandbox.token}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    url: 'https://example.com',
    duration: 5000
  })
});
# Screenshot
curl -X POST https://sandbox-abc123.oblien.com/browser/screenshot \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://app.example.com/dashboard",
    "fullPage": true,
    "save": true
  }'

# Extract content
curl -X POST https://sandbox-abc123.oblien.com/browser/content \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/products",
    "selector": ".product-list"
  }'

# Monitor requests
curl -X POST https://sandbox-abc123.oblien.com/browser/monitor \
  -H "Authorization: Bearer YOUR_SANDBOX_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "duration": 5000
  }'

Use Cases

Visual Testing

// Capture screenshots for visual regression
const screenshot = await sandbox.browser.screenshot({
  url: 'https://app.example.com',
  fullPage: true,
  save: true
});

Web Scraping

// Extract structured data
const content = await sandbox.browser.getPageContent({
  url: 'https://example.com/listings',
  selector: '.listing-item',
  waitForFullLoad: true
});

Performance Monitoring

// Monitor network performance
const requests = await sandbox.browser.monitorRequests({
  url: 'https://app.example.com',
  duration: 10000
});

const slowRequests = requests.requests.filter(r => r.duration > 1000);
console.log('Slow requests:', slowRequests);

Error Detection

// Find JavaScript errors
const logs = await sandbox.browser.getConsoleLogs({
  url: 'https://app.example.com',
  includeNetworkErrors: true
});

const errors = logs.logs.filter(l => l.type === 'error');
if (errors.length > 0) {
  console.error('Page has errors:', errors);
}

Best Practices

  1. Set appropriate timeouts: Use timeout parameter for slow-loading pages

  2. Use selectors for targeted extraction: Extract specific elements instead of entire pages

  3. Save screenshots when needed: Set save: true to keep screenshots for later

  4. Monitor specific request types: Filter by ['fetch', 'xhr'] for API calls only

  5. Clean up screenshots: Regularly clean saved screenshots to save space

Next Steps