Skip to content

Commit b64d2a5

Browse files
committedMar 2, 2024
use different browser based on env
1 parent 421e47e commit b64d2a5

File tree

4 files changed

+668
-26
lines changed

4 files changed

+668
-26
lines changed
 

‎package-lock.json

+642-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
"@google/generative-ai": "^0.2.1",
1313
"axios": "^1.6.7",
1414
"cheerio": "^1.0.0-rc.12",
15+
"chrome-aws-lambda": "^10.1.0",
1516
"dotenv": "^16.4.5",
16-
"express": "^4.18.3",
17+
"express": "^4.18.3"
18+
},
19+
"devDependencies": {
1720
"puppeteer": "^22.3.0"
1821
}
19-
}
22+
}

‎src/helpers.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function isEnvLocal() {
2+
return process.env.APP_ENV === "local";
3+
}
4+
5+
function isEnvProd() {
6+
return process.env.APP_ENV === "production";
7+
}
8+
9+
module.exports = {
10+
isEnvLocal,
11+
isEnvProd,
12+
};

‎src/scraper.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
const axios = require("axios").default;
22
const cheerio = require("cheerio");
3-
const puppeteer = require("puppeteer");
3+
const helpers = require("./helpers");
44

55
async function scrapeSpaContent(url, element) {
6-
const browser = await puppeteer.launch();
6+
let browser;
7+
8+
if (helpers.isEnvProd()) {
9+
browser = await require("chrome-aws-lambda").puppeteer.launch();
10+
} else {
11+
browser = await require("puppeteer").launch();
12+
}
13+
714
const page = await browser.newPage();
815

916
await page.goto(url, { waitUntil: "networkidle2" });

0 commit comments

Comments
 (0)
Please sign in to comment.