Cannot inject jquery


I am trying a puppeteer crawler in my actor and I would like to inject jquery:

await puppeteer.injectJQuery(page);
const $ = window.$;
var headLine = $("h1[itemprop='headline']").text().trim();

But I get this error:

Cannot read property ‘$’ of undefined

So it seems there is no window object?



this way works for me:

handlePageFunction: async ({ request, page }) => {
  console.log(`Processing ${request.url}...`);

  await Apify.utils.puppeteer.injectJQuery(page);

  const test = await page.evaluate(() => {
    return $('title').text().trim()

  await Apify.pushData({ test });


Seems that I have to use evaluate function when working with puppeteer crawler…