Merge pull request #59 from Sparticuz/feature/examples

This commit is contained in:
Kyle McNally 2023-02-10 14:40:42 -05:00 committed by GitHub
commit 9e148b56f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 6 deletions

View File

@ -140,6 +140,15 @@ const browser = await puppeteer.launch({
});
```
### Examples
Here are some example projects and help with other services
- [Production Dependency](https://github.com/Sparticuz/chromium/tree/master/examples/production-dependency)
- [Serverless Framework with Lambda Layer](https://github.com/Sparticuz/chromium/tree/master/examples/serverless-with-lambda-layer)
- [Chromium-min](https://github.com/Sparticuz/chromium/tree/master/examples/remote-min-binary)
- AWS SAM *TODO*
- [Webpack](https://github.com/Sparticuz/chromium/issues/24#issuecomment-1343196897)
- [Netlify](https://github.com/Sparticuz/chromium/issues/24#issuecomment-1414107620)
### Running Locally
This package will run in headless mode when `NODE_ENV = "test"`. If you want to run using your own local binary, set `IS_LOCAL` to anything.

View File

@ -1,5 +1,5 @@
const puppeteer = require("puppeteer-core");
const chromium = require('@sparticuz/chromium');
const chromium = require("@sparticuz/chromium");
const handler = async () => {
try {
@ -21,10 +21,9 @@ const handler = async () => {
await page.close();
await browser.close();
} catch (error) {
throw new Error(error.message);
}
};
handler();
handler().then(() => console.log("Done"));

View File

@ -0,0 +1,31 @@
const puppeteer = require("puppeteer-core");
const chromium = require("@sparticuz/chromium-min");
const handler = async () => {
try {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(
"https://github.com/Sparticuz/chromium/releases/download/v110.0.1/chromium-v110.0.1-pack.tar"
),
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().then(() => console.log("Done"));

View File

@ -0,0 +1,17 @@
{
"name": "chromium-remote-min",
"version": "0.0.0",
"description": "This package demonstrates using @sparticuz/chromium-min",
"license": "ISC",
"author": {
"name": "Kyle McNally"
},
"main": "index.js",
"scripts": {
"test": "node index.js"
},
"dependencies": {
"@sparticuz/chromium-min": "110.0.1",
"puppeteer-core": "19.6.3"
}
}

View File

@ -1,5 +1,5 @@
const puppeteer = require("puppeteer-core");
const chromium = require('@sparticuz/chromium');
const chromium = require("@sparticuz/chromium");
module.exports = {
handler: async () => {
@ -22,9 +22,8 @@ module.exports = {
await page.close();
await browser.close();
} catch (error) {
throw new Error(error.message);
}
}
},
};