PHP code example of browser7 / sdk

1. Go to this page and download the library: Download browser7/sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

browser7 / sdk example snippets




rowser7\Browser7Client;

$client = new Browser7Client('your-api-key');

// Simple render
$result = $client->render('https://example.com');
echo $result->html;

$client = new Browser7Client('b7_your_api_key_here');

$result = $client->render('https://example.com', [
    'countryCode' => 'US'
]);

echo $result->html;              // Rendered HTML
print_r($result->selectedCity);  // City used for rendering

use Browser7\WaitAction;

$result = $client->render('https://example.com', [
    'countryCode' => 'GB',
    'city' => 'london',
    'waitFor' => [
        WaitAction::click('.cookie-accept'),          // Click element
        WaitAction::selector('.main-content'),         // Wait for element
        WaitAction::delay(2000)                        // Wait 2 seconds
    ]
]);

$result = $client->render('https://protected-site.com', [
    'countryCode' => 'US',
    'captcha' => 'auto'  // Auto-detect and solve CAPTCHAs
]);

print_r($result->captcha);  // CAPTCHA detection info

$result = $client->render('https://example.com', [
    'countryCode' => 'US',
    '> 80,        // 1-100 (JPEG only)
    'screenshotFullPage' => false     // false = viewport only, true = full page
]);

// Save screenshot to file
file_put_contents('screenshot.jpg', base64_decode($result->screenshot));

$result = $client->render('https://example.com', [
    'fetchUrls' => [
        'https://example.com/api/data',
        'https://example.com/api/user'
    ]
]);

print_r($result->fetchResponses);  // Array of fetch responses

$balance = $client->getAccountBalance();

echo "Total: " . $balance->totalBalanceFormatted . "\n";
echo "Renders remaining: " . $balance->totalBalanceCents . "\n";
echo "\nBreakdown:\n";
echo "  Paid: " . $balance->breakdown->paid->formatted . " (" . $balance->breakdown->paid->cents . " renders)\n";
echo "  Free: " . $balance->breakdown->free->formatted . " (" . $balance->breakdown->free->cents . " renders)\n";
echo "  Bonus: " . $balance->breakdown->bonus->formatted . " (" . $balance->breakdown->bonus->cents . " renders)\n";

// Production (default)
$client = new Browser7Client('your-api-key');

// Canadian endpoint
$client = new Browser7Client(
    'your-api-key',
    'https://ca-api.browser7.com/v1'
);

$balance = $client->getAccountBalance();
echo "Total: " . $balance->totalBalanceFormatted . "\n";
echo "Renders remaining: " . $balance->totalBalanceCents . "\n";

WaitAction::delay(3000);  // Wait 3 seconds

WaitAction::selector('.main-content', 'visible', 10000);

WaitAction::text('In Stock', '.availability', 10000);

WaitAction::click('.cookie-accept', 5000);