Add production-dependency example

This commit is contained in:
Sparticuz 2023-02-09 10:21:16 -05:00
parent dc0a61daa1
commit b8bfaffda1
3 changed files with 48 additions and 0 deletions

1
.gitignore vendored
View File

@ -10,3 +10,4 @@ _/amazon/samconfig.toml
_/amazon/.aws-sam
*.tar
*.tgz
examples/**/package-lock.json

View File

@ -0,0 +1,30 @@
const puppeteer = require("puppeteer-core");
const chromium = require('@sparticuz/chromium');
const handler = async () => {
try {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
ignoreHTTPSErrors: true,
});
const page = await browser.newPage();
await page.goto("https://www.example.com", { waitUntil: "networkidle0" });
console.log("Chromium:", await browser.version());
console.log("Page Title:", await page.title());
await page.close();
await browser.close();
} catch (error) {
throw new Error(error.message);
}
};
handler();

View File

@ -0,0 +1,17 @@
{
"name": "chromium-production-dependency",
"version": "0.0.0",
"description": "This package demonstrates using @sparticuz/chromium as a production dependency. WARNING: This package is over 50 megabytes and will likely not deploy using anything other than self-host",
"license": "ISC",
"author": {
"name": "Kyle McNally"
},
"main": "index.js",
"scripts": {
"test": "node index.js"
},
"dependencies": {
"@sparticuz/chromium": "110.0.0",
"puppeteer-core": "19.6.3"
}
}