Last active
December 17, 2021 16:49
-
-
Save travist/aaf2c22554a9f0268065f139aa61b007 to your computer and use it in GitHub Desktop.
Run puppeteer from docker exec.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker exec pdf-server node --eval="\ | |
const puppeteer = require('puppeteer');\ | |
(async () => {\ | |
const translateProxy = function(proxy) {\ | |
return proxy.replace(/http[s]?:\/\//g, '').split(',').join(';');\ | |
};\ | |
const puppeteerArgs = [\ | |
'--no-sandbox',\ | |
'--disable-setuid-sandbox',\ | |
'--disable-dev-shm-usage',\ | |
'--disable-web-security',\ | |
];\ | |
if (process.env.HTTP_PROXY) {\ | |
puppeteerArgs.push('--proxy-server=' + translateProxy(process.env.HTTP_PROXY));\ | |
}\ | |
else if (process.env.HTTPS_PROXY) {\ | |
puppeteerArgs.push('--proxy-server=' + translateProxy(process.env.HTTPS_PROXY));\ | |
}\ | |
if (process.env.NO_PROXY) {\ | |
puppeteerArgs.push('--proxy-bypass-list=' + translateProxy(process.env.NO_PROXY));\ | |
}\ | |
const browser = await puppeteer.launch({\ | |
args: puppeteerArgs,\ | |
executablePath: process.env.CHROME_BIN || null,\ | |
ignoreHTTPSErrors: true\ | |
});\ | |
try {\ | |
console.log('Created PDF browser.');\ | |
const page = await browser.newPage();\ | |
console.log('New page');\ | |
await page.goto('https://form.io');\ | |
console.log('Go to page');\ | |
await page.evaluate(async () => {\ | |
try {\ | |
const resp = await fetch('https://examples.form.io/example');\ | |
const result = await resp.text();\ | |
console.log(result);\ | |
}\ | |
catch (err) {\ | |
console.log(err);\ | |
}\ | |
});\ | |
}\ | |
catch (err) {\ | |
console.log(err);\ | |
}\ | |
})();\ | |
" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment