|
| 1 | +# Centos 6 puppeteer docker image |
| 2 | + |
| 3 | +docker image with [Google Puppeteer](https://github.com/GoogleChrome/puppeteer) installed for **Centos 6 only** |
| 4 | + |
| 5 | +If you can, please use Centos 7 or higher but cause Centos 6 is EOL. Otherwise you can use this tool for Centos6. |
| 6 | + |
| 7 | +Repo is based on [Google Puppeteer](https://github.com/GoogleChrome/puppeteer) and [alekzonder/docker-puppeteer] (https://github.com/alekzonder/docker-puppeteer) |
| 8 | + |
| 9 | +## install |
| 10 | + |
| 11 | +``` |
| 12 | +docker pull gergokee/centos6-puppeteer:latest |
| 13 | +
|
| 14 | +``` |
| 15 | + |
| 16 | +## before usage |
| 17 | + |
| 18 | + |
| 19 | +1. You should **not** pass `--no-sandbox, --disable-setuid-sandbox` args when launching it, only if there is no other way, when you need to run it as **root** (which is not recommended). |
| 20 | + |
| 21 | +```js |
| 22 | +const puppeteer = require('puppeteer'); |
| 23 | + |
| 24 | +(async () => { |
| 25 | + |
| 26 | + console.info("Starting browser"); |
| 27 | + |
| 28 | + let browser; |
| 29 | + |
| 30 | + try { |
| 31 | + |
| 32 | + browser = await puppeteer.launch({}); |
| 33 | + |
| 34 | + } catch (e) { |
| 35 | + |
| 36 | + console.info("Unable to launch browser mode in sandbox mode. Lauching Chrome without sandbox."); |
| 37 | + browser = await puppeteer.launch({args:[ |
| 38 | + '--no-sandbox', |
| 39 | + '--disable-setuid-sandbox' |
| 40 | + ]}); |
| 41 | + |
| 42 | + } |
| 43 | + |
| 44 | + console.info("Browser successfully started"); |
| 45 | + console.info("Closing browser"); |
| 46 | + |
| 47 | + await browser.close(); |
| 48 | + |
| 49 | + console.info("Done"); |
| 50 | + |
| 51 | +})(); |
| 52 | +``` |
| 53 | + |
| 54 | +2. If you see errors like "ERR_NETWORK_CHANGED", write your script to check the output of it and make a loop till the output is not generating errors. Unfortunately the problem is that IPV6 needs to be turned off. And because latest docker for Centos 6 is docker v1.7, you are unable to pass the necessary flag: **--sysctl net.ipv6.conf.all.disable_ipv6=1** |
| 55 | + |
| 56 | + |
| 57 | +3. add `--enable-logging` for chrome debug logging http://www.chromium.org/for-testers/enable-logging |
| 58 | + |
| 59 | +```js |
| 60 | +const puppeteer = require('puppeteer'); |
| 61 | + |
| 62 | +(async() => { |
| 63 | + |
| 64 | + const browser = await puppeteer.launch({args: [ |
| 65 | + '--no-sandbox', |
| 66 | + '--disable-setuid-sandbox', |
| 67 | + |
| 68 | + // debug logging |
| 69 | + '--enable-logging', '--v=1' |
| 70 | + ]}); |
| 71 | + (async () => { |
| 72 | + |
| 73 | + console.info("Starting browser"); |
| 74 | + |
| 75 | + let browser; |
| 76 | + |
| 77 | + try { |
| 78 | + |
| 79 | + browser = await puppeteer.launch({args: [ |
| 80 | + '--enable-logging', '--v=1' |
| 81 | + ]}); |
| 82 | + |
| 83 | + } catch (e) { |
| 84 | + |
| 85 | + console.info("Unable to launch browser mode in sandbox mode. Lauching Chrome without sandbox."); |
| 86 | + browser = await puppeteer.launch({args:[ |
| 87 | + '--no-sandbox', |
| 88 | + '--disable-setuid-sandbox', |
| 89 | + '--enable-logging', '--v=1' |
| 90 | + ]}); |
| 91 | + |
| 92 | + } |
| 93 | + |
| 94 | + console.info("Browser successfully started"); |
| 95 | + console.info("Closing browser"); |
| 96 | + |
| 97 | + await browser.close(); |
| 98 | + |
| 99 | + console.info("Done"); |
| 100 | + |
| 101 | +})(); |
| 102 | + |
| 103 | + |
| 104 | +``` |
| 105 | +
|
| 106 | +## usage |
| 107 | +
|
| 108 | +### mount your script to /app/index.js |
| 109 | +
|
| 110 | +```bash |
| 111 | +docker run --rm -v <path_to_script>:/app/index.js gergokee/centos6-puppeteer:latest |
| 112 | +``` |
| 113 | +
|
| 114 | +### custom script from dir |
| 115 | +
|
| 116 | +```bash |
| 117 | +docker run --rm \ |
| 118 | + -v <path_to_dir>:/app \ |
| 119 | + gergokee/centos6-puppeteer:latest \ |
| 120 | + node my_script.js |
| 121 | +``` |
0 commit comments