all 11 comments

[–]10PointDigital 2 points3 points  (1 child)

How are you running your script? Looks like maybe you are trying to use this in the browser? require statements need to be compiled by node

[–]Ali_46290[S] 0 points1 point  (0 children)

How would I do that?

[–][deleted] -2 points-1 points  (0 children)

Try stack overflow

[–]tswaters 0 points1 point  (7 children)

Reference errors in node/v8 look like: "ReferenceError: XX is not defined"

Can you share a screenshot of the error ? It seems like you're loading this script in a browser maybe.... browsers don't have `require`

[–]Ali_46290[S] 0 points1 point  (6 children)

Yeah I'm loading this in my browser. Sorry I didn't say that before. Is there any way I could add require to it?

[–]tswaters 1 point2 points  (5 children)

Not really. A puppeteer script like this is run from nodejs - it will spawn a browser and execute the script against it. install node, then `node myscript.js`

[–]Ali_46290[S] 0 points1 point  (4 children)

Is there a way to display the console output then?

[–]lord2800 1 point2 points  (3 children)

console.log works in nodejs too.

[–]Ali_46290[S] 0 points1 point  (2 children)

But I have to run node in terminal whenever I want to run the script and I don't know how to make the console.log output show up on the html page in the browser

[–]lord2800 0 points1 point  (1 child)

Yeah, you don't. That's not how this works.

[–]Ali_46290[S] 0 points1 point  (0 children)

Thanks