Merge pull request #59 from Sparticuz/feature/examples
This commit is contained in:
commit
9e148b56f3
|
|
@ -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
|
### 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.
|
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.
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const puppeteer = require("puppeteer-core");
|
const puppeteer = require("puppeteer-core");
|
||||||
const chromium = require('@sparticuz/chromium');
|
const chromium = require("@sparticuz/chromium");
|
||||||
|
|
||||||
const handler = async () => {
|
const handler = async () => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -21,10 +21,9 @@ const handler = async () => {
|
||||||
await page.close();
|
await page.close();
|
||||||
|
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(error.message);
|
throw new Error(error.message);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
handler();
|
handler().then(() => console.log("Done"));
|
||||||
|
|
|
||||||
|
|
@ -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"));
|
||||||
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
const puppeteer = require("puppeteer-core");
|
const puppeteer = require("puppeteer-core");
|
||||||
const chromium = require('@sparticuz/chromium');
|
const chromium = require("@sparticuz/chromium");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
handler: async () => {
|
handler: async () => {
|
||||||
|
|
@ -22,9 +22,8 @@ module.exports = {
|
||||||
await page.close();
|
await page.close();
|
||||||
|
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(error.message);
|
throw new Error(error.message);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue