Skip to content

Documentation

PHP SDK: JavaScript pages and browser actions

If the HTML response has no products but an ordinary browser shows them, the site may render its catalog with JavaScript. Enable browser mode in the site settings. Then a normal $ctx->http()->get() can receive the page rendered through the platform.

For clicks, searches, and scrolling, use a managed page.

<?php
function run(\Sdk\Context $ctx): void
{
    $url = (string) $ctx->param('catalog_url', '');
    if ($url === '') {
        $ctx->abort('Set catalog_url');
    }
    $page = $ctx->browser()->open($url);
    try {
        $page->waitFor('.product-card', 15000);
        $ctx->log('Catalog rendered');
        $dom = $ctx->dom($page->content(), $url);
        foreach ($dom->qa('.product-card') as $card) {
            $sku = $card->attr('data-sku');
            if ($sku !== null) {
                $ctx->emit(['sku' => $sku, 'name' => $card->q('.product-title')?->text()], $sku);
            }
        }
        $ctx->log('Page snapshot saved', ['snapshot' => $page->screenshot()]);
    } finally {
        $page->close();
    }
}

waitFor() waits for the required element, not merely for network loading to end. This helps avoid empty screenshots and partially rendered pages. The selectors above are illustrative.

Available actions

Call Purpose
$page->goto($url) Navigate within the same page
$page->click('.load-more') Click a button using a CSS selector
$page->type('input[name=q]', 'belt') Enter text
$page->scroll(3, 500) Scroll three steps with a 500 ms pause between steps
$page->waitFor('.product-card', 15000) Wait up to 15 seconds for an element
$page->content() Get the current HTML
$page->screenshot() Save a screenshot and get its UUID
$page->close() Close the page and release a slot

At most two pages can be open at once. Always close them in finally. After clicking Load more, check that the card count increases or another batch appears. If it does not, stop with a clear message instead of clicking forever.

Browser actions consume processing time. Wait for a specific element instead of sleeping for a fixed period after every action. Respect the site's and run's limits.

Read JSON from network responses

If the interface shows only part of an API response, use browser XHR/fetch capture. Enable patterns before navigation or before the action that triggers the request.

CAPTCHA

CAPTCHA setup and API: automatic handling, opt-out, site hints, agents and verification. User guide and prices.