Big_Smoke_420B
Apify & Crawlee2y ago
2 replies
Big_Smoke_420

router.addHandler from a separate function

Say I have code like this:

import { createPlaywrightRouter, Dataset } from 'crawlee';

export const router = createPlaywrightRouter();

router.addHandler('CATEGORY', async ({ request, page, enqueueLinks, log }) => {
    log.debug(`Enqueueing categories from page: ${request.url}`);

    await page.waitForSelector('.collection-block-item');
    await enqueueLinks({
        selector: '.collection-block-item',
        label: 'CATEGORY',
    });
});


Now I'm not particularly good in JS, so hoping that some JS gurus can chime in here, but is there any way that the callback async ({ request, page, enqueueLinks, log }) => { ... } could be put inside a separate function and instead pass the function to addHandler?

So something like this:

import doStuff from './stuff';

router.addHandler('CATEGORY', doStuff);
Was this page helpful?