Тёмный

Automate Chrome in an API with Puppeteer and Netlify Serverless Functions 

Colby Fayock
Подписаться 31 тыс.
Просмотров 11 тыс.
50% 1

Опубликовано:

 

14 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 94   
@colbyfayock
@colbyfayock 2 месяца назад
Learn how to build a full stack Next.js app in my upcoming course: colbyfayock.com/course
@robinbeaudru6892
@robinbeaudru6892 2 года назад
Thank you man! Amazing! We want more of those Puppeteer serverless stuffs!
@colbyfayock
@colbyfayock 2 года назад
thanks Robin!
@TKTBC777
@TKTBC777 Год назад
Thanks for 1000 times hahaha I've used a couple days to find solution for using puppeteer with serverless functions. Now I found it on you video
@colbyfayock
@colbyfayock Год назад
haha 💯 glad it helped
@MaxProgramming
@MaxProgramming 3 года назад
This is exactly what I wanted. I am loving netlify serverless functions and puppeteer but i wanted to know if they can work together
@colbyfayock
@colbyfayock 3 года назад
yesss its a powerful combo!
@JamesQQuick
@JamesQQuick 3 года назад
This is very neat!
@colbyfayock
@colbyfayock 3 года назад
thanks James 😁🙌
@christiandiazportela1798
@christiandiazportela1798 3 года назад
Thanks a lot, Colby! your channel is underrated! regards from Bolivia.
@colbyfayock
@colbyfayock 3 года назад
thanks Christian, really appreciate that :) cheers!
@mariusailisoaie183
@mariusailisoaie183 2 года назад
Thank you very much for the tutorial! It was useful and helpful.
@colbyfayock
@colbyfayock 2 года назад
No problem!
@c4346
@c4346 3 года назад
Very useful and interesting as always, thanks colby :)
@colbyfayock
@colbyfayock 3 года назад
No problem 💪
@k.t.2540
@k.t.2540 2 года назад
This tutorial was very useful. Thank you
@colbyfayock
@colbyfayock 2 года назад
you're welcome! :)
@sureshmangs4806
@sureshmangs4806 3 года назад
Amazing, thanks Colby.
@colbyfayock
@colbyfayock 3 года назад
No problem! 🙌
@dotnet501
@dotnet501 3 года назад
Thanks, space jelly 🙏🍻
@colbyfayock
@colbyfayock 3 года назад
you got it! 😁💪
@dragosvlasie8875
@dragosvlasie8875 10 месяцев назад
Great video! And thanks for sharing the github link as well
@colbyfayock
@colbyfayock 10 месяцев назад
no problem!
@dragosvlasie8875
@dragosvlasie8875 10 месяцев назад
Unfortunatly this is not working anymore, :(, since the update to node v18 on netlify
@rushdude87
@rushdude87 Год назад
Very helpful video, although I am struggling with the deployment stage. When running netlify deploy, it just seems to hang until eventually I get a JSON HTTP error with a status code of 500 and the logs on netlify just say cancelling deployment and I'm not sure why. Following your example, I don't have a build script since my app runs the same as yours, however it seems like when attempting to deploy from Github instead of the CLI, netlify runs a build command, which we don't have in this case.
@colbyfayock
@colbyfayock Год назад
try running `netlify deploy --build`, that may help
@bassguitarist2686
@bassguitarist2686 Месяц назад
Thanks for the tutorial, I get all the way to the point where I test to return the title but I get this "message": "Protocol error (Page.navigate): Target closed.", I put await on mostly everything that I can see would need to.
@colbyfayock
@colbyfayock Месяц назад
hey you should check out this newer video i published recently, it may be helpful to get this working properly: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-kOdIzhPfLuo.html
@bassguitarist2686
@bassguitarist2686 Месяц назад
@@colbyfayock Thank you Colby!
@muneebakram1670
@muneebakram1670 3 года назад
Awesome man, You are great. Thanks for sharing.
@colbyfayock
@colbyfayock 3 года назад
thanks :) and you're welcome!
@navpan18
@navpan18 3 года назад
Loved it
@colbyfayock
@colbyfayock 3 года назад
thank you!!
@berry772
@berry772 3 года назад
Thanks! This is great!
@colbyfayock
@colbyfayock 3 года назад
no problem!
@jamesgrubb
@jamesgrubb 2 года назад
Hi, Colby thanks for this tutorial, fantastic post. I'm trying to port this workflow to Nextjs. Firstly I tried as is and was getting a bunch of errors I then tried using puppeteer (as opposed to puppeteer-core) this worked locally but failed when uploaded to Netlify and Vercel's servers. Any thoughts, please.
@colbyfayock
@colbyfayock 2 года назад
hey James, thanks! i dont have much context here but when deploying to cloud providers you need to be able to include a browser to be spun up virtually, thats where the chrome-aws-lambda comes in: github.com/alixaxel/chrome-aws-lambda - sounds like that might be the issue? you can see my setup and configuration here: github.com/colbyfayock/my-puppeteer-function/blob/main/functions/results.js
@jamesgrubb
@jamesgrubb 2 года назад
@@colbyfayock Thanks for your time. Are there any reasons why the code woud not work inside NextJs's API/? Probably a typo on my part Ill check again.
@colbyfayock
@colbyfayock 2 года назад
@@jamesgrubb not totally sure off the top of my head. Did you happen to see any error logs? If not you could try adding some random console logs or try catches and see where it's railing
@colbyfayock
@colbyfayock 2 года назад
@@jamesgrubb I wrote this a while ago that gets deployed to Vercel but as you can see here I used the Vercel function pattern and deployment instead of nextjs. Can't remember the reason behind this but that might be a sign github.com/AutomationPanda/applitools-preview/blob/main/functions/eyes.js
@jamesgrubb
@jamesgrubb 2 года назад
@@colbyfayock Thanks again
@isagive
@isagive 2 года назад
Great job man. Thank you
@colbyfayock
@colbyfayock 2 года назад
thanks, you got it!
@seewai
@seewai Год назад
Do you have any guidance on setting this up with CORS? Right now, when i try and pass data in the body of the request or just try and ping the endpoint, I get a CORS error and the function doesn't work. This happens on localhost and live.
@colbyfayock
@colbyfayock Год назад
have you seen this? answers.netlify.com/t/netlify-function-blocked-by-cors-policy/85438
@jazperruedas8114
@jazperruedas8114 2 года назад
Hey really awesome work!! I'm still new with back end stuff, I really wanna know if I can implement this to my chrome extension, I want it to show the data on other website(adding element div using chrome extension stuff) using headless browsing but need it to be interactable like "VehicleStatus("DJAI" ,"3C6MRVJGOME571321") " and will pull up the status on the spefic page I wanted
@colbyfayock
@colbyfayock 2 года назад
hey not really sure, havent worked with chrome extensions, but you could totally accept a body in the serverless function and pass that into whatever logic in the headless browser session to find what yo uneed
@fadelibrahim7663
@fadelibrahim7663 2 года назад
what about netlify functions pricing? can you give an example how it is gonna be if we scaled scraping puppeteer with netlify how much does the free plan will last
@colbyfayock
@colbyfayock 2 года назад
Their pricing page has a good summary of what's included. You'd need to do the expected calculations for your projects www.netlify.com/pricing/
@justinfleagle
@justinfleagle Год назад
What if I have to sign in using Puppeteer, snd I have to keep the connection open to wait for a user of the application to make API requests?
@colbyfayock
@colbyfayock Год назад
can you elaborate on what you're asking? most providers have a limit for how much time you're able to keep a function running, but generally speaking, as long as you're within that time limit, the function shouldn't just shut off until you respond or hit that timeout
@justinfleagle
@justinfleagle Год назад
​@@colbyfayock Gladly. Here is an example: An application needs to use Puppeteer to sign in, get request headers and use them to make requests to non-public APIs. The catch is, is that the sign in session needs to be kept open to allow for a user (on some random front-end) to make a request to fetch that non-public API data using the session from signing in using Puppeteer.
@sanskaarpatni9137
@sanskaarpatni9137 3 года назад
Amazing!
@colbyfayock
@colbyfayock 3 года назад
Thank you!
@muslim101f
@muslim101f 3 года назад
Really so cool! thanks.
@colbyfayock
@colbyfayock 3 года назад
no rpoblem!
@cjaffiliated6422
@cjaffiliated6422 2 года назад
can you do puppeteer web scrapping video for scrapping aliexpress product page, the product description
@colbyfayock
@colbyfayock 2 года назад
Thanks for the suggestion. I'll add it to my list
@kizhissery
@kizhissery 2 года назад
how to use context to change the variable in url pls
@colbyfayock
@colbyfayock 2 года назад
can you elaborate? not sure i'm following
@paterfamilias01
@paterfamilias01 2 года назад
Awesome.
@colbyfayock
@colbyfayock 2 года назад
thanks!
@raze_quaza
@raze_quaza 2 года назад
Had this working for a few months, then came back to my program after a break and now I'm receiving an Error: Navigation failed because browser has disconnected! .. Happens in dev, and made sure my executablePath is pointing to my Chrome app. Any help would be greatly appreciated 🙏🙏🙏 Thanks for the great video!
@colbyfayock
@colbyfayock 2 года назад
so it's still working when deployed though?
@raze_quaza
@raze_quaza 2 года назад
@@colbyfayock I just checked earlier today and although it doesn't error out in prod it doesn't technically work. It's supposed to post data to my database but doesn't
@raze_quaza
@raze_quaza 2 года назад
It's kinda hard to debug in prod
@colbyfayock
@colbyfayock 2 года назад
@@raze_quaza maybe you can try adding console logs to look at the function logs? you can add things like try/catch around the requests / functionality to see if any issues pop up. i also like to add console.log checkpoints to see how far it got before it failed
@scottfwalter
@scottfwalter 3 года назад
To use an async function so you need to have a paid tier of netlify?
@colbyfayock
@colbyfayock 3 года назад
im not aware of that requiring a paid tier? are you thinking of background functions?
@scottfwalter
@scottfwalter 3 года назад
@@colbyfayock I'm new to Netlify. When I saw async in the function I thought that meant background function. Since from my reading functions are synchronous and background functions are asynchronous. However, I realize now all functions re marked as async.
@colbyfayock
@colbyfayock 3 года назад
@@scottfwalter yeah they're synchronous in that they'll run as soon as you make the request and return a response in a synchronous-like way, but that doesn't refer to whats happening inside of the function
@eleah2665
@eleah2665 3 года назад
Team! Can I outsource my brain to puppeteer? I think I can.
@colbyfayock
@colbyfayock 3 года назад
We have the technology!
@staz-tech9961
@staz-tech9961 2 года назад
Does anyone else get this error? "errorMessage": "Failed to launch the browser process!
@colbyfayock
@colbyfayock 2 года назад
hey! are you using the same tech / libraries that i used in the video? here's my code if that helps github.com/colbyfayock/my-puppeteer-function
@jamalmriley
@jamalmriley Год назад
@@colbyfayock I got the same error and I checked that I'm using the same code/libraries as you. Is it because chrome-aws-lambda is deprecated now?
@colbyfayock
@colbyfayock Год назад
@@jamalmriley it might be the node version. last time i tried this with the same package versions, the node version gave me issues, particularly trying to deploy with that version / make other packages work with it
@adityamaurya9851
@adityamaurya9851 Год назад
yes the jest tutorial please 🙏 I am stuck with my code working 2/5 times 😭
@colbyfayock
@colbyfayock Год назад
Not sure if this might help ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-2HFEFz7LWdE.html
@adityamaurya9851
@adityamaurya9851 Год назад
@@colbyfayock ong thanks for the reply and yes this is exactly the video I needed 😭🙏 hope you get a million subs asap
@colbyfayock
@colbyfayock Год назад
Get fresh tutorials and other free content straight to your inbox! colbyfayock.com/news
@RagnarSwanson
@RagnarSwanson 15 дней назад
I don’t think this works anymore :/
@colbyfayock
@colbyfayock 15 дней назад
check this out: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-kOdIzhPfLuo.html
@straktormedia8676
@straktormedia8676 6 месяцев назад
Great video! However while everything worked locally (Windows), they didn't work when the app was deployed. I'm getting this error, probably related to Chrome. Error - Failed to launch the browser process! /tmp/chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory TROUBLESHOOTING: Here are the versions of the dependencies in case this is the problem: "dependencies": { "chrome-aws-lambda": "^10.1.0", "dotenv": "^16.4.5", "puppeteer-core": "^10.2.0" }
@colbyfayock
@colbyfayock 6 месяцев назад
hey, it's been a little while since i played with this, but the last time i tried checking this out part of the issue is some of these dependencies require older versions due to the bundle size and those older versions require old versions of node which are deprecated for at least Netlify and Vercel from my understanding
@blackjack4482
@blackjack4482 5 месяцев назад
Were you able to fix it? I've been trying and I have the same error
@straktormedia8676
@straktormedia8676 5 месяцев назад
@@blackjack4482 The problem is an issue with the f***in Chromium versions. This package seems to solve the issue. Try these dependencies: "dependencies": { "@sparticuz/chromium": "^110.0.1", "dotenv": "^16.4.5", "puppeteer-core": "19.6" } And I think you might need to adjust a method a bit to match their syntax. I think something like this will work: const browser = await puppeteer.launch({ args: chromium.args, executablePath: await chromium.executablePath(), headless: true, });
Далее
You might not need useEffect() ...
21:45
Просмотров 163 тыс.
Get Started with Headless Chrome and Puppeteer
15:26
Просмотров 57 тыс.
A Guide to Web Scraping with Node.js
9:54
Просмотров 381 тыс.
Pieter Levels - Indie Hacking is Dead. Now what?
1:11:13
Industrial-scale Web Scraping with AI & Proxy Networks
6:17
Web Scraping  With Javascript (Puppeteer Tutorial)
43:35