Skip to content

Commit d0d9991

Browse files
NiznikrSiTaggart
andauthored
chore: use node 16 for opengraph (#3025)
Co-authored-by: Simon Taggart <[email protected]>
1 parent 521e4d9 commit d0d9991

File tree

7 files changed

+84
-115
lines changed

7 files changed

+84
-115
lines changed

internal-docs/engineering/doc-site/open-graph-image-preview-function.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ The code that generates the opengraph preview page lives in:
6262

6363
Netlify Functions are just AWS Lambdas in disguise. They take an incoming request and you can return a response.
6464

65-
Inside our function we use `chrome-aws-lambda` for grabbing the Chrome Browser binary for AWS Lambdas, and puppeteer to run and control the browser.
65+
Inside our function we use `@sparticuz/chromium` for grabbing the Chrome Browser binary for AWS Lambdas, and puppeteer to run and control the browser.
6666

6767
Using Puppeteer, we instruct Chrome to visit a url on the website, which renders a dynamic page based on the parameters we give it. We then tell puppeteer to use Chrome to take a screenshot of the page, and that image is then returned as the response of the function.
6868

@@ -71,9 +71,3 @@ The page on the website renders a box 800px x 420px. The information is display
7171
[Winston](https://github.com/winstonjs/winston) does our logging, so we can observe the function running in real time in the Netlify UI.
7272

7373
[Rollbar](https://docs.rollbar.com/docs/aws-lambda) wraps our function and helps log errors to the Rollbar service so we are alerted if it starts to break.
74-
75-
## Node runtime
76-
77-
🚨 **Node v14** 🚨
78-
79-
The Netlify function must run using Node v14 for the Chrome binary to work correctly. We are explicitly opting out of Node 16 runtime in Netlify functions by setting the `AWS_LAMBDA_JS_RUNTIME` environment variable in the Netlify UI.

netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
[functions]
1616
directory = "packages/paste-website/functions"
17-
external_node_modules = ["chrome-aws-lambda", "puppeteer-core"]
17+
external_node_modules = ["@sparticuz/chromium", "puppeteer-core"]
1818

1919
# INTRODUCTION/
2020
[[redirects]]

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"@netlify/functions": "^0.7.2",
127127
"@percy/cli": "^1.10.1",
128128
"@percy/cypress": "^3.1.2",
129+
"@sparticuz/chromium": "^110.0.0",
129130
"@storybook/addon-a11y": "7.0.0-beta.45",
130131
"@storybook/addon-actions": "7.0.0-beta.45",
131132
"@storybook/addon-essentials": "7.0.0-beta.45",
@@ -167,7 +168,6 @@
167168
"browser-sync": "^2.26.9",
168169
"chalk": "4.1.2",
169170
"chromatic": "^6.17.0",
170-
"chrome-aws-lambda": "^10.0.0",
171171
"color": "^3.1.2",
172172
"commander": "^2.20.0",
173173
"concurrently": "^7.6.0",
@@ -209,7 +209,7 @@
209209
"precise-commits": "^1.0.2",
210210
"prettier": "^2.8.1",
211211
"prop-types": "^15.7.2",
212-
"puppeteer-core": "^10.1.0",
212+
"puppeteer-core": "^19.6.1",
213213
"react": "^18.0.0",
214214
"react-dom": "^18.0.0",
215215
"react-ga": "^3.3.0",

packages/paste-website/functions/opengraph.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* or 900 seconds (Enterprise plan).
1414
*/
1515
import puppeteer from 'puppeteer-core';
16-
import chromium from 'chrome-aws-lambda';
16+
import chromium from '@sparticuz/chromium';
1717
import Rollbar from 'rollbar';
1818
import type {LambdaHandler} from 'rollbar';
1919

@@ -50,7 +50,7 @@ async function getOptions(isDev: boolean): Promise<{args: any; executablePath: a
5050
}
5151

5252
return {
53-
executablePath: await chromium.executablePath,
53+
executablePath: await chromium.executablePath(),
5454
args: chromium.args,
5555
headless: chromium.headless,
5656
};

packages/paste-website/netlify.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
[functions]
2424
directory = "functions"
25-
external_node_modules = ["chrome-aws-lambda", "puppeteer-core"]
25+
external_node_modules = ["@sparticuz/chromium", "puppeteer-core"]
2626

2727
# need to all add redirects to ./netlify.toml as well
2828
# INTRODUCTION/

packages/paste-website/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@mdx-js/react": "^1.6.22",
2727
"@next/bundle-analyzer": "^13.1.6",
2828
"@next/mdx": "^13.1.6",
29+
"@sparticuz/chromium": "^110.0.0",
2930
"@twilio-paste/alert": "^11.0.3",
3031
"@twilio-paste/alert-dialog": "^6.0.2",
3132
"@twilio-paste/anchor": "^9.0.2",
@@ -105,7 +106,6 @@
105106
"@types/lodash": "^4.14.182",
106107
"@types/mdx-js__react": "^1.5.5",
107108
"airtable": "^0.11.6",
108-
"chrome-aws-lambda": "^10.0.0",
109109
"color": "^3.1.2",
110110
"date-fns": "2.21.3",
111111
"deepmerge": "4.2.2",
@@ -120,7 +120,7 @@
120120
"pretty-format": "^28.1.0",
121121
"prism-react-renderer": "^1.3.5",
122122
"prop-types": "^15.7.2",
123-
"puppeteer-core": "^10.1.0",
123+
"puppeteer-core": "^19.6.1",
124124
"react": "^18.0.0",
125125
"react-color": "^2.19.3",
126126
"react-dom": "^18.0.0",

0 commit comments

Comments
 (0)