Skip to content

Instantly share code, notes, and snippets.

@camallen
Created January 17, 2019 16:34
Show Gist options
  • Save camallen/36b4a704c28aa9cb13fd3bc51e044727 to your computer and use it in GitHub Desktop.
Save camallen/36b4a704c28aa9cb13fd3bc51e044727 to your computer and use it in GitHub Desktop.
Generate a snapshot of PRN map overlay using chrome headless and puppeteer
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://prn-maps.planetaryresponsenetwork.org/', {waitUntil: 'networkidle0'});
await page.screenshot({path: 'headless-screenshot.jpeg', type: 'jpeg', fullPage: true});
// looks like pdf generation is problematic for centering the page
// https://github.com/GoogleChrome/puppeteer/issues/915
// try various options to no avail
// var height = await page.evaluate(() => {return document.body.clientHeight});
// await page.pdf({path: 'headless.pdf', width: "1280px", height: height + "px"});
// await page.setViewport({ width: 1024, height: 1280 });
// await page.emulateMedia('screen');
// await page.pdf({
// path: 'headless.pdf',
// width: '1024px',
// height: '1280px',
// pageRanges: '1-1'
// });
// await page.pdf({path: 'headless.pdf', width: 1920, height: 1080});
await browser.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment