Skip to content

Commit

Permalink
fix(puppeteer): replace page.waitForTimeout() with sleep()
Browse files Browse the repository at this point in the history
Closes #2335
  • Loading branch information
B4nan committed Feb 15, 2024
1 parent a8cd603 commit 52d7219
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Expand Up @@ -26,7 +26,7 @@ import log_ from '@apify/log';
import type { Request } from '@crawlee/browser';
import { KeyValueStore, RequestState, validators, Configuration } from '@crawlee/browser';
import type { Dictionary, BatchAddRequestsResult } from '@crawlee/types';
import type { CheerioRoot } from '@crawlee/utils';
import { type CheerioRoot, sleep } from '@crawlee/utils';
import * as cheerio from 'cheerio';
import type { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping.js';
import { getInjectableScript } from 'idcac-playwright';
Expand Down Expand Up @@ -524,7 +524,7 @@ export async function infiniteScroll(page: Page, options: InfiniteScrollOptions
let retry = 0;

while (!body && retry < 10) {
await page.waitForTimeout(100);
await sleep(100);
body = await page.$('body');
retry++;
}
Expand Down Expand Up @@ -584,7 +584,7 @@ export async function infiniteScroll(page: Page, options: InfiniteScrollOptions

while (!finished) {
await doScroll();
await page.waitForTimeout(250);
await sleep(250);
if (scrollDownAndUp) {
await page.mouse.wheel({ deltaY: -1000 });
}
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/puppeteer-default/actor/main.js
Expand Up @@ -11,7 +11,8 @@ await Actor.main(async () => {
preNavigationHooks: [(_ctx, goToOptions) => {
goToOptions.waitUntil = ['networkidle2'];
}],
async requestHandler({ page, enqueueLinks, request }) {
async requestHandler({ page, enqueueLinks, request, infiniteScroll }) {
await infiniteScroll();
const { url } = request;
const pageTitle = await page.title();
await Dataset.pushData({ url, pageTitle });
Expand Down

0 comments on commit 52d7219

Please sign in to comment.