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:
| Parameter | Type | Description |
|---|---|---|
url | string | URL to visit (required) |
path | string | Path for container URLs |
waitFor | number | Wait time in ms |
selector | string | CSS selector to extract |
extract | string | Specific data to extract |
waitForFullLoad | boolean | Wait for all resources |
useProxy | boolean | Use 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 pathconst 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:
| Parameter | Type | Default | Description |
|---|---|---|---|
url | string | required | URL to screenshot |
path | string | - | Path for container URLs |
width | number | 1920 | Viewport width |
height | number | 1080 | Viewport height |
fullPage | boolean | false | Capture full page |
format | string | png | png, jpeg, or webp |
quality | number | 80 | Image quality (1-100) |
selector | string | - | Screenshot specific element |
save | boolean | false | Save to file |
deviceType | string | - | Device preset |
scale | number | 1 | Device scale factor |
timeout | number | 30000 | Timeout 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
-
Set appropriate timeouts: Use
timeoutparameter for slow-loading pages -
Use selectors for targeted extraction: Extract specific elements instead of entire pages
-
Save screenshots when needed: Set
save: trueto keep screenshots for later -
Monitor specific request types: Filter by
['fetch', 'xhr']for API calls only -
Clean up screenshots: Regularly clean saved screenshots to save space
Next Steps
- File Operations - Work with files
- Terminal - Execute commands
- Snapshots - Save environment states