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.

Writing code without immediate resolution can be hard. Here is a code snippet, which you can use to test your Page Function's code directly in your browser's console. Just copy & paste your Page Function's code and label of matching URL you are visiting now.

This code is only for debugging your Page Function for a particular page. It does not crawl the website and the output is not saved anywhere.

First, you need to inject jQuery's code:

var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);

Then you can insert your Page Function with Mockup code:

function pageFunction(context) {
  /*
    this is your pageFunction
  */
}pageFunction ({
  request: {
    label: '', // label of actual url
    url: window.location.href
  },
  willFinishLater: function () {console.log('(willFinishLater)', arguments)},
  finish: function () {console.log('(finish)', arguments)},
  enqueuePage: function () {console.log('(enqueuePage)', arguments)},
  skipOutput: function () {console.log('(skipOutput)', arguments)},
  skipLinks: function () {console.log('(skipLinks)', arguments)},
  jQuery: $
});

Happy debugging!

Did this answer your question?