This directory contains example usage of the Open Browser Rendering API.
const fetch = require('node-fetch');
const fs = require('fs');
async function takeScreenshot() {
const response = await fetch('http://localhost:3000/screenshot', {
method: 'POST',
headers: {
'Authorization': 'Bearer supersecret123',
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: 'https://example.com',
viewport: { width: 1920, height: 1080 },
screenshotOptions: { fullPage: true, type: 'png' }
})
});
const buffer = await response.buffer();
fs.writeFileSync('screenshot.png', buffer);
console.log('Screenshot saved!');
}
takeScreenshot();const fetch = require('node-fetch');
const fs = require('fs');
async function generatePDF() {
const response = await fetch('http://localhost:3000/pdf', {
method: 'POST',
headers: {
'Authorization': 'Bearer supersecret123',
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: 'https://example.com',
format: 'A4',
printBackground: true
})
});
const buffer = await response.buffer();
fs.writeFileSync('page.pdf', buffer);
console.log('PDF saved!');
}
generatePDF();const fetch = require('node-fetch');
async function evaluateScript() {
const response = await fetch('http://localhost:3000/evaluate', {
method: 'POST',
headers: {
'Authorization': 'Bearer supersecret123',
'Content-Type': 'application/json'
},
body: JSON.stringify({
url: 'https://example.com',
script: 'document.title'
})
});
const result = await response.json();
console.log('Page title:', result.result);
}
evaluateScript();import requests
def take_screenshot():
response = requests.post(
'http://localhost:3000/screenshot',
headers={
'Authorization': 'Bearer supersecret123',
'Content-Type': 'application/json'
},
json={
'url': 'https://example.com',
'viewport': {'width': 1920, 'height': 1080},
'screenshotOptions': {'fullPage': True, 'type': 'png'}
}
)
with open('screenshot.png', 'wb') as f:
f.write(response.content)
print('Screenshot saved!')
take_screenshot()import requests
def generate_pdf():
response = requests.post(
'http://localhost:3000/pdf',
headers={
'Authorization': 'Bearer supersecret123',
'Content-Type': 'application/json'
},
json={
'url': 'https://example.com',
'format': 'A4',
'printBackground': True
}
)
with open('page.pdf', 'wb') as f:
f.write(response.content)
print('PDF saved!')
generate_pdf()<?php
function takeScreenshot() {
$ch = curl_init('http://localhost:3000/screenshot');
$data = json_encode([
'url' => 'https://example.com',
'viewport' => ['width' => 1920, 'height' => 1080],
'screenshotOptions' => ['fullPage' => true, 'type' => 'png']
]);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer supersecret123',
'Content-Type: application/json'
]);
$result = curl_exec($ch);
curl_close($ch);
file_put_contents('screenshot.png', $result);
echo 'Screenshot saved!';
}
takeScreenshot();
?>curl -X POST http://localhost:3000/screenshot \
-H "Authorization: Bearer supersecret123" \
-H "Content-Type: application/json" \
-o screenshot.png \
-d '{
"url": "https://example.com",
"viewport": {"width": 1920, "height": 1080},
"screenshotOptions": {"fullPage": true, "type": "png"}
}'curl -X POST http://localhost:3000/pdf \
-H "Authorization: Bearer supersecret123" \
-H "Content-Type: application/json" \
-o page.pdf \
-d '{
"url": "https://example.com",
"format": "A4",
"printBackground": true
}'curl -X POST http://localhost:3000/evaluate \
-H "Authorization: Bearer supersecret123" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"script": "document.title"
}'curl http://localhost:3000/healthcurl -X POST http://localhost:3000/screenshot \
-H "Authorization: Bearer supersecret123" \
-H "Content-Type: application/json" \
-o screenshot.jpg \
-d '{
"url": "https://example.com",
"viewport": {"width": 1920, "height": 1080},
"screenshotOptions": {
"fullPage": false,
"type": "jpeg",
"quality": 90
},
"gotoOptions": {
"waitUntil": "networkidle",
"timeout": 45000
}
}'curl -X POST http://localhost:3000/evaluate \
-H "Authorization: Bearer supersecret123" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"script": "({ title: document.title, url: window.location.href, links: Array.from(document.querySelectorAll(\"a\")).length })"
}'See the examples/ directory for complete integration examples:
examples/node-express/- Express.js integrationexamples/python-flask/- Flask integrationexamples/php-laravel/- Laravel integration