Skip to content

Commit 917c62c

Browse files
committed
✨ add Puppeteer example to drive the chromium browser
1 parent 3afe305 commit 917c62c

File tree

7 files changed

+360
-1
lines changed

7 files changed

+360
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Also available here `wget https://raw.githubusercontent.com/jfrazelle/dotfiles/m
4242
Launch the container using:
4343
`docker container run -it --rm --security-opt seccomp=$(pwd)/chrome.json zenika/alpine-chrome`
4444

45-
# How to use
45+
# How to use in command line
4646

4747
## Default entrypoint
4848

@@ -83,6 +83,20 @@ Command (with no-sandbox): `docker container run -it --rm -v $(pwd):/usr/src/ap
8383

8484
Command (with no-sandbox): ``docker container run -u `id -u $USER` -it --rm -v $(pwd):/usr/src/app zenika/alpine-chrome --no-sandbox --screenshot --hide-scrollbars --window-size=412,732 https://www.chromestatus.com/``
8585

86+
# How to use with Puppeteer
87+
88+
With tool like ("Puppeteer")[https://pptr.dev/#?product=Puppeteer&version=v1.5.0&show=api-class-browser], we can add a lot things with our Chrome Headless.
89+
90+
With some code in NodeJS, we can improve and make some tests.
91+
92+
See the ["with-puppeteer"](https://github.com/Zenika/alpine-chrome/blob/master/with-puppeteer) folder for more details.
93+
94+
If you have a NodeJS/Puppeteer script in your current folder named `my-test.js`, you can launch it using the following command:
95+
96+
```
97+
docker run -it --rm -v $(pwd):/usr/src/app --cap-add=SYS_ADMIN zenika/alpine-chrome:with-puppeteer node my-test.js
98+
```
99+
86100
# References
87101

88102
* Headless Chrome website: https://developers.google.com/web/updates/2017/04/headless-chrome

with-puppeteer/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

with-puppeteer/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
**.pdf

with-puppeteer/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM zenika/alpine-chrome
2+
3+
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD 1
4+
COPY package.json package-lock.json /usr/src/app/
5+
RUN npm install
6+
COPY . /usr/src/app
7+
WORKDIR /usr/src/app
8+
ENTRYPOINT []
9+
CMD node pdf.js

with-puppeteer/package-lock.json

Lines changed: 302 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

with-puppeteer/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "zenika-alpinechrome-withpuppeteer",
3+
"version": "1.0.0",
4+
"description": "Tests with puppeteer",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/zenika/alpine-chrome.git"
12+
},
13+
"author": "jlandure",
14+
"license": "MIT",
15+
"dependencies": {
16+
"puppeteer": "^1.5.0"
17+
}
18+
}

with-puppeteer/pdf.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const puppeteer = require('puppeteer');
2+
3+
(async () => {
4+
const browser = await puppeteer.launch({
5+
executablePath: '/usr/bin/chromium-browser',
6+
//args: ['--headless', '--disable-gpu', '--remote-debugging-port=9222'],
7+
});
8+
const page = await browser.newPage();
9+
await page.goto('https://www.chromestatus.com/', {waitUntil: 'networkidle2'});
10+
await page.pdf({path: 'hn.pdf', format: 'A4'});
11+
12+
await browser.close();
13+
})();

0 commit comments

Comments
 (0)