Apify

Apify and Crawlee Official Forum

b
F
A
J
A

How to pass UserData when executing crawler

When I do await crawler.run(['https://crawlee.dev'], { userData: { depth: 0 } });
I got this error:
Uncaught ArgumentError ArgumentError: Did not expect property userData to exist, got [object Object] in object options

How can I set userData in option?
`
1
H
A
t
4 comments
await crawler.run([{url: 'https://crawlee.dev', userData: { depth: 0 } }]);
userData is part of request, not part of crawler
You passed the userData as the second parameter of the run() method instead of within the request. Hence the ArgumentError.

Try this instead:
Plain Text
await crawler.run([{
    url: 'https://crawlee.dev',
    userData: {
        depth: 0,
    },
}]);
Also, something that was not obvious to me was how to get the user data on the route.
you can do it like so
Plain Text
const routeHandler = async ({ request, crawler, page, log }) => {
    // get user data
    let { depth } = request.userData  
}
Add a reply
Sign up and join the conversation on Discord
Join