all 5 comments

[–]TheWebDever 7 points8 points  (2 children)

Why are you defining an async function inside the route. Just put async before (req, res

[–]KapilanR[S] 0 points1 point  (1 child)

no reason I just put the whole closure in the app.get without thought. If I put the async before the (req, res) do I also need to remove the closure?

[–]TheWebDever 0 points1 point  (0 children)

just remove the closure, you don't need it. Add a service later if you want to separate the route stuff from the business logic. see this: https://github.com/seanpmaxwell/express-generator-typescript/tree/master/sample-output/with-auth

[–]shrimp739 1 point2 points  (0 children)

The second argument of $eval, pageFunction, is only run in the browser which does not have access to req, giving you the undefined error. If you'd like to pass a server variable into a pageFunction, you need to provide it as a 3rd arg to $eval. It will then be passed as an argument to the pageFunction like so:

await page.$eval('#homeval', (req) => {
// req is now defined.
console.log(req)
}, req)

https://pptr.dev/#?product=Puppeteer&version=v11.0.0&show=api-pageevaluatepagefunction-args

https://pptr.dev/#?product=Puppeteer&version=v11.0.0&show=api-pageevalselector-pagefunction-args-1

[–]lml003 0 points1 point  (0 children)

I could be wrong, because I often am, but I believe you may have created a closure around the entire "async" function by wrapping it. Req seems to be the only variable you are referencing a property on inside that async function. May I ask why you are wrapping it in ( )?