Fireship · @fireship

Puppeteer on Cloud Functions

Uploaded August 21, 2018 · Length 9:12

Puppeteer on Cloud Functions

Summary

server-side rendering with puppeteer and cloud functions for firebase hosting

  • server-side rendering
  • puppeteer cloud functions
  • firebase hosting
  • cloud functions puppeteer
  • server rendering

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    [Music]

  2. 0:06

    when cloud functions 2.0 came out last

  3. 0:09

    month we got access to a whole bunch of

  4. 0:11

    cool new features such as a node 8

  5. 0:13

    runtime custom memory and region

  6. 0:15

    settings and the ability to use

  7. 0:16

    puppeteer in the cloud functions

  8. 0:18

    environment today we're going to put all

  9. 0:20

    these new features to use so we can

  10. 0:21

    server-side render pretty much any

  11. 0:23

    JavaScript application from a firebase

  12. 0:25

    function if you're new the channel like

  13. 0:27

    and subscribe and if you want to get

  14. 0:28

    really good at cloud functions consider

  15. 0:30

    becoming a pro member to get access to

  16. 0:32

    the cloud functions master course so one

  17. 0:35

    of the major benefits of the new node 8

  18. 0:37

    runtime and cloud functions is that it

  19. 0:39

    allows us to run puppeteer and headless

  20. 0:41

    Chrome headless chrome is just a web

  21. 0:43

    browser that can run on your server and

  22. 0:45

    puppeteer is a high level API allowing

  23. 0:48

    you to interact with the browser it's

  24. 0:50

    very intuitive to use and you get direct

  25. 0:52

    access to the Dom on the rendered page

  26. 0:54

    so you can use it for things like web

  27. 0:56

    scraping server-side rendering and to

  28. 0:58

    end testing performance benchmarking and

  29. 1:00

    probably a whole bunch of other things

  30. 1:02

    as well

  31. 1:02

    if we go back to episode 66 we used an

  32. 1:06

    app called render Tron to server-side

  33. 1:08

    render and angular application but one

  34. 1:10

    of the major drawbacks that approach is

  35. 1:12

    that we needed to build and maintain our

  36. 1:14

    own docker container in this video we'll

  37. 1:16

    build an app that's equivalent to render

  38. 1:17

    Tron but on a firebase cloud function

  39. 1:20

    I'm going to be building this function

  40. 1:21

    in an ionic 4 project but you can build

  41. 1:24

    it by itself or with any other

  42. 1:25

    JavaScript framework the cloud functions

  43. 1:28

    back end is completely agnostic to your

  44. 1:30

    front-end if you're in a brand-new

  45. 1:32

    project run firebase and it functions

  46. 1:34

    and then I've selected the typescript

  47. 1:36

    option and it's very important that

  48. 1:38

    you're up to date on the latest version

  49. 1:40

    of firebase tools because all this stuff

  50. 1:42

    is very new from there we'll see the end

  51. 1:44

    of the functions directory and then

  52. 1:46

    we'll need to set up node.js version 8

  53. 1:48

    as the runtime open the package JSON

  54. 1:51

    create an object called engines then set

  55. 1:54

    node to a string value of eight then

  56. 1:57

    another thing you want to do if you're

  57. 1:58

    using typescript is add the Dom Lib to