This article relates to the legacy Apify Crawler product, which is being retired in favor of the apify/legacy-phantomjs-crawler actor. All the information in this article is still valid, and applies to both the legacy Crawler product and the new actor. For more information, please read this blog post.

For new projects, we recommend using the newer apify/web-scraper actor that is based on the modern headless Chrome browser.

Some web pages do not load all their content immediately, but only fetch it in the background using AJAX, while pageFunction might be executed before the content has actually been loaded. You can wait for dynamic content to load using the following code:

function pageFunction(context) {
    var $ = context.jQuery;
    var startedAt =;

    var extractData = function() {
        // timeout after 10 seconds
        if( - startedAt > 10000 ) {
            context.finish("Timed out before #my_element was loaded");

        // if my element still hasn't been loaded, wait a little more
        if( $('#my_element').length === 0 ) {
            setTimeout(extractData, 500);

        // refresh page screenshot and HTML for debugging

        // save a result
            value: $('#my_element').text()

    // tell the crawler that pageFunction will finish asynchronously

Did this answer your question?