How to use puppeteer on Google Cloud Functions

Поділитися
Вставка
  • Опубліковано 6 лис 2024

КОМЕНТАРІ • 53

  • @SimranjeetSingh-zv4xe
    @SimranjeetSingh-zv4xe 3 роки тому +6

    I have watched millions of videos on UA-cam, Udemy and other platforms but this was probably the best in terms of information, fun and engagement. Incredible work man, Cheers!

  • @jsoverson
    @jsoverson  5 років тому +6

    Puppeteer on cloud functions + the devtools protocol can allow you to turn clever devtools hacks into a full HTTP API endpoint.

  • @timdowd
    @timdowd Рік тому +3

    New versions of puppeteer no longer work in google cloud functions due to dependency issues. So now you need puppeteer to be in a container unfortunately... The puppeteer docs recommend cloud run

  • @cdac1645
    @cdac1645 5 років тому +6

    Please make more videos on this subject. Like cloud functions with parameters and issues with CORS.

  • @sanjayajanakantha7883
    @sanjayajanakantha7883 8 місяців тому

    Thank you Jarrod! It works for me and ur save my day! I realize that we are not always suppose to use latest versions

  • @planetmall2
    @planetmall2 5 років тому +7

    Great video. Thank you for continuing to make these!

  • @mattorrock4844
    @mattorrock4844 3 роки тому +2

    Thanks, but could you do a video that shows how to use these functions from within say, a React project? For example, I'm working within an existing React project and used firebase init within the root dir, which creates the functions folder. The firebase deploy command looks for functions inside that folder, and the syntax you show here won't work. Any help? Would be an awesome vid, thanks!

  • @dionvansevenant6801
    @dionvansevenant6801 5 років тому +2

    Very interesting. Good explanations. However, I have poked at a few of your other videos and haven't found a reference to your kickstart script yet. Did you show the whole thing around 1:02 of this video, or just a snippet? Thanks!

    • @jsoverson
      @jsoverson  5 років тому

      Yeah it's very short and I have a few for different types of projects (e.g. rust, typescript). You can check it out here twitter.com/jsoverson/status/1097881605824237569?s=19

    • @dionvansevenant6801
      @dionvansevenant6801 5 років тому

      @@jsoverson cool. Thanks.
      Doesn't seem to work on Debian under WSL (Windows Subsystem for Linux), but that's ok. I get the intent and idea of it and can poke around with it when I get the chance.

  • @dazlave
    @dazlave Рік тому

    I could be totally wrong, but would it not be important to close the browser and context resources to keep billing costs down?

  • @cnikolov
    @cnikolov 4 роки тому +1

    Do you need the close the browser when doing this? As well or the function will do it when the response is returned

  • @gijovarghese7548
    @gijovarghese7548 4 роки тому +1

    How long will the Puppeteer instance be running? So even if we execute many cloud functions in parallel, those all use the same puppeteer instance?

    • @jl-dq5ch
      @jl-dq5ch 4 роки тому

      That what it looks like. I'm currently having a problem where it runs the same request twice at about the same time. The only neat thing about that is that it seems to show that that one instance is used to run both queries.

  • @ffgcvs
    @ffgcvs 3 роки тому

    Can I use the same idea for running puppeteer on cloud functions with a logged area like GMP (Google Marketing Platform)? I have a local script in nodejs which does this job, but I need to run manually every day

  • @planetmall2
    @planetmall2 5 років тому +2

    Jarrod, have you ever run into this error when running puppeteer on a function? Timed out after 30000 ms while trying to connect to Chrome! The only Chrome revision guaranteed to work is r674921. I have tried to adjust the runtime environment between 8 and 10 and also changed the args to all the examples on the API. I get the same error no matter what. Any help would be great! Thanks again!

    • @jsoverson
      @jsoverson  5 років тому +1

      I have but not recently. What version of puppeteer+chrome? Is it a bundled chrome? Is this locally or on GCP?

    • @planetmall2
      @planetmall2 5 років тому

      @@jsoverson puppeteer: "1.19.0" - I am using it with a Firebase function. It looks like the internet has recently had that same issue.

    • @jsoverson
      @jsoverson  5 років тому

      @@planetmall2 No I haven't seen that yet. 1.19 was what I used in the video and that worked (I just tried again). Maybe chrome isn't starting properly for some other reason? Is this new behavior or the first time you've tried it? Try some of the following args: --disable-gpu, --disable-dev-shm-usage, --disable-setuid-sandbox, --no-first-run, --no-zygote.

    • @planetmall2
      @planetmall2 5 років тому

      @@jsoverson I tried a few different versions for the args with no luck. I will continue to diagnose.

    • @thomasstarzynski6787
      @thomasstarzynski6787 4 роки тому

      did you find a solve for that by now? I'm having the same one. It seems like this is a common issue if you check on github: github.com/puppeteer/puppeteer/issues/4796

  • @rafaelbarros719
    @rafaelbarros719 2 роки тому

    can i make it without headless mode?

  • @jasonc6241992
    @jasonc6241992 Рік тому

    You sure you don't want to close both the context and browser? My script ends in a blank tab if i just close the context.

  • @riverbrooks2822
    @riverbrooks2822 5 років тому +4

    Super informational video, great stuff!

  • @gfinzer
    @gfinzer 4 роки тому

    Jarrod, you are simply the best.

  • @knsakib
    @knsakib 4 роки тому

    The github repo is not accessible. Can you please check?

  • @david-tracy
    @david-tracy 3 роки тому

    how can we determine what an appropriate memory size for our function will be?

  • @aarong9327
    @aarong9327 3 роки тому

    This is scary powerful.

  • @thecyrusj13
    @thecyrusj13 4 роки тому +1

    This runs fine locally but I get Error: could not handle the request when I go to the url in the cloud

    • @thecyrusj13
      @thecyrusj13 4 роки тому +1

      Sorry, my mistake. I didn't have billing enabled.

    • @thecyrusj13
      @thecyrusj13 4 роки тому +1

      @@darekdede1995 Rather than using Google Cloud services I ultimately just used AWS which I'm used to. If you're interested in the AWS Lambda route for using Puppeteer see: github.com/alixaxel/chrome-aws-lambda

  • @jatinrai199
    @jatinrai199 3 роки тому

    You're awesome ! Keep it up. Subscribed your channel. Please post more videos on puppeteer.

  • @phpmysql2007
    @phpmysql2007 4 роки тому

    NICE! got mine to work too!

  • @mauroleonardosabatellidemo3619
    @mauroleonardosabatellidemo3619 2 роки тому

    Thank you my friend

  • @jl-dq5ch
    @jl-dq5ch 4 роки тому

    I have the browser running with headless: false so that I can see whats going on and it seems like it is launching the browser twice using the same query:
    Am I doing something wrong? If I remove the res.end()/.send() it only runs once but then I am unable to deploy...
    exports.zillowScraper = async (req, res) => {
    const url = req.query.location
    ?`www.zillow.com/homes/${req.query.location}`
    : "www.zillow.com/homes/92259/"
    const browser = await browserPromise
    const context = await browser.createIncognitoBrowserContext()
    const page = await context.newPage()
    await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36')

    zillowScraper(page, url, context)
    res.end()
    }

  • @leopoldocouto
    @leopoldocouto 5 років тому

    Hello Jarrod!
    How do I display, in my index.html, a return message from a function (using puppeteer) from another .js file?
    For example:
    I have an index.html page, and an index.js.
    In index.js I have a function that returns data taken from any page using Puppeteer. And I would like to display this message as a on my index.html page.
    Thanks for your attention and great videos.
    * sorry for gooleTranslate's english

    • @jsoverson
      @jsoverson  5 років тому +1

      Can you elaborate? Like via AJAX on a regular webpage?

    • @leopoldocouto
      @leopoldocouto 5 років тому

      @@jsoverson Im trying tô develop. The code in puppetter os ready. Now, i have to display the function return in HTML. But i dont know how

    • @jsoverson
      @jsoverson  5 років тому

      That's a tough problem to solve without knowing much of the app. Are you returning the data as json?

    • @leopoldocouto
      @leopoldocouto 5 років тому

      @@jsoverson I can return the data anyway.
      About the app, it's simple, there's only one .js file where I use puppeteer to enter, log in and extract data. And I wanted to display this data in an html page. Is there another better method of doing this?

    • @jsoverson
      @jsoverson  5 років тому +1

      @@leopoldocouto you can return html directly from the function if you want to. You can treat it like a normal express app so you can use any template system you want (like handlebars). If you are returning it as json you will need a separate html file to call your function via XHR or Fetch and render it that way. If I've misunderstood the question, can you upload an example of the problem to GitHub?

  • @tzarinadeabreu2507
    @tzarinadeabreu2507 2 роки тому

    Jarrod, tens este vídeo com legenda para a língua Portuguesa do Brasil? Muito obrigada!😉

  • @theseanmodd
    @theseanmodd 3 роки тому

    THANK YOU

  • @phantazzor
    @phantazzor 3 роки тому

    Wow no need of express!?

  • @riverbrooks2822
    @riverbrooks2822 5 років тому +1

    Your subscribers (I) are hungry for content!! Haha xD

    • @jsoverson
      @jsoverson  5 років тому

      😖 I've been traveling and it's beating me up. I probably am still one week out until the next one. What should it be on? I've got puppeteer stuff, deepfake stuff, reverse engineering, GCP stuff, attack tools. There's a lot on the backlog.

    • @riverbrooks2822
      @riverbrooks2822 5 років тому

      @@jsoverson Good question. I'll give an answer to that question shortly.

    • @riverbrooks2822
      @riverbrooks2822 5 років тому

      @@jsoverson attack tools or puppeteer stuff, personally I think.

  • @arthigo
    @arthigo 3 роки тому

    "A Gigabyte of RAM Should Do the Trick"